Definitions

Definition Name

Description

Arglist  

[ | expr | param:=expr ][,]

A list of zero or more exprs that are assigned to the parameters of the procedure.

A positional parameter may be skipped by omitting the expression. Only optional parameters may be skipped.

Positional parameter assignment is done with expr. Each parameter is assigned in turn. By name parameter assignment may follow.

By name parameter assignment is done with param:=expr. All following parameters must be assigned by name.

Array Variable  

A variable that holds an array of values. A Variant variable can hold an array. Dynamic arrays can be ReDimensioned.

As [New] Type  

Dim, Private, Public and Static statements may declare variable types using As type or As New objtype. A variable declared using As New objtype is automatically created prior to use, if the variable is Nothing.

As Type

Variable and parameter types, as well as, function and property results may be specified using As type: Boolean, Byte, Currency, Date, Double, Integer, Long, Object, PortInt, Single, String, String*n, UserDialog, Variant, objtype, userenum, usertype.

Attribute Definition/Statement

Syntax:

Attribute attributename = value

Attribute varname.attributename = value

Attribute procname.attributename = value

Group: Declaration

Description:

All attribute definitions and statements are ignored except for:

Form 1: Module level attribute

  • Attribute VB_Name = "name"

  • Attribute VB_GlobalNameSpace = bool

  • Attribute VB_Creatable = bool

  • Attribute VB_PredeclaredId = bool

  • Attribute VB_Exposed = bool

  • Attribute VB_HelpID = int

  • Attribute VB_Description = "text"

  • VB_Name - Declares the name of the class module or object module.

  • VB_GlobalNameSpace - Declares the class module as a global class. (ignored)

  • VB_Creatable - Declares the module as creatable (True), non-creatable (False). (ignored)

  • VB_PredeclaredId - Declares the module as a predeclared identifier (True). (ignored)

  • VB_Exposed - Declares the module as public (True). (ignored)

  • VB_HelpID - Declares the module's help context displayed by the object browser.

  • VB_Description - Declares the module's help text displayed by the object browser.

Form 2: Macro/Module level variable attribute

  • Public varname As Type

  • Attribute varname.VB_VarUserMemId = 0

  • Attribute varname.VB_VarHelpID = int

  • Attribute varname.VB_VarDescription = "text"

  • VB_VarUserMemID - Declares Public varname as the default property for a class module or object module.

  • VB_VarHelpID - Declares the variable's help context displayed by the object browser.

  • VB_VarDescription - Declares the variable's help text displayed by the object browser.

Form 3: User defined procedure attribute

  • [Sub | Function | Property [Get|Let|Set]] procname

  • Attribute procname.VB_UserMemId = 0

  • Attribute procname.VB_HelpID = intAttribute procname.VB_Description = "text"

  • End [Sub | Function | Property]

  • VB_UserMemID - Declares Property procname as the default property for a class module or object module.

  • VB_HelpID - Declares the procedure's help context displayed by

  • the object browser.

  • VB_Description - Declares the procedure's help text displayed by the object browser.

HelpFile:

Each macro/module can define the HelpFile for the object browser:

'#HelpFile "helpfile"

where "helpfile" is a full path to the help file associated with the help text and help context.

Attribute  

A file attribute is zero or more of the following values added together.

Attribute Value Description

  • vbNormal 0 Normal file.

  • vbReadOnly 1 Read-only file.

  • vbHidden 2 Hidden file.

  • vbSystem 4 System file.

  • vbVolume 8 Volume label.

  • vbDirectory 16 MS-DOS directory.

  • vbArchive 32 File has changes since last backup.

Begin Dialog  

Syntax:

Begin Dialog UserDialog [X, Y,] DX, DY[, Title$]

[,.dialogfunc]

User Dialog Item

[User Dialog Item]

End Dialog

Group: User Dialog

Description:

Define a UserDialog type to be used later in a Dim As UserDialog statement.

Parameters:

  • X This numeric value is the distance from the left edge of the screen to the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font. If this is omitted then the dialog will be centered.

  • Y This numeric value is the distance from the top edge of the screen to the top edge of the dialog box. It is measured in 1/12th of the average character width for the dialog's font. If this is omitted then the dialog will be centered.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ This string value is the title of the user dialog. If this is omitted then there is no title.

  • dialogfunc This is the function name that implements the DialogFunc for this UserDialog. If this is omitted then the UserDialog doesn't have a dialogfunc.

User Dialog Item:

One of: CancelButton, CheckBox, ComboBox, DropListBox, GroupBox, ListBox, OKButton, OptionButton, OptionGroup, PushButton, Text, TextBox.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for ok)

End Sub

Big-Endian  

Multiple byte data values (not strings) are stored with the highest order byte first. For example, the long integer &H01020304 is stored as this sequence of four bytes: &H01, &H02, &H03 and &H04. A Binary or Random file written using Put uses little-endian format so that it can be read using Get on any machine. (Big-endian machines, like the Power-PC, reverse the bytes as they are read by Get or written by Put.)

CancelButton Dialog Item  

Syntax:

CancelButton X, Y, DX, DY[,.Field]

Group: User Dialog

Description:

Define a cancel button item. Pressing Cancel from a Dialog instruction causes a run-time error. (Dialog( ) function call returns 0.)

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this is omitted then the field name is "Cancel".

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,30,"Please push Cancel"

OKButton 40,90,40,20

CancelButton 110,90,60,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for cancel)

Debug.Print "Cancel was not pressed"

End Sub

Charlist  

A group of one or more characters enclosed by [ ] as part of Like operator's right string expression.

This list contains single characters and/or character ranges which describe the characters in the list.

A range of characters is indicated with a hyphen (-) between two characters. The first character must be ordinally less than or equal to the second character.

Special pattern characters like ?, *, # and [ can be matched as literal characters.

The ] character can not be part of charlist, but it can be part of the pattern outside the charlist.

CheckBox Dialog Item  

Syntax:

CheckBox X, Y, DX, DY, Title$,.Field[, Options]

Group: User Dialog

Description:

Define a checkbox item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Field The value of the check box is accessed via this field. cleared is 0, selected is 1 and grayed is 2.

  • Options This numeric value controls the type of check box. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

Check box is either selected or cleared.

1

Check box is either selected, cleared, or grayed, and it switches between selected and cleared when clicked.

2

Check box is either selected, cleared, or grayed, and it cycles through all three states as the button is clicked

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

CheckBox 10,25,180,15,"&Check box",.Check

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.Check = 1

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.Check

End Sub

ComboBox Dialog Item  

Syntax:

ComboBox X, Y, DX, DY, StrArray$( ),.Field$[, Options]

Group: User Dialog

Description:

Define a combo box item. Combo boxes combine the functionality of an edit box and a list box.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • StrArray$( ) This one-dimensional array of strings establishes the list of choices. All the non-null elements of the array are used.

  • Field$ The value of the combo box is accessed via this field. This is the text in the edit box.

  • Options This numeric value controls the type of combo box. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

List is not sorted.

2

List is sorted.

Example:

Sub Main

Dim combos$(3)

combos$(0) = "Combo 0"

combos$(1) = "Combo 1"

combos$(2) = "Combo 2"

combos$(3) = "Combo 3"

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

ComboBox 10,25,180,60,combos$(),.combo$

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.combo$ = "none"

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.combo$

End Sub

Condexpr

An expression that returns a numeric result. If the result is zero then the conditional is False. If the result is non-zero then the conditional is True.

0 'false

-1 'true

X > 20 'true if X is greater than 20

S$ = "hello" 'true if S$ equals "hello"

Const Definition

Syntax:

[ | Private | Public ] _

Const name[type] [As Type] = expr[,]

Group: Declaration

Description:

Define name as the value of expr. The expr may be refer other constants or built-in functions. If the type of the constants is not specified, the type of expr is used. Constants defined outside a Sub, Function or Property block are available in the entire macro/module.

Private is assumed if neither Private or Public is specified.

Note: Const statement in a Sub, Function or Property block may not use Private or Public.

Example:

Sub Main

Const Pi = 4*Atn(1), e = Exp(1)

Debug.Print Pi ' 3.14159265358979

Debug.Print e ' 2.71828182845905

End Sub

Dateexpr

An expression that returns a date result. Use #literal-date# to express a date value.

#1/1/2000# ' Jan 1, 2000

Now+7 ' seven days from now

DateSerial(Year(Now)+1,Month(Now),Day(Now))

' one year from now

Declare

Syntax:

[ | Private | Public ] _

Declare Sub name Lib "dll name" _

[Alias "module name"] [([param[,...]])]

-or-

[ | Private | Public ] _

Declare Function name[type] Lib "dll name" _

[Alias "module name"] [([param[,...]])] [As type[()]]

Group: Declaration

Description:

Interface to a DLL defined subroutine or function. The values of the calling arglist are assigned to the params.

Declare defaults to Public if neither Private nor Public is specified.

WARNING! Be very careful when declaring DLL subroutines or functions. If you make a mistake and declare the parameters or result incorrectly then Windows might halt. Save any open documents before testing new DLL declarations.

Err.LastDLLError returns the error code for that last DLL call (Windows 32 bit versions only).

Parameters:

  • name This is the name of the subroutine or function being defined. If Alias "module name" is omitted then this is the module name, too.

  • "dll name" This is the DLL file where the module's code is.

  • "module name" This is the name of the module in the DLL file. If this is #number then it is the ordinal number of the module. If it is omitted then name is the module name. The DLL is searched for the specified module name. If this module exists, it is used. All As String parameters are converted from Unicode to ASCII prior to calling the DLL and from ASCII to Unicode afterwards. (Use "Unicode:module name" to prevent ASCII to Unicode conversion.) If the module does not exist, one or two other module names are tried:

    1. For Windows NT only: The module name with a "W" appended is tried. All As String parameters are passed as Unicode to calling the DLL.
    2. For Windows NT and Windows 95: The module name with an "A" appended is tried. All As String parameters are converted from Unicode to ASCII prior to calling the DLL and from ASCII to Unicode afterwards.
    3. If none of these module names is found a run-time error occurs.
  • params A list of zero or more params that are used by the DLL subroutine or function. (Note: A ByVal string's value may be modified by the DLL.)

Example:

Declare Function GetActiveWindow& Lib "user32" ()

Declare Function GetWindowTextLengthA& Lib "user32" (ByVal hwnd&)

Declare Sub GetWindowTextA Lib "user32" (ByVal hwnd&, ByVal lpsz$, ByVal cbMax&)

Function ActiveWindowTitle$()

ActiveWindow = GetActiveWindow()

TitleLen = GetWindowTextLengthA(ActiveWindow)

Title$ = Space$(TitleLen)

GetWindowTextA ActiveWindow,Title$,TitleLen+1

ActiveWindowTitle$ = Title$

End Function

Sub Main

Debug.Print ActiveWindowTitle$()

End Sub

Def

Syntax:

Def{Bool|Cur|Date|Dbl|Int|Lng|Obj|Sng|Str|Var} letterrange[,...]

Group: Declaration

Description:

Define untyped variables as:

  • DefBool - Boolean

  • DefByte - Byte

  • DefCur - Currency

  • DefDate - Date

  • DefDbl - Double

  • DefInt - Integer

  • DefLng - Long

  • DefObj - Object

  • DefSng - Single

  • DefStr - String

  • DefVar - Variant

Parameters:

letterrange letter, or letter-letter: A letter is one of A to Z. When letter-letter is used, the first letter must be alphabetically before the second letter. Variable names that begin with a letter in this range default to declared type.

If a variable name begins with a letter not specific in any letterrange, then the variable is a Variant. The letterranges are not allowed to overlap.

Example:

DefInt A,C-W,Y' integer

DefBool B ' boolean

DefStr X ' string

' all others are variant

Sub Main

B = 1 ' B is an boolean

Debug.Print B ' True

X = "A" ' X is a string

Debug.Print X '"A"

Z = 1 ' Z is a variant (anything)

Debug.Print Z ' 1

Z = "Z"

Debug.Print Z '"Z"

End Sub

Dialogfunc

A dialog function executes while a UserDialog is visible.

Dim

Syntax:

Dim [WithEvents] name[type][([dim[,...]])][As [New] type][,...]

Group: Declaration

Description:

Dimension var array(s) using the dims to establish the minimum and maximum index value for each dimension. If the dims are omitted then a scalar (single value) variable is defined. A dynamic array is declared using ( ) without any dims. It must be ReDimensioned before it can be used.

Example:

Sub DoIt(Size)

Dim C0,C1(),C2(2,3)

ReDim C1(Size) ' dynamic array

C0 = 1

C1(0) = 2

C2(0,0) = 3

Debug.Print C0;C1(0);C2(0,0) ' 1 2 3

End Sub

Sub Main

DoIt 1

End Sub

Dim

[lower To] upper

Array dimension. If lower is omitted then the lower bound is zero or one depending on the Option Base setting. (The lower bound of an array element in a Type definition is not affected by the Option Base setting.) upper must be at least as big as lower.

Dim A(100 To 200) '101 values

Note: For ReDim the lower and upper may be any valid expression. Otherwise, lower and upper must be constant expressions.

Dlgvar

A dialog variable holds values for fields in the dialog. Dialog variables are declared using Dim dlgvar As UserDialog.

DropListBox Dialog Item

Syntax:

DropListBox X, Y, DX, DY, StrArray$( ),.Field[, Options]

Group: User Dialog

Description:

Define a drop-down listbox item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • StrArray$( ) This one-dimensional array of strings establishes the list of choices. All the non-null elements of the array are used.

  • Field The value of the drop-down list box is accessed via this field. It is the index of the StrArray$( ) var.

  • Options This numeric value controls the type of drop-down list box. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

Text box is not editable and list is not sorted.

1

Text box is editable and list is not sorted.

2

Text box is not editable and list is sorted

3

Text box is editable and list is sorted.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Dim lists$(3)

lists$(0) = "List 0"

lists$(1) = "List 1"

lists$(2) = "List 2"

lists$(3) = "List 3"

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

DropListBox 10,25,180,60,lists$(),.list1

DropListBox 10,50,180,60,lists$(),.list2,1

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.list1 = 2 ' list1 is a numeric field

dlg.list2 = "xxx" ' list2 is a string field

Dialog dlg ' show dialog (wait for ok)

Debug.Print lists$(dlg.list1)

Debug.Print dlg.list2

End Sub

Enum

Syntax:

[ | Private | Public ] Enum name

elem [ = value]

[...]

End Enum

Group: Declaration

Description:

Define a new userenum. Each elem defines an element of the enum. If value is given then that is the element's value. The value can be any constant integer expression. If value is omitted then the element's value is one more than the previous element's value. If there is no previous element then zero is used.

Enum defaults to Public if neither Private or Public is specified.

Example:

Enum Days

Monday

Tuesday

Wednesday

Thursday

Friday

Saturday

Sunday

End Enum

Sub Main

Dim D As Days

For D = Monday To Friday

Debug.Print D ' 0 through 4

Next D

End Sub

Expr

An expression that returns the appropriate result.

Field

Use.field to access individual fields in a dialog variable.

dlg.LastName$

dlg.ZipCode

Function

Syntax:

[ | Private | Public | Friend ] [ Default ] Function name[type][([param[,...]])] [As type[()]]

statements

End Function

Group: Declaration

Description:

User defined function. The function defines a set of statements to be executed when it is called. The values of the calling arglist are assigned to the params. Assigning to name[type] sets the value of the function result.

Function defaults to Public if Private, Public or Friend are not is specified.

See Also: Declare, Property, Sub.

Example:

Function Power(X,Y)

P = 1

For I = 1 To Y

P = P*X

Next I

Power = P

End Function

Sub Main

Debug.Print Power(2,8) ' 256

End Sub

GroupBox Dialog Item

Syntax:

GroupBox X, Y, DX, DY, Title$[,.Field]

Group: User Dialog

Description:

Define a groupbox item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ This string value is the title of the group box.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this identifier is omitted then the first two words of the title are used.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

GroupBox 10,25,180,60,"Group box"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for ok)

End Sub

Instruction

A single command.

Beep

Debug.Print "Hello"

Today = Date

Multiple instructions may be used instead of a single instruction by separating the single instructions with colons.

X = 1:Debug.Print X

If X = 1 Then Debug.Print "X=";X:Stop

Beep ' must resume from Stop to get to here

Label

An identifier that names a statement. Identifiers start with a letter. Following chars may be a letter, an underscore or a digit.

ListBox Dialog Item

Syntax:

ListBox X, Y, DX, DY, StrArray$( ),.Field[, Options]

Group: User Dialog

Description:

Define a lis tbox item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • StrArray$( ) This one-dimensional array of strings establishes the list of choices. All the non-null elements of the array are used.

  • Field The value of the list box is accessed via this field. It is the index of the StrArray$( ) var.

  • Options This numeric value controls the type of list box. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

List is not sorted.

1

List is not sorted and horizontally scrollable

2

List is sorted.

3

List is sorted and horizontally scrollable.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Dim lists$(3)

lists$(0) = "List 0"

lists$(1) = "List 1"

lists$(2) = "List 2"

lists$(3) = "List 3"

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

ListBox 10,25,180,60,lists$(),.list

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.list = 2

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.list

End Sub

Little-Endian

Multiple byte data values (not strings) are stored with the lowest order byte first. For example, the long integer &H01020304 is stored as this sequence of four bytes: &H04, &H03, &H02 and &H01. A Binary or Random file written using Put uses little-endian format so that it can be read using Get on any machine. (Big-endian machines, like the Power-PC, reverse the bytes as they are read by Get or written by Put.)

Method

An object provides methods and properties. Methods can be called as subs (the return value is ignored), or used as functions (the return value is used).

If the method name contains characters that are not legal in a name, surround the method name with [].

App.[Title$]

Name

An identifier that names a variable or a user defined procedure. Identifiers start with a letter. Following chars may be a letter, an underscore or a digit.

Count

DaysTill2000

Get_Data

Num

An expression that returns a numeric result. Use &O to express an octal number. Use &H to express a hex number.

Numvar

A variable that holds one numeric value. The name of a numeric variable may be followed by the appropriate type char.

Objexpr

A expression that returns a reference to an object or module.

CreateObject("WinWrap.CDemoApplication")

Objtype

A specific ActiveX Automation type defined by your application, another application or by an object module or class module.

See Also: CreateObject( ), GetObject( ).

Objvar

A variable that holds a objexpr which references an object. Object variables are declared using As Object in a Dim, Private or Public statement.

OKButton Dialog Item

Syntax:

OKButton X, Y, DX, DY[,.Field]

Group: User Dialog

Description:

Define an OK button item. Pressing the OK button updates the dlgvar field values and closes the dialog. (Dialog( ) function call returns -1.)

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this is omitted then the field name is "OK".

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,30,"Please push the OK button"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for ok)

End Sub

Option

Syntax:

Option Base [0|1]

-or-

Option Compare [Binary | Text]

-or-

Option Explicit

-or-

Option Private Module

Group: Declaration

Description:

Form 1: Set the default base index for array declarations. Affects Dim, Static, Private, Public and ReDim. Does not affect Array, ParamArray or arrays declare in a Type. Option Base 0 is the default.

Form 2: Set the default comparison mode for string.

• Option Compare Binary - compare string text using binary data (default)

• Option Compare Text - compare string text using the collation rules

String comparison using <, <=, =, >, >=, <>, Like and StrComp are affected by this mode's setting.

Form 3: Require all variables to be declared prior to use. Variables are declared using Dim, Private, Public, Static or as a parameter of Sub, Function or Property blocks.

Form 4: Public symbols defined by the module are only accessible from the same project.

Example:

Option Base 1

Option Explicit

Sub Main

Dim A

Dim C(2) ' same as Dim C(1 To 2)

Dim D(0 To 2)

A = 1

B = 2 ' B has not been declared

End Sub

OptionButton Dialog Item

Syntax:

OptionButton X, Y, DX, DY, Title$[,.Field]

Group: User Dialog

Description:

Define an option button item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ The value of this string is the title of the option button.

See Also: Begin Dialog, Dim As UserDialog, OptionGroup.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

OptionGroup.options

OptionButton 10,30,180,15,"Option &0"

OptionButton 10,45,180,15,"Option &1"

OptionButton 10,60,180,15,"Option &2"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.options = 2

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.options

End Sub

OptionGroup Dialog Item

Syntax:

OptionGroup.Field

OptionButton X, Y, DX, DY, Title$[,.Field]

OptionButton X, Y, DX, DY, Title$[,.Field]

Group: User Dialog

Description:

Define a optiongroup and option button items.

Parameters:

  • Field The value of the option group is accessed via this field. This first option button is 0, the second is 1, etc.

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ The value of this string is the title of the option button.

See Also: Begin Dialog, Dim As UserDialog, OptionButton.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

OptionGroup.options

OptionButton 10,30,180,15,"Option &0"

OptionButton 10,45,180,15,"Option &1"

OptionButton 10,60,180,15,"Option &2"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.options = 2

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.options

End Sub

Param

[ [Optional] [ | ByVal | ByRef ] | ParamArray ] param[type][( )] [As type] [ = default value ]

The param receives the value of the associated expression in the Declare, Sub, Function or Property call. (See arglist.)

An Optional param may be omitted from the call. It may also have a default value. The parameter receives the default value if a value is not specified by the call. If the default value is omitted, the parameter is a Variant and no value is specified in the call then IsMissing will return True.

All parameters following an Optional parameter must also be Optional.

ParamArray may be used on the final param. It must be an array of Variant type. It must not follow any Optional parameters. The ParamArray receives all the expressions at the end of the call as an array. If LBound(param) > UBound(param) then the ParamArray didn't receive any expressions.

If the param is not ByVal and the expression is merely a variable then the param is a reference to that variable (ByRef). (Changing param changes the variable.) Otherwise, the parameter variable is local to the procedure, so changing its value does not affect the caller.

Use param( ) to specify an array parameter. An array parameter must be referenced and can not be passed by value. The bounds of the parameter array are available via LBound( ) and UBound( ).

Picture Dialog Item

Syntax:

Picture X, Y, DX, DY, FileName$, Type[,.Field]

Group: User Dialog

Description:

Define a picture item. The bitmap is automatically sized to fit the item's entire area.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • FileName$ The value of this string is the.BMP file shown in the picture control.

  • Type This numeric value indicates the type of bitmap used. See below.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this identifier is omitted then the first two words of the title are used.

Type

Effect

0

FileName is the name of the bitmap file. If the file does not exist then "(missing picture)" is displayed.

3

The clipboard's bitmap is displayed. Not supported.

+16

Instead of displaying "(missing picture)" a run-time error occurs.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Picture 10,10,180,75,"SAMPLE.BMP",0

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for ok)

End Sub

Order of Precedence

When several operators are used in an expression, each operator is evaluated in a predetermined order. Operators are evaluated in this order:

  1. ^ (power)

  2. - (negate)

  3. * (multiply), / (divide)

  4. \ (integer divide)

  5. Mod (integer remainder)

  6. + (add), - (difference)

  7. & (string concatenate)

  8. = (equal), <> (not equal), < (less than) > (greater than), <= (less than or equal to), >= (greater than or equal to), Like, (string similarity) Is (object equivalence)

  9. Not (logical bitwise invert)

  10. And (logical bitwise and)

  11. Or (logical or bitwise or)

  12. Xor (logical or bitwise exclusive-or)

  13. Eqv (logical or bitwise equivalence)

  14. Imp (logical or bitwise implication)

Operators shown on the same line are evaluated from left to right.

Private

 

Syntax:

Private [WithEvents] name[type][([dim[,...]])] [As [New] type][,...]

Group: Declaration

Description:

Create arrays (or simple variables) which are available to the entire macro/module, but not other macros/modules. Dimension var array(s) using the dims to establish the minimum and maximum index value for each dimension. If the dims are omitted then a scalar (single value) variable is defined. A dynamic array is declared using ( ) without any dims. It must be ReDimensioned before it can be used. The Private statement must be placed outside of Sub, Function or Property blocks.

See Also: Dim, Option Base, Public, ReDim, Static, WithEvents.

Example:

Private A0,A1(1),A2(1,1)

Sub Init

A0 = 1

A1(0) = 2

A2(0,0) = 3

End Sub

Sub Main

Init

Debug.Print A0;A1(0);A2(0,0) ' 1 2 3

End Sub

Procedure

A subroutine, function or property.

Property

An object provides methods and properties. Properties may be used as values (like a function call) or changed (using assignment syntax).

If the property name contains characters that are not legal in a name, surround the property name with [].

App.[Title$]

Syntax:

[ | Private | Public | Friend ] [ Default ] Property Get name[type][([param[,...]])] [As type[()]]

statements

End Property

-or-

[ | Private | Public | Friend ] Property [Let|Set] name[([param[,...]])]

statements

End Property

Group: Declaration

Description:

User defined property. The property defines a set of statements to be executed when its value is used or changed. A property acts like a variable, except that getting its value calls Property Get and changing its value calls Property Let (or Property Set). Property Get and Property Let with the same name define a property that holds a value. Property Get and Property Set with the same name define a property that holds an object reference. The values of the calling arglist are assigned to the params. (For Property Let and Property Set the last parameter is the value on the right hand side of the assignment operator.)

Property defaults to Public if Private, Public or Friend are not is specified.

See Also: Function, Sub.

Example:

Dim X_Value

Property Get X()

X = X_Value

End Property

Property Let X(NewValue)

If Not IsNull(NewValue) Then X_Value = NewValue

End Property

Sub Main

X = "Hello"

Debug.Print X

X = Null

Debug.Print X

End Sub

Public

Syntax:

Public [WithEvents] name[type][([dim[,...]])] [As [New] type][,...]

Group: Declaration

Description:

Create arrays (or simple variables) which are available to the entire macro/module and other macros/modules. Dimension var array(s) using the dims to establish the minimum and maximum index value for each dimension. If the dims are omitted then a scalar (single value) variable is defined. A dynamic array is declared using ( ) without any dims. It must be ReDimensioned before it can be used. The Public statement must be placed outside of Sub, Function or Property blocks.

See Also: Dim, Option Base, Private, ReDim, Static, WithEvents.

Example:

Public A0,A1(1),A2(1,1)

Sub Init

A0 = 1

A1(0) = 2

A2(0,0) = 3

End Sub

Sub Main

Init

Debug.Print A0;A1(0);A2(0,0) ' 1 2 3

End Sub

PushButton Dialog Item

Syntax:

PushButton X, Y, DX, DY, Title$[,.Field]

Group: User Dialog

Description:

Define a push button item. Pressing the push button updates the dlgvar field values and closes the dialog. (Dialog( ) function call returns the push button's ordinal number in the dialog. The first push button returns 1.)

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ The value of this string is the title of the push button control.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this identifier is omitted then the first two words of the title are used.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,30,"Please push the DoIt button"

OKButton 40,90,40,20

PushButton 110,90,60,20,"&Do It"

End Dialog

Dim dlg As UserDialog

Debug.Print Dialog(dlg)

End Sub

Statement

Zero or more instructions. A statement is at least one line long. Begin Dialog, Do, For, If (multiline), Select Case, While and With statements are always more than one line long. A single line statement continues on the next line if it ends a line with a space and an underscore ' _'.

S$ = "This long string is easier to read, " + "if it is broken across two lines."

Debug.Print S$

Static

Syntax:

Static name[type][([dim[,...]])][As [New] type][,...]

Group: Declaration

Description:

A static variable retains it value between procedure calls. Dimension var array(s) using the dims to establish the minimum and maximum index value for each dimension. If the dims are omitted then a scalar (single value) variable is defined. A dynamic array is declared using ( ) without any dims. It must be ReDimensioned before it can be used.

See Also: Dim, Option Base, Private, Public, ReDim.

Example:

Sub A

Static X

Debug.Print X

X = "Hello"

End Sub

Sub Main

A

A ' prints "Hello"

End Sub

Str

An expression that returns a string result.

"Hello"

S$

S$ + " Goodbye"

S$ & " Goodbye"

Mid$(S$,2)

Strarray

A variable that holds an array of string values. The name of a string variable may be followed by a $.

StreamNum

An expression that returns a numeric result. Streams 1 through 255 are private to each macro. Streams 256 through 511 are shared by all macros.

Strvar

A variable that holds one string value. The name of a string variable may be followed by a $. FirstName$

Sub

 

Syntax:

[ | Private | Public | Friend ] Sub name[([param[,...]])]

statements

End Sub

Group: Declaration

Description:

User defined subroutine. The subroutine defines a set of statements to be executed when it is called. The values of the calling arglist are assigned to the params. A subroutine does not return a result.

Sub defaults to Public if Private, Public or Friend are not is specified.

See Also: Declare, Function, Property.

Example:

Sub IdentityArray(A()) ' A() is an array of numbers

For I = LBound(A) To UBound(A)

A(I) = I

Next I

End Sub

Sub CalcArray(A(),B,C) ' A() is an array of numbers

For I = LBound(A) To UBound(A)

A(I) = A(I)*B+C

Next I

End Sub

Sub ShowArray(A()) ' A() is an array of numbers

For I = LBound(A) To UBound(A)

Debug.Print "(";I;")=";A(I)

Next I

End Sub

Sub Main

Dim X(1 To 4)

IdentityArray X() ' X(1)=1, X(2)=2, X(3)=3, X(4)=4

CalcArray X(),2,3 ' X(1)=5, X(2)=7, X(3)=9, X(4)=11

ShowArray X() ' print X(1), X(2), X(3), X(4)

End Sub

Text Dialog Item

Syntax:

Text X, Y, DX, DY, Title$[,.Field][, Options]

Group: User Dialog

Description:

Define a text item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Title$ The value of this string is the title of the text control.

  • Field This identifier is the name of the field. The dialogfunc receives this name as string. If this identifier is omitted then the first two words of the title are used.

  • Options This numeric value controls the alignment of the text. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

Text is left aligned.

1

Text is right aligned.

2

Text is centered.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

Dialog dlg ' show dialog (wait for ok)

End Sub

TextBox Dialog Item

Syntax:

TextBox X, Y, DX, DY,.Field$[, Options]

Group: User Dialog

Description:

Define a textbox item.

Parameters:

  • X This number value is the distance from the left edge of the dialog box. It is measured in 1/8th of the average character width for the dialog's font.

  • Y This number value is the distance from the top edge of the dialog box. It is measured in 1/12th of the character height for the dialog's font.

  • DX This number value is the width. It is measured in 1/8th of the average character width for the dialog's font.

  • DY This number value is the height. It is measured in 1/12th of the character height for the dialog's font.

  • Field The value of the text box is accessed via this field.

  • Options This numeric value controls the type of text box. Choose one value from following table. (If this numeric value omitted then zero is used.)

Option

Description

0

Text box allows a single line of text to be entered.

1

Text box allows multiple lines of text can be entered.

-1

Text box allows a hidden password can be entered.

See Also: Begin Dialog, Dim As UserDialog.

Example:

Sub Main

Begin Dialog UserDialog 200,120

Text 10,10,180,15,"Please push the OK button"

TextBox 10,25,180,20,.Text$

OKButton 80,90,40,20

End Dialog

Dim dlg As UserDialog

dlg.Text$ = "none"

Dialog dlg ' show dialog (wait for ok)

Debug.Print dlg.Text$

End Sub

Type

Syntax:

[ | Private | Public ] Type name

elem [([dim[,...]])] As [New] type

[...]

End Type

Group: Declaration

Description:

Define a new usertype. Each elem defines an element of the type for storing data. As [New] type defines the type of data that can be stored. A user defined type variable has a value for each elem. Use.elem to access individual element values.

Type defaults to Public if neither Private or Public is specified.

Example:

Type Employee

FirstName As String

LastName As String

Title As String

Salary As Double

End Type

Sub Main

Dim e As Employee

e.FirstName = "John"

e.LastName = "Doe"

e.Title = "President"

e.Salary = 100000

Debug.Print e.FirstName '"John"

Debug.Print e.LastName '"Doe"

Debug.Print e.Title '"President"

Debug.Print e.Salary ' 100000

End Sub

Type Symbols

Variable and parameter types, as well as, function and property results may be specified using a type character as the last character in their name.

Type char As Type

% Integer

? PortInt

& Long

! Single

# Double

@ Currency

$ String

Userenum

User defined enums are defined with Enum.

Usertype

User defined types are defined with Type.

Usertypevar

A user defined type variable holds values for elements of the user defined type. User defined types are defined using Type.

Declare with Dim, Private, Public or Static.

Declare as a parameter of Sub, Function or Property definition.

Var

A variable holds either a string, a numeric value or an array of values depending on its type.

Variantvar

A variant variable can hold any type of value (except String*n or usertypevar). or it can hold an array.

WithEvents

Syntax:

[Dim | Private | Public] WithEvents name As objtype[,...]

Group: Declaration

Description:

Dimensioning a module level variable WithEvents allows the macro to implement event handling Subs. The variable's As type must be a type from a referenced type library (or language extension) which implements events.

Example:

Dim WithEvents X As Thing

Sub Main

Set X = New Thing

X.DoIt ' DoIt method raises DoingIt event

End Sub

Private Sub X_DoingIt

Debug.Print "X.DoingIt event"

End Sub