Syntax |
Const name [As type] = expression [,name [As type] = expression]... |
Description |
Declares a constant for use within the current script. |
Comments |
The name is only valid within the current Basic Control Engine script. Constant names must follow these rules: 1. Must begin with a letter. 2. May contain only letters, digits, and the underscore character. 3. Must not exceed 80 characters in length. 4. Cannot be a reserved word. Constant names are not case-sensitive. |
|
The expression must be assembled from literals or other constants. Calls to functions are not allowed except calls to the Chr$ function, as shown below: Const s$ = "Hello, there" + Chr(44) Constants can be given an explicit type by declaring the name with a type-declaration character, as shown below: Const a% = 5 'Constant
Integer whose value is 5 |
|
The type can also be given by specifying the As type clause: Const a As Integer = 5 'Constant
Integer whose value is 5 You cannot specify both a type-declaration character and the type: Const a% As Integer = 5 'THIS IS ILLEGAL. If an explicit type is not given, then the Basic Control Engine script will choose the most imprecise type that completely represents the data, as shown below: Const a = 5 'Integer
constant |
|
Constants defined within a Sub or Function are local to that subroutine or function. Constants defined outside of all subroutines and function can be used anywhere within that script. The following example demonstrates the scoping of constants: Const DefFile ="default.txt" Sub Test1 Const DefFile ="foobar.txt" Sub Test2 MsgBox
DefFile 'Displays
"default.txt". |
Example |
This example displays the declared constants in a dialog box (crlf produces a new line in the dialog box). Const crlf = Chr$(13) + Chr$(10) Const greeting As String = "Hello, " Sub Main() r = InputBox("Please enter your
name","Enter Name") |
See Also |
DefType (statement); Let (statement); = (statement); Constants (topic). |
C |