Variables and Constants
Option Explicit - A statement that will force you to declare all variables used in your program. If you fail to declare a variable, an error will occur when you run your program.
DECLARING A VARIABLE:
When you declare a variable, VB reserves space in the computers memory and assigns a name to it. When declaring variables, certain rules must be followed.
Rules for Variable Names:
NOTE: The rules specified above also apply to control names placed on a form.
The DIM statement is used to declare all variables in VB.
DIM < variable_name > as < datatype >
DECLARING A CONSTANT:
Constants are always declared using the keyword CONST. You give the constant a name, data type and value. Once a value is declared as a constant, it can never be changed again in the program. Trying to change a constant will cause an error. The rules for variables also apply to constants.
DIM < constant name > as < datatype > = <value >
NAMED CONSTANTS - These are constants that you name yourself with the CONST keyword. Named constants can come in the form of numeric constants and string constants.
NUMERIC CONSTANTS - Constants that can contain only the digits 0-9, a decimal point.
STRING CONSTANTS - Constants that can contain letters, digits, and special characters such as @#$%^&*. String constants must be enclosed in double quotes.
INSTRINCT CONSTANTS - System-Defined constants that are built into VB.
Examples of Instrinct Constants:
SCOPES OF VARIABLES:
Scope - Is a term used to refer to the visibility of a variable.
Lifetime - The period of time that variables exist within the program.
3 LEVELS OF SCOPE:
Default Property - Automatically selects a command button when the user presses the < ENTER > key. To make a command button a default button, you set its DEFAULT property to TRUE. Only one command button per form can have its default property set to true. When the program is run, this command button will be highlighted.
Cancel Property - The button that is selected when the user presses the < ESC > key. To set a command button to cancel the program, set its CANCEL property to TRUE. Only one command button per form can have its cancel button set to true.
TabStop Property - Represents all controls on a form that can receive focus. If the TabStop property is TRUE, a control can receive focus. If it is FALSE, then it cannot.
Some controls can receive focus, others cannot.
Text Boxes, and Command Buttons can receive focus.
Labels and Images cannot receive focus.
TabIndex Property- Determines order of focus moves as the < TAB > key is pressed.
Name - Used to assign the name of the control as it is known by the project. Caption - The label that appears next to, in or on top of the control.
BackColor - The background color of the control.
ForeColor - The color of the text that appears on or next to the control.
Text - The text which appears in a text box.
Alignment - Determines the justification of text within a label or text box.
MultiLine - Allows a string to be spread out among several lines, rather than one line.
Font - Allows you to set the font and font size of a control.
TabIndex - Determines the order the focus moves as the < TAB > key is pressed.
Visible- Property used to make a control visible or invisible
FillStyle - Primarily used with shapes, is used to fill the shape. Different options are available.
No Comments for this page.