If.| Where Declaration Keyword Used (Scope & Lifetime) | |||
|---|---|---|---|
| Declaration Keyword | In Procedure of Any Module | In Declaration Section of Non-Standard Module |
In Declaration Section of Standard Module (.bas) |
| Dim | Procedure & Procedure | Module & Application | Module & Application |
| Static | Procedure & Application | NA | NA |
| Private | Procedure & Procedure | Module & Application | Module & Application |
| Public | NA | Global & Application | Global & Application |
| Const | Global & Application | Global & Application | Global & Application |
A variable, constant, or object variable is usually declared before using it. Explicit variable declaration is not required but highly recommended. For one, it helps Visual Basic spell check your variables. If using it be sure to use the Option Explicit keyword in the Declarations section of the module's code. Syntax:
{Dim | Static | Private | Public} Variable [As DataType]
{Dim | Static | Private | Public} Const Constant [As DataType] = expression
{Dim | ReDim | Static | Private | Public} ObjectVariable As [New] ClassOrObjeccodeype
...
Set <ObjectVariable> = [New] Object
Module1.strAge and Form1.strAge.Static keyword is either used within a procedure or at procedure declaration (to make all the variables in the procedure static). Static variables have procedure scope and application lifetime. This sounds like you might as well make a module or global scope variable but those variables would not be exclusive to the procedure.As keyword when declaring. If no data type is declared, Visual Basic will assume that the data type is variant. EG: The statement Dim Alpha, Beta As Byte, makes a variable called Alpha of the data type Variant and a variable called Beta of the type Byte.As String * n, where n is the desired length.Set keyword. Note that you cannot use the New keyword with generic object types, fundamental data types (EG: Integer), specific control types (EG: TextBox), or specific controls (EG: TextBox1).Declare arrays as you would a variable but with these modifications:
Dim intArray(3) As Integer
'VB6/VBS arrays are zero-based 'This array has 4 elements
Private intArray(1 to 7) As String
Dim vntArrays(2) As Variant Dim strArray(4) As String Dim intArray(5) As Integer vntArrays(0) = strArray vntArrays(1) = intArray
Static bytMatrix(3, 1 to 7) As Byte
'VB6/VBS supports up to 60 dimensions
For I = 1 To 5 For J = 1 To 10 intMatrixA(I, J) = I * 10 + J Next J Next I
Public myArray()
'and then (within a procedure only) 'use the ReDim keyword to set the variable size:
ReDim my Array(x +1)
ReDim keyword eliminates all data in the array before resizing. To preserve the data, the Preserve keyword must be used and only the upper bound can be resized. EG:
ReDim Preserve Array(UBound(Array)+1).
Array(argList). The function takes a comma delimited list of n values and return a variant array of size n. EG:
Dim A, B, C A = Array(11,22,33) B = A(2) 'B is now 22 C = Array() 'C is an array of zero length
_) at the end of each line.:) is placed between statements.&) to link strings and use plus sign (+) to link numerical values.&O and hexadecimal numbers with &H. EG: 15 = &O17 = &HF.Option Explicit keywords at the start of each code module should almost be mandatory. It enables VB to check for errors on your identifiers.DogBite. (Java and JavaScript folks like to capitalize only the second word and beyond. EG: dogBite.)PromotionalPrograms instead of ProPrg.DogRun and DogBite.Form1.Temp.vbTileVertical.
vbCrLf.adStatusOK.[LibraryName.][ModuleName.]ConstantName.imgDog and lblDog for the Dog image and label.mnuFileSave or mnuFile_Save....).|
Prefix |
Object |
Prefix |
Object |
|---|---|---|---|
|
pnl |
3D Panel ActiveDoc ADODataControl AnimatedButton/Animation CoolBar CheckBox Chart ComboBox/DBCombo/DataCombo CommandButton Common Dialog CommandGroup Connection Container Control CoolBar Custom Data Database DataEnvironment DataRepeater DataReport DBEngine DirListBox Document Drive/DriveListBox DatePicker EditBox Error FileListBox FileSystemObject Frame Field Form/MDIForm FormSet Frame FlatScrollBar Grid/DBGrid/DataGrid GridColumn GridHeader MSFlexGrid/MSHFlexGrid HScrollBar HyperLink Image ImageCombo ImageList Index InternetTransfer |
lbl |
Label Line ListBox/DBList/DataList ListView MAPIMessages/MAPISession MaskedEditBox MultimediaMCI Menu MonthView Object OLEBoundControl OLE OptionButton OptionGroup Page PageFrame Parameter PictureBox ProgressBar ProjectHook Property QueryDef RemoteData Recordset Relation RichTextBox Separator Shape Slider Spinner StatusBar SysInfo TabbedDialog TableDef TabStrip TextBox Timer ToolBar TreeView UpDown User VerticalScrollBar WinSock Workspace |
Page Modified: (Hand noted: 2007-09-20 20:02:00Z) (Auto noted: 2007-11-17 06:37:27Z)