Function.

Slides:



Advertisements
Similar presentations
Arithmetic in Pascal (2) Arithmetic Functions Perform arithmetic calculations Gives an argument to the function and it returns the result.
Advertisements

Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
Testing a program Remove syntax and link errors: Look at compiler comments where errors occurred and check program around these lines Run time errors:
Section 3.6 BUILT-IN FUNCTIONS involving numbers & strings.
VBA & Excel Barry L. Nelson IEMS 465 Fall Quarter 2003.
Copyright © 2001 by Wiley. All rights reserved. Chapter 3: Variables, Assignment Statements, and Arithmetic Variables Assignment Statements Arithmetic.
Illuminating Computer Science CCIT 4-6Sep
IE 212: Computational Methods for Industrial Engineering
Chapter 3 Programming Fundamentals Writing Code 3 Exploring Microsoft Visual Basic 6.0 Copyright © 1999 Prentice-Hall, Inc. By Carlotta Eaton.
1 Documenting Your Project. 2 Documenting your Project Insert Banner Comments in your code Comment - coding statement used by humans not the compiler.
Lecture 8 Visual Basic (2).
COMPUTER PROGRAMMING I Objective 7.03 Apply Built-in Math Class Functions.
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
How to start Visual Studio 2008 or 2010 (command-line program)
1 E0001 Computers in Engineering Built in Functions.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
Introduction to VB.NET 2005 Dr. McDaniel IDS4704 Spring 2005.
IMS 3253: Subroutines 1 Dr. Lawrence West, MIS Dept., University of Central Florida Topics Procedures Subroutines Parameters –By Value.
CS105 Lab 9 – Do-While-Loops Announcements MP2 released today! See website for several important announcements/deadlines CS 105 – Fall
University of Sunderland CIF 104 Fundamentals of DatabasesUnit 16 SESSION 16 VBA example.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Chapter 8 - Visual Basic Schneider
6c – Function Procedures Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
ME 142 Engineering Computation I Using Subroutines Effectively.
1 GUI programming Graphical user interface-based programming Chapter G1 (pages )
Chapter 3 w Variables, constants, and calculations DIM statements - declaration temporary memory locations identifier, data type, scope data types - values.
Pay Example (PFirst98) Please use speaker notes for additional information!
ME 142 Engineering Computation I Using Subroutines Effectively.
Control Your Application Sequence, Selection, and Repetition.
Introduction to Programming Python Lab 3: Arithmetic 22 January PythonLab3 lecture slides.ppt Ping Brennan
Introduction to Programming
Controlling Program Flow with Decision Structures.
Loop and repetition. Today Passing values to and back from Sub procedures Option Buttons Do While Loops For Loops Population Growth.
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Chapter 4 - Visual Basic Schneider1 Chapter 4 General Procedures.
Adding Code to the Option Button. Open VB 1.Double click the Calculate button and select General from the Object list box. 2.Add the following code to.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
More on Variables and Subroutines. Introduction Discussion so far has dealt with self- contained subs. Subs can call other subs or functions. A module.
Starting Out with Visual Basic.NET 2 nd Edition Chapter 6 Sub Procedures And Functions.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
Chapter 4.  Variables – named memory location that stores a value.  Variables allows the use of meaningful names which makes the code easier to read.
Introduction to Computer CC111 Week 10 Visual Basic 3 1.
TUTORIAL 4 Visual Basic 6.0 Mr. Crone. Pseudocode Pseudocode is written language that is part-code part- English and helps a programmer to plan the layout.
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
L131 Assignment Operators Topics Increment and Decrement Operators Assignment Operators Debugging Tips rand( ) math library functions Reading Sections.
Chapter 3 - Visual Basic Schneider. Private Sub cmdEvaluate_Click() Dim n As Single, root As Single n = 6.76 root = Sqr(n) picResults.Print root; Int(n);
Use TryParse to Validate User Input
Introduction to Programming
Royal University of Phnom Penh
Introduction to Programming
Lesson 16 Sub Procedures Lesson 17 Functions
Use TryParse to Validate User Input
Method.
Introduction to Programming
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Department Array in Visual Basic
PROGRAMMING Program Development.
Introduction to Programming
Sub Procedures and Functions
CS285 Introduction - Visual Basic
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Introduction to Programming
Chapter 3 Programming Fundamentals
Tutorial 11 Using and Writing Visual Basic for Applications Code
Lecture 20 – Practice Exercises 4
Presentation transcript:

Function

The Wind Chill Project Write a program that calculates the wind chill temperature Find a formula - UST Today Weather Web site www.usatoday.com/weather/wchilform.htm Inputs: Wind Speed and Temperature Outputs: Wind Chill Temperature

The Wind Chill Project Orginal formula Visual Basic statement WC = 0.0817(3.71(V **0.5) + 5.81 - 0.25V)(T - 91.4) + 91.4 Visual Basic statement WC = 0.0817 * (3.71 * Sqr(V) + 5.81 -(0.25 * V)) * (T - 91.4) + 91.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

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

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

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 = 0.0817 * (3.71 * Sqr(V) _ +5.81 - (0.25*V)) * (T-91.4)+91.4 End Function

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

The Wind Chill Project using Functions and Procedures Hands-On Exercise 1 (p.103-114) 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

End of Lecture