Procedure - A unit of code that performs a specific task and can be called from other locations of the program.
PURPOSES OF PROCEDURES:
Break large sections of code into smaller units of code that perform a specific task.
Makes it easier to debug and maintain program.
Cuts down on the amount of code that has to be written, and eliminates duplication of code.
TYPES OF PROCEDURES:
Sub Procedure - A procedure that performs a task but DOES NOT return values back to the calling module.
Function Procedure - A procedure that performs a task and RETURNS a value back to the calling module. With function procedures, the value is returned back to the calling module using the function name.
CREATING A NEW SUB PROCEDURE:
Display the code window for the form
Select ADD PROCEDURE from the TOOLS menu
Enter the name of the procedure in the text box next to where it says NAME
Select PRIVATE for SCOPE
Click OK
You will be given the procedure shell. Type in the contents of your procedure
Click on the code button to exit the procedure
Example of a Sub Procedure:
Example of a Sub Procedure Call:
Example of a Function Procedure:
Example of a Function Procedure Call:
WITH STATEMENT
The WITH keyword allows you to cut down on coding when dealing with properties of controls.
Syntax of WITH statement:
With < control >
.< property1> = < value1 >
.< property2> = < value2 >
.< property3> = < value3 >
End With
Assigning controls without the WITH KEYWORD:
Assigning controls using the WITH KEYWORD:
COMMON DIALOG CONTROL
Allows your project to use the dialog boxes that are provided as part of the Windows environment to set properties for a control such as font, font size and color.
FEATURES OF THE DIALOG CONTROL:
You only need common dialog control on your form
You cannot change the controls size
The location of the control does NOT matter
The control will be invisible when the program runs
Dialog controls are stored with an extension of .ocx
When naming Dialog controls, begin with a prefix of dlg
The common dialog box may not appear in your toolbox. It is a custom * control and will need to be added to your project before you can use it.
RETRIEVING THE COMMON DIALOG CONTROL:
Click on Project
Click on Components
Scroll down and find Microsoft Common Dialog Control 6.0
Click the check box next to it to select it.
Click OK and it will be placed in your tool box.
Click on Dialog Control and place it on your form.
CHANGING FONTS:
Example Syntax for Setting Fonts:
With dlgCommon (assuming that you named it that)
.Flags = cdlCFScreenFonts ‘Loads different fonts into memory
.ShowFont
End With
CHANGING COLOR:
Example Syntax for Changing Color:
RANDOM NUMBERS
Rnd - Generates a random number between 0 and 1.
Randomize - Tells VB to randomly generate numbers for the rnd statement. Using randomize will allow the rnd statement to generate an entirely random set of numbers that do not follow any recognizable pattern.
Generating Numbers between 1 and 10:
Generating Numbers between 1 and 100:
INT() FUNCTION:
Converts a floating point value to an integer by truncating off any remainder that the number has. INT(4.656) will return a value of 4.