Search
Left Quote    Wise men speak because they have something to say; Fools because they have to say something.
- Plato (427-347 B.C.)    
Right Quote
 
[login] | [Register]
 

Getting Started with VB 6.0

by: bs0d
Page: 3 of 9
(View All)

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:
  • Must begin with a letter.
  • Can consist of letters, digits and the underscore.
  • Cannot contain any spaces or periods.
  • Must be 1 to 255 positions in length
  • Can not use Reserved Words as 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.

Syntax:

DIM < variable_name > as < datatype >

Examples:



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.


Syntax:

DIM < constant name > as < datatype > = <value >

Examples:



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:
  • vbRed
  • vbGreen
  • vbBlue
  • Checked
  • vbYellow
  • UnChecked

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:


  • Global Variable - Variable accessible anywhere in VB, in all forms that are a part of the project.
  • Module-Level Variable - Variable to all procedures on the form in which it is declared.
  • Local Variable - Variable accessible only in the procedure which it was declared.

PROPERTIES


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.
  • 0 - Left Justify
  • 1 - Right Justify
  • 2 - Center

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.
  • 0 - Solid
  • 1 - Transparent
  • 2 - Horizontal Line
  • 3 - Vertical Line
  • 4 - Upward Diagonal
  • 5 - Downward Diagonal
  • 6 - Cross
  • 7 - Diagonal Cross

EXAMPLES :



1  |  2  |  3  |  4  |  5  |  6  |  7  |  8  |  9  |  
Next »


No Comments for this page.

You Must be logged in or a member to comment.


Tutorial Stats

Tutorial Stats

169,299 Views
0 Total Comments
4.16 Rating of 5 (6 Votes)

Options

Tutorial Options

· Login to Rate This Article
· Login to Post a Comment
· Read more by this author
Digg This Article! Del.icio.us: Bookmark This Article Reddit: Bookmark This Article BlinkList: Blink This Article! YahooMyWeb BlogMarks: Add This Mark! Furl: Save This Article Spurl: Mark This Article

Articles

Related    

· Coding a Webserver
· Using Crystal Reports in VB
Your Article Here



"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank