Presentation is loading. Please wait.

Presentation is loading. Please wait.

Procedures Stefano Grazioli.

Similar presentations


Presentation on theme: "Procedures Stefano Grazioli."— Presentation transcript:

1 Procedures Stefano Grazioli

2 Critical Thinking “Recording” error
Extra credit (+1 point) to the first person who finds any material mistake in the vLabs or deck. timestamp will tell. Alternative ways of doing things do not count as errors. Easy meter  x 10 year

3 Renaming a Project Unzip & make a copy of the project folder
Look inside the folder. Find the folder that contains the .vbproj file and many other files. Keep that folder, delete the ‘outer’ stuff. Change the folder name to the new name. Click on .vbproj to start VS and change all other filenames from inside VS.

4 You do the talking Name, Major Learning objectives
What you like about the class What can be improved Attitude towards the Tournament

5 Procedures Lasagne and Tagliatelle

6 Subs are a type of procedure
Public Sub MyProcedure() Dim inputFromUser As String = "" Dim userNum As Double = 0 inputFromUser = InputBox("Please enter a number to square") userNum = Double.Parse(inputFromUser) userNum = userNum ^ 2 ShowTheUser(userNum) End Sub Private Sub ShowTheUser(someValue As Double) Range(“A1”).Value = "The result is " someValue.ToString("N0") A procedure is a named sequence of steps Purpose: reuse & simplify existing code Good practice: shorter than a single screen Sometimes it takes arguments “Macro” is the old name for procedure

7 Local and global variables
Dim userNum As Double = 0 Public Sub MyProcedure() Dim inputFromUser As String = "" inputFromUser = InputBox("Please enter a number to square") userNum = Double.Parse(inputFromUser) userNum = userNum ^ 2 ShowTheUser(userNum) End Sub Private Sub ShowTheUser(someValue As Double) Range(“A1”).Value = "The result is " someValue.ToString("N0") Variables are names for physical places in your computer memory Variables have a lifecycle Variables have a scope Find the vars in here

8 Functions are another type of procedure
input Return a single value Conceptually similar to the formulas in your worksheets output Private Function CalcInterest(r As Double, principal As Double, t As Double) As Double Dim interest As Double = 0 interest = principal * ((((1 + r) ^ t) - 1)) Return interest End Function

9 Argument Binding ‘ A function
Sometimes difficult to understand for beginners ‘ A function Private Function CalcInterest(r As Double, principal As Double, t As Double) As Double ‘ No binding myInt = CalcInterest(0.05, 1000, 10) ‘ With binding (typical use) myRate = 0.10 userPrincipal = 8000 years = 20 myInt = CalcInterest(myRate, userPrincipal, years)

10 Arguments vs. Globals Arguments are short-term variables used as input to procedures (Subs and functions) -best practice -more efficient & less errors Globals are variables defined outside of a Sub/Function -Use globals if variables have an extended life, are small, and are used by many procedures

11 WINIT What Is New In Technology?

12 Homework Using Subs & Functions


Download ppt "Procedures Stefano Grazioli."

Similar presentations


Ads by Google