Presentation is loading. Please wait.

Presentation is loading. Please wait.

Function.

Similar presentations


Presentation on theme: "Function."— Presentation transcript:

1 Function

2 The Wind Chill Project Write a program that calculates the wind chill temperature Find a formula - UST Today Weather Web site Inputs: Wind Speed and Temperature Outputs: Wind Chill Temperature

3 The Wind Chill Project Orginal formula Visual Basic statement
WC = (3.71(V **0.5) V)(T ) Visual Basic statement WC = * (3.71 * Sqr(V) (0.25 * V)) * (T )

4 Functions Function - unit of code that returns a value
Build-in Functions Sqr - square root Rnd - random number generator Int - returns integer portion of a number Val - converts a string to a value

5 Functions Locating built-in functions Programmer-written functions
Open the Functions online reference book or search for a function by name Programmer-written functions Write your own functions using the Function statement

6 The Function Statement
Private Function function-name (argument1, argument2....) statements End Function Where Private or Public is required Function indicates the beginning of a function function-name is the name that will be used to call the function ( ) parentheses are required around the argument list argument1, argument2 are optional variables needed to perform the calculation or actions needed for the function End Function indicates the end of the function

7 WindChill Function Private Function WindChill( )
‘Purpose: Calculate the Wind Chill ‘Reference: National Weather Service Dim V As Integer ‘Wind Speed Velocity Dim T AS Integer ‘Temperature V = hsbSpeed.Value T = hsbTemperature.Value WindChill = * (3.71 * Sqr(V) _ (0.25*V)) * (T-91.4)+91.4 End Function

8 WindChill Function Private Sub cmdCalculate_Click() WC = WindChill()
When the cmdCalculate button is clicked, the WindChill function is executed Private Sub cmdCalculate_Click() WC = WindChill() txtWindChill.Text = Cint(WC) End Sub

9 The Wind Chill Project using Functions and Procedures
Hands-On Exercise 1 (p ) Create a New Project Create the Controls for Temperature Input Create the Controls for Wind Speed Input Create the Controls for Wind Chill Output Create the Image Control Add Banner Comments Add the Wind Chill Function Add Temperature and Speed Procedures Save, Run, Test your Project

10 End of Lecture


Download ppt "Function."

Similar presentations


Ads by Google