Sub Procedures and Functions Chapter 5 P 1
Sub Procedures and Functions Chapter 5 P. 1 Shape Control, Line Control Fig. 5. 1, Fig. 5. 2 The Scroll Bar Controls - properties Min smallest value Max largest value Large. Change distance to move when the user clicks on the gray area Small. Change distance to move when the user clicks on the arrow Scroll bar events A scroll bar has two methods associated with it in this project.
Chapter 5 P. 2 Example Fig. 5. 3 Form with scroll bars Example Fig. 5. 4 Detail of the scroll bar Example Fig. 5. 5 Toolbox tools for creating scrollbars Programming example Design and create the form Set the properties Write the code - go to the upper left on the code - select vsb. Move. Car - under the method select vsb. Scroll - under the method select vsb. Change - type in the code for each procedure
Chapter 5 P. 3 The Case Statement - general form Select Case expression Case constant list statements Case Else ‘OPTIONAL! End Select Example P. 141 - constant list - list of values - range of values with TO - boolean expression
Chapter 5 P. 4 - testing strings - use quotes around the strings - use UCASE or LCASE to avoid problems Testing Option Buttons with the Case statement Examples P. 143 IGNORE THE PROCEDURE HEADING FOR THE MOMENT! They use syntax which we have not yet covered. Functions for Financial Calculations - Pmt method for calculating payments on a loan - Rate for computing interest rate etc.
Chapter 5 P. 5 Writing general procedures These are procedures which are not associated with any control. Advantage - avoid duplicating code - simplify code Method 1 - under Tools select Add procedure - select Sub and Private - type in the name of the procedure Method 2 Type in the heading and End Sub Example P. 147 In this example, the calling procedures are vsb. Move. Car_Change(), vsb. Move. Car_SCroll(), hsb. Move. Car_Change(), and hsb. Move. Car_SCroll(). The called procedure is Position_Image().
Chapter 5 P. 6 Passing variables to procedures Definition Suppose Procedure A calls Procedure B. The programmer may want to allow Procedure B to use a variable defined in Procedure A. The variable is said to be passed from A to B, and then back from B to A. Example Procedure A( ) Dim i. Value As Integer B (i. Value) ‘Procedure B gets i. Value and ‘does something End Sub Procedure B (i. Value) do something involving i. Value End Sub
Chapter 5 P. 7 Example P. 148 Procedure hsb. Move. Car_Change() calls Procedure Move. Horizontal. Variable i. XPosition is a variable which is defined in hsb. Move. Car_Change() and is then passed to Move. Horizontal. Functions versus procedures A function returns one value. The general syntax is: Private Function name (parameter) End Function Example P. 149
- Slides: 7