Friday, March 18, 2011

Chapter 6 Summary

6.1 Procedures
-Collection of statements that performs a task.
-Unlike a function, procedures don't return a value.

Use the call method to call procedures.

Modularize: breaking apart code into smaller procedures.

Format:
[Access Specifier] Sub ProcedureName ([parameterList])
    [Statements]
End Sub

-When making a variable local to a procedure, that variable will be destroyed once the procedure executes. If you want to keep that variable, use "Static" instead of "Dim" when declaring the variable.

6.2 Passing Arguments to Procedures
-Values that are passed to a procedure to execute are called arguments.
ByVal: passing an argument using this means that it's only a copy of the argument, the original argument isn't changed from what the ByVal statement brings back.
ByRef: is the original argument, changes can be made.

Example of how to pass arguments:

Sub DisplayValue (ByVal intnumber As Integer)
   MessageBox.Show(intNumber.ToString())
End Sub

The name of the procedure is "DisplayValue". "intNumber" is the variable that is created to store the value that the code passes the argument to. If the code were to be:
DisplayValue(txtPhone.text); it'll pass whatever is in the text-box to the intNumber variable, eventually displaying a message box with the text-box.

-You can pass multiple arguements to a procedure, just make sure you have enough variables.

6.3 Functions
-A function returns a value to the part of the program that called the function.

Format:
[AccessSpecifier] Function FunctionName ([ParameterList]) As DataType
   [Statements]
Return Value
End Function

Example:
Function Sum(ByVal dblNum1 As Double, ByVal dblNum2 As Double) As Double
   Return dblNum1+dblNum2
End Function

In this function, you're declaring a Function name as "Sum". dblNum1/dblNum2 will be the variables to hold the user input. The "As Double" after the parantheses is the data type that the function will return the value as.

If the code was: dblTotal=Sum(dblVal1+dblVal2), it'll pass the dblVal1/dblVal2 variables to the dblNum1/dblNum2 variables in the function. It'll return a value, and Sum will assign that value to the dblTotal variable.

6.4 Debugging Continued
Step Into: When an application is break mode, step into causes the currently highlighted line to execute.
   -Activate by pressing F8, select Debug in the menu-Step Into, or click the Step Into button.

Step Over: It'll cause the currently highlighted line to execute like Step Into, but if the line contains a function/procedure, it'll execute the function/procedure without stopping through it's statements.
   -Activate by pressing Shit+F8, select Step Over from Debug, or press the Step Over button.

Step Out: Use this when single-stepping through a function/procedure if you want the remainder of the function/procedure to finish executing without single-stepping.
   -Activate by pressing Ctrl+Shift+F8, select Step Out from Debug, or press Step Out button.

6.5 Bagel/Coffee Price Calculator Application
See book starting pg. 381.

No comments:

Post a Comment