Natural Resource Biometrics Visual Basic Functions for Natural [PDF]

Within Microsoft Excel®, there exists the ability to write Visual Basic (VBA) Subroutines and Functions. This tutorial

3 downloads 5 Views 744KB Size

Recommend Stories


PdF Download Natural Resource Economics
Raise your words, not voice. It is rain that grows flowers, not thunder. Rumi

Natural Resource Assessment Process
Happiness doesn't result from what we get, but from what we give. Ben Carson

Natural Resource Analyst
Sorrow prepares you for joy. It violently sweeps everything out of your house, so that new joy can find

natural resource commission[571]
Learning never exhausts the mind. Leonardo da Vinci

Natural Resource Curse
Live as if you were to die tomorrow. Learn as if you were to live forever. Mahatma Gandhi

ODI Natural Resource Perspec
The happiest people don't have the best of everything, they just make the best of everything. Anony

The Natural Resource Curse
Just as there is no loss of basic energy in the universe, so no thought or action is without its effects,

[PDF] Download Environmental and Natural Resource Economics
Pretending to not be afraid is as good as actually not being afraid. David Letterman

PdF Environmental and Natural Resource Economics
Don’t grieve. Anything you lose comes round in another form. Rumi

[PDF] Environmental and Natural Resource Economics
You can never cross the ocean unless you have the courage to lose sight of the shore. Andrè Gide

Idea Transcript


Natural Resource Biometrics Visual Basic Functions for Natural Resource Programming By David R. Larsen Lesson 1 Objectives: In this lesson we will learn:  Learn to setup the Visual Basic (VBA) developers interface.  Enter a VBA function.  Learn some basic syntax.  Learn to run the function we just made. Within Microsoft Excel®, there exists the ability to write Visual Basic (VBA) Subroutines and Functions. This tutorial is designed to present the basic concepts you need to make use of the tools. This tutorial is designed for college students in natural resources with little or no computer programming experience. This is not designed to be an exhaustive reference to Excel VBA programming. First you will need to access the Visual Basic interface. In this tutorial I will be using Excel spreadsheet, from the Microsoft Office 2010 suite. If you are using a different version of Excel the tool will be in your release but the specific locations may differ. To start the VBA interface. 1. Open Excel. 2. Click on the file tab 3. Click on Options 4. Check the Developer label in the Customize the Ribbon 5. Click OK This should add the Developer tab above the Ribbon bar

Figure 1. Illustration of the location of the developer tab in Microsoft Excel®

Now we can select the developer tab.

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics

Figure 2. Illustration of the location of the Visual Basic icon in the developer ribbon.

After we click on the Visual Basic icon, we get the Visual Basic Programming window

Figure 3. Illustration of the Visual Basic Programming interface

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics

In the programming window we next:  Click on insert  then module

Figure 4. Illustration of the Insert-> module menu item

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics

Figure 5. Illustration of the module programming window

In the tutorial we will be using pseudo-code , is a series of steps of tasks that a function must complete to accomplish the task. In computer programming, pseudo-code is used to describe the steps that program must complete so that you have the opportunity to develop the actual instructions. Our first example is a function that when passed the your name replies “Hello, your name”   

Declare a function hello that accepts a String labeled name and returns a String. Variable in code have types that can be, String, integer, or double, we will see more examples of this later. Create a variable the same name as the function, the values in the variable that is the same name as the function will be returned at the end of the function. Concatenate and String “Hello, “ with the variable name with a plus sign.

Declare a function with String argument returning a String Concatenate the argument string with a “Hello, “ string.

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics To implement this pseudo-code here is the simplest function that we will program. This implementation step is what you provide as the assignment. This one is provided as a example. Function hello(name As String) As String hello = "Hello, " + name End Function

Figure 6. Illustration of the code entered into the programming window

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics

Figure 7. Illustration of the use of our new function in Excel.

This is the result of running the hello function. Simple and of little value as a function but it illustrates the steps of creating a function using Visual Basic in Excel.

In our series of programming lessons we will creates more functions: 1. 2. 3. 4. 5. 6.

Hello function described in this lesson. Mean function that produces the same results as the built-in Average function. Quadratic mean function. Simpson diversity function. Shannon diversity function. Tree Volume function.

This series is designed to use the concepts presented in the previous lessons while adding a new concept in each lesson. In programming an important concept is testing of the result. In each of these functions we will first calculate the values using just a excel spreadsheet so that you have an idea that you code is working correctly. Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Natural Resource Biometrics In this lesson we have learn: • • • •

Learn to setup the Visual Basic (VBA) developers interface. Enter a VBA function. Learn some basic syntax. Learn to run the function we just made.

Natural Resources Biometrics by David R. Larsen is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

Smile Life

When life gives you a hundred reasons to cry, show life that you have a thousand reasons to smile

Get in touch

© Copyright 2015 - 2024 PDFFOX.COM - All rights reserved.