Examples: Dim statement

Example 1

' Declare a one-dimensional Integer array and a Single 
' variable.
Dim philaMint(5) As Integer 
Dim x As Single
x! = 10.0
philaMint%(0) = 3                 ' Assigns an Integer value
philaMint%(1) = x                 ' Converts Single 10.0 to Integer 10
Print DataType(philaMint%(0)); DataType(philaMint%(1))
' Output:
' 2  2
' Both values are Integers.

Example 2

Dim xB As New Button("Merge", 60, 125)

xB is declared as an object reference variable to hold references to objects of the class named Button. A new Button object is created. For this example, suppose that the constructor sub for the class Button takes three arguments: a name for a button, and x- and y-position coordinates for the location of the button. The new button created is named "Merge," and positioned at (60, 125). A reference to this button is assigned to xB.

Example 3

' Declare iVer and kVer as Integer variables. Note that 
' the phrase As Integer must be repeated to declare both 
' variables as Integer.
Dim iVer As Integer, kVer As Integer
' Declare nVer as an Integer variable. 
' The declared type of mVer is Variant, the default
' data type, because no data type is declared for mVer: 
' there is no As type phrase for mVer, and no data type
' suffix attached to mVer.
Dim mVer, nVer As Integer
Print TypeName(mVer), TypeName(nVer%)         ' Prints EMPTY INTEGER

Example 4

' Declare marCell and perDue as Integer variables.
' The phrase As Integer declares marCell as an Integer
' variable. The data type suffix % declares perDue as an
' Integer variable.
Dim marCell As Integer, perDue%
Print TypeName(marCell), TypeName(perDue%)    ' Prints INTEGER INTEGER

Example 5

Dim marCell% As Integer
' Error, because the Dim statement attempts to declare
' the Integer variable marCell using both the data type
' suffix character for Integer, and the data type name
' Integer. The declaration should include one or the 
' other, but not both.

Example 6

' A data type suffix character is optional in references to a 
' declared variable.
' Declare marCell as an Integer variable.
Dim marCell As Integer
' Use the data type suffix character in a reference to marCell.
marCell% = 1
' Refer to marCell without using the suffix character.
Print marCell                        ' Prints 1

Example 7

' Declare marCell as an Integer variable.
Dim marCell As Integer
' Assign integer value to marCell.
marCell% = 1
Print marCell$
' Error, because the Print statement refers to marCell
' using the data type suffix character $ for a String
' variable, but marCell was declared as an Integer.

Example 8

Dim db As New NotesDatabase ("Server003", "discuss.nsf")

This Dim objRef As New prodClass(argList) statement declares an object reference to, and creates an instance of, the Notes/Domino NotesDatabase class. The Dim statement for creating a NotesDomino object requires two string arguments: a server name and a database path name.