Lr225 Language Ref BasicScript
Lr225 Language Ref BasicScript
25
Language Reference
Summit Software
Confidential
Contents
Introduction ...........................................................................................................................1
Index ...................................................................................................................................561
This manual provides a complete reference for the BasicScript 2.25 scripting language.
It contains the following:
• The Language Summary provides you with a list of all functions, statements, and
methods in the BasicScript language. These items are grouped by the task you wish
to accomplish, so you can easily find the BasicScript language item that will help
you do your work.
• The A-Z Reference provides detailed explanations of each item in the BasicScript
language. It also provides concise descriptions of important topics.
• Appendix A, “Language Elements by Platform,” provides a quick, alphabetic list of
the items in the BasicScript language that also shows the platforms supported by
each item.
Typographic Conventions
This manual uses the following typographic conventions.
Convention Description
Convention Description
The following table summarizes the functions, statements, methods and other items that
belong to the BasicScript language. Items are grouped by the tasks you might wish to
perform.
' (keyword)
Syntax 'text
Description Causes the compiler to skip all characters between this character and the end of the
current line.
Comments This is very useful for commenting your code to make it more readable.
Example Sub Main()
'This whole line is treated as a comment.
i$="Strings" 'This is a valid assignment with a comment.
This line will cause an error (the apostrophe is missing).
End Sub
- (operator)
Syntax 1 expression1 - expression2
Syntax 2 -expression
Description Returns the difference between expression1 and expression2 or, in the second syntax,
returns the negation of expression.
Comments Syntax 1
The type of the result is the same as that of the most precise expression, with the
following exceptions:
If one expression is and the other expression is then the type of the result is
Syntax 2
If expression is numeric, then the type of the result is the same type as expression, with
the following exception:
• If expression is Boolean, then the result is Integer.
Note: In 2's complement arithmetic, unary minus may result in an overflow with
Integer and Long variables when the value of expression is the largest negative
number representable for that data type. For example, the following generates an
overflow error:
Sub Main()
Dim a As Integer
a = -32768
a = -a 'Generates overflow here.
End Sub
When negating variants, overflow will never occur because the result will be
automatically promoted: integers to longs and longs to doubles.
#Const (directive)
Syntax #Const constname = expression
#If...Then...#Else (directive)
Syntax #If expression Then
[statements]
[#ElseIf expression Then
[statements]]
[#Else
[statements]]
#End If
Description Causes the compiler to include or exclude sections of code based on conditions.
Comments The expression represents any valid BasicScript Boolean expression evaluating to True
of False. The expression may consist of literals, operators, constants defined with
#Const, and any of the following predefined constants:
Constant Value
AIX True if development environment is AIX.
HPUX True if development environment is HPUX.
Constant Value
& (operator)
Syntax expression1 & expression2
Description Returns the concatenation of expression1 and expression2.
Comments If both expressions are strings, then the type of the result is String. Otherwise, the type
of the result is a String variant.
When nonstring expressions are encountered, each expression is converted to a String
variant. If both expressions are Null, then a Null variant is returned. If only one
expression is Null, then it is treated as a zero-length string. Empty variants are also
treated as zero-length strings.
In many instances, the plus (+) operator can be used in place of &. The difference is that
+ attempts addition when used with at least one numeric expression, whereas & always
concatenates.
Example 'This example assigns a concatenated string to variable s$ and
'a string to s2$, then concatenates the two variables and
'displays the result in a dialog box.
Sub Main()
s$ = "This string" & " is concatenated"
s2$ = " with the & operator."
MsgBox s$ & s2$
End Sub
See Also + (operator); Operator Precedence (topic).
Platform(s) All.
() (keyword)
Syntax 1 ...(expression)...
Syntax 2 ...,(parameter),...Description
* (operator)
Syntax expression1 * expression2
Description Returns the product of expression1 and expression2.
Comments The result is the same type as the most precise expression, with the following
exceptions:
If one expression is and the other expression is then the type of the result is
. (keyword)
Syntax 1 [Link]
Syntax 2 [Link]
/ (operator)
Syntax expression1 / expression2
Description Returns the quotient of expression1 and expression2.
Comments The type of the result is Double, with the following exceptions:
If one expression is and the other expression is then the type of the result is
\ (operator)
Syntax expression1 \ expression2
Description Returns the integer division of expression1 and expression2.
Comments Before the integer division is performed, each expression is converted to the data type of
the most precise expression. If the type of the expressions is either Single, Double,
Date, or Currency, then each is rounded to Long.
If either expression is a Variant, then the following additional rules apply:
• If either expression is Null, then the result is Null.
• Empty is treated as an Integer of value 0.
Example 'This example assigns the quotient of two literals to a variable
'and displays the result.
Sub Main()
s% = 100.99 \ 2.6
MsgBox "Integer division of 100.99\2.6 is: " & s%
End Sub
^ (operator)
Syntax expression1 ^ expression2
Description Returns expression1 raised to the power specified in expression2.
_ (keyword)
Syntax text1 _
text2
Description Line-continuation character, which allows you to split a single BasicScript statement
onto more than one line.
Comments The line-continuation character cannot be used within strings and must be preceded by
white space (either a space or a tab).
The line-continuation character can be followed by a comment, as shown below:
i = 5 + 6 & _ 'Continue on the next line.
"Hello"
Example Const crlf = Chr$(13) + Chr$(10)
Sub Main()
'The line-continuation operator is useful when concatenating
'long strings.
message = "This is a line of text that" + crlf + "extends" _
Platform(s) All.
+ (operator)
Syntax expression1 + expression2
Description Adds or concatenates two expressions.
Comments Addition operates differently depending on the type of the two expressions:
and the other
If one expression is expression is then
Numeric Numeric Perform a numeric add (see below).
String String Concatenate, returning a string.
Numeric String A runtime error is generated.
Variant String Concatenate, returning a String variant.
Variant Numeric Perform a variant add (see below).
Empty variant Empty variant Return an Integer variant, value 0.
Empty variant Any data type Return the non-Empty operand
unchanged.
Null variant Any data type Return Null.
Variant Variant Add if either is numeric; otherwise,
concatenate.
When using + to concatenate two variants, the result depends on the types of each
variant at runtime. You can remove any ambiguity by using the & operator.
Numeric Add
A numeric add is performed when both expressions are numeric (i.e., not variant or
string). The result is the same type as the most precise expression, with the following
exceptions:
If one expression is and the other expression is then the type of the result is
Single Long Double
Boolean Boolean Integer
A runtime error is generated if the result overflows its legal range.
Variant Add
If both expressions are variants, or one expression is Numeric and the other expression
is Variant, then a variant add is performed. The rules for variant add are the same as
those for normal numeric add, with the following exceptions:
• If the type of the result is an Integer variant that overflows, then the result is a
Long variant.
• If the type of the result is a Long, Single, or Date variant that overflows, then the
result is a Double variant.
Example 'This example assigns string and numeric variable values and
'then uses the + operator to concatenate the strings and form
'the sums of numeric variables.
Sub Main()
i$ = "Concatenation" + " is fun!"
j% = 120 + 5 'Addition of numeric literals
k# = j% + 2.7 'Addition of numeric variable
MsgBox "This concatenation becomes: '" i$ + _
Str(j%) + Str(k#) & "'"
End Sub
< (operator)
See Comparison Operators (topic).
<= (operator)
See Comparison Operators (topic).
<> (operator)
See Comparison Operators (topic).
= (statement)
Syntax variable = expression
Description Assigns the result of an expression to a variable.
Comments When assigning expressions to variables, internal type conversions are performed
automatically between any two numeric quantities. Thus, you can freely assign numeric
quantities without regard to type conversions. However, it is possible for an overflow
error to occur when converting from larger to smaller types. This occurs when the larger
type contains a numeric quantity that cannot be represented by the smaller type. For
example, the following code will produce a runtime error:
Dim amount As Long
Dim quantity As Integer
amount = 400123 'Assign a value out of range for int.
quantity = amount 'Attempt to assign to Integer.
When performing an automatic data conversion, underflow is not an error.
The assignment operator (=) cannot be used to assign objects. Use the Set statement
instead.
Example Sub Main()
a$ = "This is a string"
b% = 100
c# = 1213.3443
MsgBox a$ & "," & b% & "," & c#
End Sub
See Also Let (statement); Operator Precedence (topic); Set (statement); Expression Evaluation
(topic).
Platform(s) All.
= (operator)
See Comparison Operators (topic).
> (operator)
See Comparison Operators (topic).
>= (operator)
See Comparison Operators (topic).
Abs (function)
Syntax Abs(expression)
ActivateControl (statement)
Syntax ActivateControl control
Description Sets the focus to the control with the specified name or ID.
Comments The control parameter specifies either the name or the ID of the control to be activated,
as shown in the following table:
If control is Then
String A control by that name is activated.
For push buttons, option buttons, or check boxes, the control
with this name is activated. For list boxes, combo boxes, and
text boxes, the control that immediately follows the text
control with this name is activated.
Numeric A control with this ID is activated. The ID is first converted to
an Integer.
The ActivateControl statement generates a runtime error if the dialog control
referenced by control cannot be found.
You can use the ActivateControl statement to set the focus to a custom control within a
dialog box. First, set the focus to the control that immediately precedes the custom
control, then simulate a Tab keypress, as in the following example:
ActivateControl "Portrait"
DoKeys "{TAB}"
Example 'This example runs Notepad using Program Manager's Run command.
'It uses the ActivateControl command to switch focus between the
'different controls of the Run dialog box.
Sub Main()
If AppFind$("Program Manager") = "" Then Exit Sub
AppActivate "Program Manager"
Menu "[Link]"
SendKeys "Notepad"
ActivateControl "Run minimized"
SendKeys " "
ActivateControl "OK"
SendKeys "{Enter}"
End Sub
And (operator)
Syntax result = expression1 And expression2
Description Performs a logical or binary conjunction on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or Null variants, then a logical
conjunction is performed as follows:
If expression1 is and expression2 is then the result is
Binary Conjunction
If the two expressions are Integer, then a binary conjunction is performed, returning an
Integer result. All other numeric types (including Empty variants) are converted to
Long, and a binary conjunction is then performed, returning a Long result.
Binary conjunction forms a new value based on a bit-by-bit comparison of the binary
representations of the two expressions according to the following table:
If bit in expression1 is and bit in expression2 is the result is
1 1 1
0 1 0
1 0 0
0 0 0
Examples Sub Main()
n1 = 1001
n2 = 1000
b1 = True
b2 = False
'This example performs a numeric bitwise And operation and
'stores the result in N3.
n3 = n1 And n2
AnswerBox (function)
Syntax AnswerBox(prompt [,[button1] [,[button2] [,[button3] [,[title]
[,helpfile,context]]]]]]])
Description Displays a dialog box prompting the user for a response and returns an Integer
indicating which button was clicked (1 for the first button, 2 for the second, and so on).
Comments The AnswerBox function takes the following parameters:
Parameter Description
prompt Text to be displayed above the text box. The prompt parameter can
be any expression convertible to a String.
BasicScript resizes the dialog box to hold the entire contents of
prompt, up to a maximum width of 5/8 of the width of the screen
and a maximum height of 5/8 of the height of the screen. BasicScript
word-wraps any lines too long to fit within the dialog box and
truncates all lines beyond the maximum number of lines that fit in
the dialog box.
You can insert a carriage-return/line-feed character in a string to
cause a line break in your message.
A runtime error is generated if this parameter is Null.
button1 The text for the first button. If omitted, then "OK and "Cancel" are
used. A runtime error is generated if this parameter is Null.
button2 The text for the second button. A runtime error is generated if this
parameter is Null.
button3 The text for the third button. A runtime error is generated if this
parameter is Null.
Parameter Description
title String specifying the title of the dialog. If missing, then the default
title is used.
helpfile Name of the file containing context-sensitive help for this dialog. If
this parameter is specified, then context must also be specified.
context Number specifying the ID of the topic within helpfile for this
dialog's help. If this parameter is specified, then helpfile must also
be specified.
The width of each button is determined by the width of the widest button.
The AnswerBox function returns 0 if the user selects Cancel.
If both the helpfile and context parameters are specified, then context-sensitive help can
be invoked using the help key (F1 on most platforms). Invoking help does not remove
the dialog.
Example 'This example displays a dialog box containing three buttons. It
'displays an additional message based on which of the three
'buttons is selected.
Sub Main()
r% = AnswerBox("Copy files?", "Save", "Restore", "Cancel")
Select Case r%
Case 1
MsgBox "Files will be saved."
Case 2
MsgBox "Files will be restored."
Case Else
MsgBox "Operation canceled."
End Select
End Sub
AppActivate (statement)
Syntax AppActivate title | taskID,[wait]
Note: When activating applications using the task ID, it is important to declare the
variable used to hold the task ID as a Variant. The type of the ID depends on the
platform on which BasicScript is running.
Macintosh: On the Macintosh, the title parameter specifies the title of the desired
application. The MacID function can be used to specify the application signature of the
application to be activated:
AppActivate MacID(text$) | task
The title parameter is a four-character string containing an application signature. A
runtime error occurs if the MacID function is used on platforms other than the
Macintosh.
AppClose (statement)
Syntax AppClose [title | taskID]
AppFilename$ (function)
Syntax AppFilename$([title | taskID])
Description Returns a String containing the full name of the application matching either title or
taskID.
Comments The title parameter specifies the title of the application to find. If there is no exact
match, BasicScript will find an application whose title begins with title.
Alternatively, you can specify the ID of the task as returned by the Shell function.
The AppFind$ functions returns a String, whereas the AppFind function returns a
String variant. If the specified application cannot be found, then AppFind$ returns a
zero-length string and AppFind returns Empty. Using AppFind allows you detect
failure when attempting to find an application with no caption (i.e., Empty is returned
instead of a zero-length String).
AppFind$ is generally used to determine whether a given application is running. The
following expression returns True if Microsoft Word is running:
AppFind$("Microsoft Word")
Example 'This example checks to see whether Excel is running before
'activating it.
Sub Main()
If AppFind$("Microsoft Excel") <> "" Then
AppActivate "Microsoft Excel"
Else
MsgBox "Excel is not running."
End If
End Sub
See Also AppFilename$ (function).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows: Under Windows, this function returns a String containing the exact text
appearing in the title bar of the active application's main window.
AppGetActive$ (function)
Syntax AppGetActive$()
AppGetPosition (statement)
Syntax AppGetPosition x,y,width,height [,title | taskID]
The title parameter is the exact string appearing in the title bar of the named
application's main window. If no application is found whose title exactly matches title,
then a second search is performed for applications whose title string begins with title. If
more than one application is found that matches title, then the first application
encountered is used.
Under Windows 95, applications adhere to a convention where the caption contains the
name of the file before the name of the application. For example, under NT, the caption
for Notepad is "Notepad - (Untitled)", whereas under Windows 95, the caption is
"Untitled - Notepad". You must keep this in mind when specifying the title parameter.
AppGetState (function)
Syntax AppGetState[([title | taskID])]
Description Returns an Integer specifying the state of the specified top-level window.
Comments The AppGetState function returns any of the following values:
If the window is Then AppGetState returns Value
Maximized ebMinimized 1
Minimized ebMaximized 2
Restored ebRestored 3
The title parameter is a String containing the name of the desired application. If it is
omitted, then the AppGetState function returns the name of the active application.
Alternatively, you can specify the ID of the task as returned by the Shell function.
Example 'This example saves the state of Program Manager, changes it,
'then restores it to its original setting.
Sub Main()
If AppFind$("Program Manager") = "" Then
MsgBox "Can't find Program Manager."
Exit Sub
End If
AppActivate "Program Manager"'Activate Program Manager.
state = AppGetState'Save its state.
AppMinimize 'Minimize it.
MsgBox "Program Manager is minimized. Select OK to restore
it."
AppActivate "Program Manager"
AppSetState state 'Restore it.
End Sub
AppHide (statement)
Syntax AppHide [title | taskID]
Under Windows 95, applications adhere to a convention where the caption contains the
name of the file before the name of the application. For example, under NT, the caption
for Notepad is "Notepad - (Untitled)", whereas under Windows 95, the caption is
"Untitled - Notepad". You must keep this in mind when specifying the title parameter.
AppList (statement)
Syntax AppList AppNames$()
AppMaximize (statement)
Syntax AppMaximize [title | taskID]
Comments The title parameter is a String containing the name of the desired application. If it is
omitted, then the AppMaximize function maximizes the active application.
Alternatively, you can specify the ID of the task as returned by the Shell function.
Example Sub Main()
AppMaximize "Program Manager"'Maximize Program Manager.
If AppFind$("NotePad") <> "" Then
AppActivate "NotePad"'Set the focus to NotePad.
AppMaximize 'Maximize it.
End If
End Sub
AppMinimize (statement)
Syntax AppMinimize [title | taskID]
AppMove (statement)
Syntax AppMove x,y [,title | taskID]
Description Sets the upper left corner of the named application to a given location.
Comments The AppMove statement takes the following parameters:
Parameter Description
AppRestore (statement)
Syntax AppRestore [title | taskID]
End Sub
See Also AppMaximize (statement); AppMinimize (statement); AppMove (statement); AppSize
(statement); AppClose (statement).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows, Win32: Under Windows, the title parameter is the exact string appearing in
the title bar of the named application's main window. If no application is found whose
title exactly matches title, then a second search is performed for applications whose title
string begins with title. If more than one application is found that matches title, then the
first application encountered is used.
Under Windows 95, applications adhere to a convention where the caption contains the
name of the file before the name of the application. For example, under NT, the caption
for Notepad is "Notepad - (Untitled)", whereas under Windows 95, the caption is
"Untitled - Notepad". You must keep this in mind when specifying the title parameter.
AppRestore will have an effect only if the main window of the named application is
either maximized or minimized.
AppRestore will have no effect if the named window is hidden.
AppRestore generates a runtime error if the named application is not enabled, as is the
case if that application is currently displaying a modal dialog box.
AppSetState (statement)
Syntax AppSetState newstate [,title | taskID ]
Description Maximizes, minimizes, or restores the named application, depending on the value of
newstate.
Comments The AppSetState statement takes the following parameters:
Parameter Description
newstate An Integer specifying the new state of the window.
title A String containing the name of the application to change. If
omitted, then the active application is used.
taskID A number specifying the task ID of the application to be
activated. Acceptable task IDs are returned by the Shell
function.
The newstate parameter can be any of the following values:
Constant Value Description
ebMinimized 1 The named application is minimized.
AppShow (statement)
Syntax AppShow [title | taskID]
Under Windows 95, applications adhere to a convention where the caption contains the
name of the file before the name of the application. For example, under NT, the caption
for Notepad is "Notepad - (Untitled)", whereas under Windows 95, the caption is
"Untitled - Notepad". You must keep this in mind when specifying the title parameter.
AppShow generates a runtime error if the named application is not enabled, as is the
case if that application is displaying a modal dialog box.
AppSize (statement)
Syntax AppSize width,height [,title | taskID]
The title parameter is the exact string appearing in the title bar of the named
application's main window. If no application is found whose title exactly matches title,
then a second search is performed for applications whose title string begins with title. If
more than one application is found that matches title, then the first application
encountered is used.
Under Windows 95, applications adhere to a convention where the caption contains the
name of the file before the name of the application. For example, under NT, the caption
for Notepad is "Notepad - (Untitled)", whereas under Windows 95, the caption is
"Untitled - Notepad". You must keep this in mind when specifying the title parameter.
A runtime error results if the application being resized is not enabled, which is the case
if that application is displaying a modal dialog box when an AppSize statement is
executed.
AppType (function)
Syntax AppType [(title | taskID)]
Description Returns an Integer indicating the executable file type of the named application:
Returns If the file type is:
n = n + 1
End If
Next i
If n = 0 Then'Make sure at least one Windows app was found.
MsgBox "There are no running Windows applications."
Exit Sub
End If
ReDim Preserve wapps(n - 1) 'Resize to hold the exact number.
'Let the user pick one.
index% = SelectBox("Apps","Select an application:",wapps)
End Sub
ArrayDims (function)
Syntax ArrayDims(arrayvariable)
End If
End Sub
See Also LBound (function);UBound (function); Arrays (topic).
Platform(s) All.
Arrays (topic)
Fixed Arrays
The dimensions of fixed arrays cannot be adjusted at execution time. Once declared, a
fixed array will always require the same amount of storage. Fixed arrays can be declared
with the Dim, Private, or Public statement by supplying explicit dimensions. The
following example declares a fixed array of eleven strings (assuming the option base is
0):
Dim a(10) As String
Fixed arrays can be used as members of user-defined data types. The following example
shows a structure containing fixed-length arrays:
Type Foo
rect(4) As Integer
colors(10) As Integer
End Type
Dynamic Arrays
Dynamic arrays are declared without explicit dimensions, as shown below:
Public Ages() As Integer
Dynamic arrays can be resized at execution time using the Redim statement:
Redim Ages$(100)
Subsequent to their initial declaration, dynamic arrays can be redimensioned any
number of times. When redimensioning an array, the old array is first erased unless you
use the Preserve keyword, as shown below:
Redim Preserve Ages$(100)
Dynamic arrays cannot be members of user-defined data types.
Passing Arrays
Arrays are always passed by reference. When you pass an array, you can specify the
array name by itself, or with parentheses as shown below:
Dim a(10) As String
FileList a 'Both of these are OK
FileList a()
Querying Arrays
The following table describes the functions used to retrieve information about arrays.
Use this function To
LBound Retrieve the lower bound of an array. A runtime is generated if
the array has no dimensions.
UBound Retrieve the upper bond of an array. A runtime error is
generated if the array has no dimensions.
ArrayDims Retrieve the number of dimensions of an array. This function
returns 0 if the array has no dimensions.
Operations on Arrays
The following table describes the function that operate on arrays:
Use the command To
ArraySort (statement)
Syntax ArraySort array()
End Sub
See Also ArrayDims (function); LBound (function);UBound (function).
Platform(s) All.
Example 'This example fills an array with the ASCII values of the
'string's components and displays the result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
s$ = InputBox("Please enter a string.","Enter String")
If s$ = "" Then End'Exit if no string entered.
For i = 1 To Len(s$)
message = message & Asc(Mid$(s$,i,1)) & crlf
Next i
MsgBox "The Asc values of the string are:" & message
End Sub
See Also Chr, Chr$, ChrB, ChrB$, ChrW, ChrW$ (functions).
Platform(s) All.
Description Displays a dialog box requesting input from the user and returns that input as a String.
Comments The AskBox/AskBox$ functions take the following parameters:
Parameter Description
prompt$ String containing the text to be displayed above the text
box. The dialog box is sized to the appropriate width
depending on the width of prompt$. A runtime error is
generated if prompt$ is Null.
default$ String containing the initial content of the text box. The
user can return the default by immediately selecting OK. A
runtime error is generated if default$ is Null.
title$ String specifying the title of the dialog. If missing, then the
default title is used.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also
be specified.
context Number specifying the ID of the topic within helpfile for
this dialog's help. If this parameter is specified, then helpfile
must also be specified.
The AskBox$ function returns a String containing the input typed by the user in the text
box. A zero-length string is returned if the user selects Cancel.
The AskBox function returns a String variant containing the input typed by the user in
the text box. An Empty variant is returned if the user selects Cancel.
When the dialog box is displayed, the text box has the focus.
The user can type a maximum of 255 characters into the text box displayed by
AskBox$.
If both the helpfile and context parameters are specified, then a Help button is added in
addition to the OK and Cancel buttons. Context-sensitive help can be invoked by
selecting this button or using the help key (F1 on most platforms). Invoking help does
not remove the dialog.
Example 'This example asks the user to enter a filename and then
'displays what he or she has typed.
Sub Main()
s$ = AskBox$("Type in the filename:")
MsgBox "The filename was: " & s$
End Sub
Description Returns a String containing the text that the user typed.
Comments Unlike the AskBox/AskBox$ functions, the user sees asterisks in place of the characters
that are actually typed. This allows the hidden input of passwords.
The AskPassword/AskPassword$ functions take the following parameters:
Parameter Description
prompt$ String containing the text to be displayed above the text
box. The dialog box is sized to the appropriate width
depending on the width of prompt$. A runtime error is
generated if prompt$ is Null.
title$ String specifying the title of the dialog. If missing, then the
default title is used.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also
be specified.
Parameter Description
context Number specifying the ID of the topic within helpfile for
this dialog's help. If this parameter is specified, then helpfile
must also be specified.
When the dialog box is first displayed, the text box has the focus.
A maximum of 255 characters can be typed into the text box.
The AskPassword$ function returns the text typed into the text box, up to a maximum
of 255 characters. A zero-length string is returned if the user selects Cancel.
The AskPassword function returns a String variant. An Empty variant is returned if
the user selects Cancel.
If both the helpfile and context parameters are specified, then a Help button is added in
addition to the OK and Cancel buttons. Context-sensitive help can be invoked by
selecting this button or using the help key (F1 on most platforms). Invoking help does
not remove the dialog.
Example Sub Main()
s$ = AskPassword$("Type in the password:")
MsgBox "The password entered is: " & s$
End Sub
See Also MsgBox (statement); AskBox, AskBox$ (functions); InputBox, InputBox$ (functions);
OpenFileName$ (function); SaveFileName$ (function); SelectBox (function);
AnswerBox (function).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
Atn (function)
Syntax Atn(number)
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the CPU architecture on which BasicScript is executing.
Comments The following table describes what [Link]$ returns on various platforms:
Platform Sample return Value from [Link]$
Windows "Intel"
Win32 "Intel", "MIPS", "Alpha AXP", or "PowerPC"
OS/2 "Intel"
NetWare "Intel", "Motorola"
Macintosh "PowerPC", "68K"
UNIX "i386", "i486"
The [Link]$ property returns an empty string if the architecture cannot be
determined by BasicScript.
Example '
'Print the CPU architecture...
'
Sub Main()
MsgBox [Link]$
End Sub
See Also [Link]$ (property); [Link] (property).
Platform(s) All.
[Link] (method)
Syntax [Link](which)
Description Returns True if the specified capability exists on the current platform; returns False
otherwise.
Comments The which parameter is an Integer specifying the capability for which to test. It can be
any of the following values:
Value Returns True If
1 The platform supports disk drives
2 The platform supports system file attribute (ebSystem)
3 The platform supports the hidden file attribute (ebHidden)
4 The platform supports the volume label file attribute (ebVolume)
5 The platform supports the archive file attribute (ebArchive)
6 The platform supports denormalized floating-point math
7 The platform supports file locking (i.e., the Lock and Unlock
statements)
8 The platform uses big endian byte ordering
9 The internal string format used by BasicScript uses 2-byte characters.
10 The internal string format used by BasicScript is MBCS.
11 The platform supports wide characters.
12 The platform is MBCS.
Example 'This example tests to see whether your current platform
'supports disk drives and hidden file attributes and displays
'the result.
Sub Main()
message = "This operating system "
If [Link](1) Then
message = message & "supports disk drives."
Else
message = message & "does not support disk drives."
End If
MsgBox message
End Sub
See Also Cross-Platform Scripting (topic);[Link] (property).
Platform(s) All.
[Link] (property)
Syntax [Link]
Description Returns an Integer representing the code page for the current locale.
Comments Under Windows, Win32, NetWare, and OS/2, this property returns ANSI code page for
the current locale, such as 437 for MS-DOS Latin US or 932 for Japanese.
On the Macintosh, this property returns a number from 0 to 32 containing the script
code (e.g., 0 for Roman, 1 for Japanese, and so on) as defined by Apple.
Example Sub Main
If [Link] = ebWin16 And [Link] = 437 Then
MsgBox "Running US Windows"
Else if [Link] = ebWin32 And [Link] = 932 Then
MsgBox "Japanese NT"
End If
End Sub
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the end-of-line character sequence appropriate to the
current platform.
Comments This string will be either a carriage return, a carriage return/line feed, or a line feed.
Example 'This example writes two lines of text in a message box.
Sub Main()
MsgBox "This is the first line of text." & [Link]$ _
& "This is the second line of text."
End Sub
[Link] (property)
Syntax [Link]
Description Returns a Long representing the number of bytes of free memory in BasicScript's data
space.
Comments This function returns the size of the largest free block in BasicScript's data space.
Before this number is returned, the data space is compacted, consolidating free space
into a single contiguous free block.
[Link]$ (property)
Syntax [Link]$
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the locale under which BasicScript is running.
Comments The locale helps you identify information about your environment, such as the date
formats, time format, and other country-sensitive information.
The following table describes the returned value from [Link]$ on various
platforms:
Platform Return value from [Link]$
Win32 Returns a string in the format:
abbrevlang,langid,nativelang,englang
abbrevlang: Three-letter name of the language. This name is
formed by taking the two-letter language abbreviation as
found in the ISO Standard 639 and adding a third letter, as
appropriate, to indicate the sublanguage. This is the same as
that name found in the sLanguage item in the intl section of
the Windows 3.1 [Link] file.
langid: Language ID as defined by the operating system.
nativelang: Native name of the language.
englang: Full english name of the language as defined by ISO
standard 639.
Windows Returns a string in the format:
abbrevlang,country
country: Native name of the country.
abbrevlang: Three-letter name of the language. This name is
formed by taking the two-letter language abbreviation as
found in the ISO Standard 639 and adding a third letter, as
appropriate, to indicate the sublanguage. This is the same as
that name found in the sLanguage item in the intl section of
the Windows 3.1 [Link] file.
Netware Returns a string in the following format:
countrycode [,countryname]
countrycode: Country code based on the telephone country
code (1 = US, 2 = Canada, and so on).
countryname: Name of the country (such as "USA"). The
name of country is only provided for NetWare version 4.0 or
later.
[Link]$ (property)
Syntax [Link]$
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the version of the operating system under which
BasicScript is running.
Comments The following table describes the what this function returns for various platforms:
Sample return value from
Platform [Link]$
Windows "Microsoft"
Win32 "Microsoft"
OS/2 "IBM"
Netware Returns the name of the company that distributed NetWare.
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the version of the operating system under which
BasicScript is running.
Example '
'This example checks the Windows version to ensure that a
'feature is supported.
'
Sub Main
If [Link]$ = "Windows"
If [Link]$ <= 3 Then
MsgBox "That feature is not supported."
Else
MsgBox "Windows version 3.1 or greater"
End If
End If
End Sub
Platform(s) All.
Platform Notes Win32, Macintosh: The version number is returned in the following format:
[Link]
The parts of the version number are described in the following table:
Part Description
major Identifies the major version number of the operating system.
minor Identifies the minor version number of the operating system.
buildnumber Identifies the build number of the operating system.
Windows, NetWare, OS/2: The version number is returns as [Link].
UNIX: The version returned does not follow a standard format and is specific to the
operating system.
[Link] (property)
Syntax [Link]
The value returned is not necessarily the platform under which BasicScript is running
but rather an indicator of the platform for which BasicScript was created. For example,
it is possible to run BasicScript for Windows under Windows NT Workstation. In this
case, [Link] will return 0.
Example 'This example determines the operating system for which this
'version was created and displays the appropriate message.
Sub Main()
Select Case [Link]
Case ebWin16
s = "Windows"
Case ebNetWare
s = "NetWare"
Case Else
s = "neither Windows nor NetWare"
End Select
MsgBox "You are currently running " & s
End Sub
See Also Cross-Platform Scripting (topic).
Platform(s) All.
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the path separator appropriate for the current platform.
Comments The returned string is any one of the following characters: / (slash), \ (back slash), :
(colon).
Example Sub Main()
MsgBox "The path separator for this platform is: " _
& [Link]$
End Sub
[Link]$ (property)
Syntax [Link]$
Description Returns a String containing the name of the CPU in the computer on which BasicScript
is running.
Comments You can retrieve the number of processors within the computer using the
[Link] property.
The following table describes the possible values returned by this property:
Platform Sample values returned from [Link]$
Windows "8086", "80186", "80286", "80386", "80486". On
Pentium computers, the value "80486" is returned.
Win32 On Intel platforms, one of the following is returned:
"80386", "80486", "Pentium". On MIPS platforms, the
string "Rx" is returned, such as "R4000". On Alpha
platforms, one of the following is returned: "321064",
"321066", "321164". On PowerPC platforms, one of the
following is returned: "601", "603", "604", "603+",
"604+", "620".
OS/2 "80386", "80486", "Pentium".
UNIX "i386", "i486"
NetWare "680x0", "80x86"
Macintosh On 68K platforms, one of the following is returned: "68000",
"68010", "68020", "68030", "68040". On PowerMac
platforms, the string "601" is returned.
An empty string is returned if BasicScript cannot determine the processor type.
Example '
'This example prints the CPU of the computer on which
'BasicScript is executing.
'
Sub Main()
MsgBox "Processor = " & [Link]$
End Sub
[Link] (property)
Syntax [Link]
Description Returns the number of CPUs installed on the computer on which BasicScript is running.
Comments You can determine the type of processor using the [Link]$ property.
This property return 1 if the CPU has only one processor or is otherwise incapable of
containing more than one processor.
Example '
'Print the number of processors in the computer.
'
Sub Main()
MsgBox "There are " & [Link] & _
" processor(s) in the computer."
End Sub
[Link]$ (property)
Syntax [Link]$
Platform(s) All.
Beep (statement)
Syntax Beep
PushButton OKButton
Parameter Description
Description A data type capable of representing the logical values True and False.
Comments Boolean variables are used to hold a binary value—either True or False. Variables can
be declared as Boolean using the Dim, Public, or Private statement.
Variants can hold Boolean values when assigned the results of comparisons or the
constants True or False.
Internally, a Boolean variable is a 2-byte value holding –1 (for True) or 0 (for False).
Any type of data can be assigned to Boolean variables. When assigning, non-0 values
are converted to True, and 0 values are converted to False. When converting strings to
Boolean, BasicScript recognizes localized versions of the strings "True" and "False",
converting these to the True and False respectively.
When appearing as a structure member, Boolean members require 2 bytes of storage.
When used within binary or random files, 2 bytes of storage are required.
When passed to external routines, Boolean values are sign-extended to the size of an
integer on that platform (either 16 or 32 bits) before pushing onto the stack.
There is no type-declaration character for Boolean variables.
Boolean variables that have not yet been assigned are given an initial value of False.
See Also Currency (data type);Date (data type); Integer (data type); Long (data type); Object
(data type); Single (data type); String (data type); Variant (data type); DefType
(statement); CBool (function).
Platform(s) All.
ButtonEnabled (function)
Syntax ButtonEnabled(name$ | id)
Description Returns True if the specified button within the current window is enabled; returns False
otherwise.
Comments The ButtonEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the push button.
id Integer specifying the ID of the push button.
When a button is enabled, it can be clicked using the SelectButton statement.
ButtonExists (function)
Syntax ButtonExists(name$ | id)
Description Returns True if the specified button exists within the current window; returns False
otherwise.
Comments The ButtonExists function takes the following parameters:
Parameter Description
name$ String containing the name of the push button.
id Integer specifying the ID of the push button.
Note: The ButtonExists function is used to determine whether a push button exists
in another application's dialog box. There is no equivalent function for use with
dynamic dialog boxes.
ByRef (keyword)
Syntax ...,ByRef parameter,...
Description Used within the Sub...End Sub, Function...End Function, or Declare statement to
specify that a given parameter can be modified by the called routine.
Comments Passing a parameter by reference means that the caller can modify that variable's value.
Unlike the ByVal keyword, the ByRef keyword cannot be used when passing a
parameter. The absence of the ByVal keyword is sufficient to force a parameter to be
passed by reference:
MySub ByVal i 'Pass i by value.
MySub ByRef i 'Illegal (will not compile).
MySub i 'Pass i by reference.
Example Sub Test(ByRef a As Variant)
a = 14
End Sub
Sub Main()
b = 12
Test b
MsgBox "The ByRef value is: " & b'Displays 14.
End Sub
See Also () (keyword); ByVal (keyword).
Platform(s) All.
ByVal (keyword)
Syntax ...ByVal parameter...
Foo ByVal i
MsgBox "The ByVal value is still: " & i
'Displays 11 (Foo did not change the value).
End Sub
Call (statement)
Syntax Call subroutine_name [(arguments)]
Description Transfers control to the given subroutine, optionally passing the specified arguments.
Comments Using this statement is equivalent to:
subroutine_name [arguments]
Use of the Call statement is optional. The Call statement can only be used to execute
subroutines; functions cannot be executed with this statement. The subroutine to which
control is transferred by the Call statement must be declared outside of the Main
procedure, as shown in the following example.
Examples 'This example demonstrates the use of the Call statement to pass
'control to another function.
Sub Example_Call(s$)
'This subroutine is declared externally to Main and displays
'the text passed in the parameter s$.
MsgBox "Call: " & s$
End Sub
Sub Main()
'This example assigns a string variable to display, then
'calls subroutine Example_Call, passing parameter S$ to be
'displayed in a message box within the subroutine.
s$ = "DAVE"
Example_Call s$
Call Example_Call("SUSAN")
End Sub
CancelButton (statement)
Syntax CancelButton x, y, width, height [,.Identifier]
Description Defines a Cancel button that appears within a dialog box template.
Comments This statement can only appear within a dialog box template (i.e., between the Begin
Dialog and End Dialog statements).
Selecting the Cancel button (or pressing Esc) dismisses the user dialog box, causing the
Dialog function to return 0. (Note: A dialog function can redefine this behavior.)
Pressing the Esc key or double-clicking the close box will have no effect if a dialog box
does not contain a CancelButton statement.
See Also CheckBox (statement); ComboBox (statement); Dialog (function); Dialog (statement);
DropListBox (statement); GroupBox (statement); ListBox (statement); OKButton
(statement); OptionButton (statement); OptionGroup (statement); Picture
(statement); PushButton (statement); Text (statement); TextBox (statement); Begin
Dialog (statement); PictureButton (statement); HelpButton (statement).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
CBool (function)
Syntax CBool(expression)
CCur (function)
Syntax CCur(expression)
See Also CBool (function); CDate, CVDate (functions); CDbl (function); CInt (function);
CLng (function); CSng (function); CStr (function); CVar (function); CVErr
(function); Currency (data type).
Platform(s) All.
See Also CCur (function); CBool (function); CDbl (function); CInt (function); CLng
(function); CSng (function); CStr (function); CVar (function); CVErr (function);
Date (data type).
Platform(s) All.
CDbl (function)
Syntax CDbl(expression)
See Also CCur (function); CBool (function); CDate, CVDate (functions); CInt (function);
CLng (function); CSng (function); CStr (function); CVar (function); CVErr
(function); Double (data type).
Platform(s) All.
ChDir (statement)
Syntax ChDir path
See Also ChDrive (statement); CurDir, CurDir$ (functions); Dir, Dir$ (functions); MkDir
(statement); RmDir (statement); DirList (statement).
Platform(s) All.
Platform Notes UNIX: UNIX platforms do not support drive letters.
Platform Notes NetWare: NetWare (and other operating systems) may not support the use of dots to
indicate the current and parent directories unless configured to do so.
NetWare does not support drive letters. Directory specifications under NetWare use the
following format:
volume:[dir\ [dir\]... ][Link]
The volume specification can be up to 14 characters.
Windows, Win32: BasicScript tracks and remembers the current directory for all drives
in the system for that process.
Macintosh: The Macintosh does not support drive letters.
The Macintosh uses the colon (":") as the path separator. A double colon ("::") specifies
the parent directory.
ChDrive (statement)
Syntax ChDrive drive
See Also ChDir (statement); CurDir, CurDir$ (functions); Dir, Dir$ (functions); MkDir
(statement); RmDir (statement); DiskDrives (statement).
CheckBox (statement)
Syntax CheckBox x, y, width, height, title$, .Identifier
CheckBoxEnabled (function)
Syntax CheckBoxEnabled(name$ | id)
Description Returns True if the specified check box within the current window is enabled; returns
False otherwise.
Comments The CheckBoxEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the check box.
id Integer specifying the ID of the check box.
When a check box is enabled, its state can be set using the SetCheckBox statement.
CheckBoxExists (function)
Syntax CheckBoxExists(name$ | id)
Description Returns True if the specified check box exists within the current window; returns False
otherwise.
Comments The CheckBoxExists function takes the following parameters:
Parameter Description
name$ String containing the name of the check box.
id Integer specifying the ID of the check box.
Example 'This code fragment checks to ensure that the Portrait check
'box is selectable before selecting it.
Sub Main()
If CheckBoxExists("Portrait") Then
If CheckBoxEnabled("Portrait") Then
SetCheckBox "Portrait",1
End If
End If
End Sub
Choose (function)
Syntax Choose(index,expression1,expression2,...,expression13)
String
Function Format Description of charcode Returns
Wide Value of an MBCS A 2-byte character string.
character between -32768
and 32767
ChrB SBCS Value between 0 and 255 A 1-byte character string.
ChrB$
MBCS Value between 0 and 255 A 1-byte character string.
Wide Value between 0 and 255 A 1-byte character string.
ChrW SBCS Value between 0 and 255 A 1-byte character string (same
as the Chr and Chr$ functions)
ChrW$
MBCS Value of an MBCS A 1-byte or 2-byte MBCS
character between -32768 character string depending on
and 32767 charcode.
Wide Value of a wide character A 2-byte character string.
between -32768 and 32767
The Chr$ function can be used within constant declarations, as in the following
example:
Const crlf = Chr$(13) + Chr$(10)
Some common uses of this function are:
Chr$(9) Tab
Chr$(26) End-of-file
Chr$(0) Null
CInt (function)
Syntax CInt(expression)
End Sub
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function);
CLng (function); CSng (function); CStr (function); CVar (function); CVErr
(function); Integer (data type).
Platform(s) All.
Clipboard$ (function)
Syntax Clipboard$[()]
Sub Main()
Clipboard$ "Hello out there!"
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
[Link]
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
End Sub
See Also Clipboard$ (statement); [Link] (method); [Link] (method).
Platform(s) Windows, Win32, Macintosh, OS/2.
Clipboard$ (statement)
Syntax Clipboard$ NewContent$
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax WhichFormat = [Link](format)
Description Returns True if data of the specified format is available in the Clipboard; returns False
otherwise.
Comments This method is used to determine whether the data in the Clipboard is of a particular
format. The format parameter is an Integer representing the format to be queried:
Format Value Description
ebCFText 1 Text
ebCFBitmap 2 Bitmap
ebCFMetafile 3 Metafile
ebCFDIB 8 Device-independent bitmap (DIB)
ebCFPalette 9 Color palette
ebCFUnicodeText 13 Unicode text
Example 'This example puts text on the Clipboard, checks whether there
'is text on the Clipboard, and if there is, displays it.
Sub Main()
Clipboard$ "Hello out there!"
If [Link](ebCFText) Then
MsgBox Clipboard$
Else
MsgBox "There is no text in the Clipboard."
End If
End Sub
See Also Clipboard$ (function); Clipboard$ (statement).
Platform(s) Windows, Win32, Macintosh, OS/2.
[Link] (method)
Syntax text$ = [Link]([format])
Description Returns the text contained in the Clipboard.
Comments The format parameter, if specified, must be ebCFText (1).
Example 'This example retrieves the text from the Clipboard and checks
'to make sure that it contains the word "dog."
Option Compare Text
Sub Main()
If [Link](1) Then
If Instr([Link](1),"dog",1) = 0 Then
MsgBox "The Clipboard doesn't contain the word ""dog."""
Else
MsgBox "The Clipboard contains the word ""dog""."
End If
Else
MsgBox "The Clipboard does not contain text."
End If
End Sub
[Link] (method)
Syntax [Link] data$ [,format]
CLng (function)
Syntax CLng(expression)
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function);
CInt (function); CSng (function); CStr (function); CVar (function); CVErr
(function); Long (data type).
Platform(s) All.
Close (statement)
Syntax Close [[#] filenumber [,[#] filenumber]...]
ComboBox (statement)
Syntax ComboBox x,y,width,height,ArrayVariable,.Identifier
Description This statement defines a combo box within a dialog box template.
Comments When the dialog box is invoked, the combo box will be filled with the elements from the
specified array variable.
This statement can only appear within a dialog box template (i.e., between the Begin
Dialog and End Dialog statements).
The ComboBox statement requires the following parameters:
Parameter Description
OKButton 76,8,40,14,.OK
Text 8,10,39,8,"&Weekdays:"
ComboBox 8,20,60,72,days$,.Days
End Dialog
Dim DaysDialog As DaysDialogTemplate
[Link] = "Tuesday"
r% = Dialog(DaysDialog)
MsgBox "You selected: " & [Link]
End Sub
ComboBoxEnabled (function)
Syntax ComboBoxEnabled(name$ | id)
Description Returns True if the specified combo box is enabled within the current window or dialog
box; returns False otherwise.
Comments The ComboBoxEnabled function takes the following parameters:
Parameter Description
SelectComboBoxItem "Filename:","[Link]"
End If
If ComboBoxEnabled(365) Then
SelectComboBoxItem 365,3'Select the third item.
End If
End Sub
See Also ComboBoxExists (function); GetComboBoxItem$ (function);
GetComboBoxItemCount (function); SelectComboBoxItem (statement).
Platform(s) Windows.
ComboBoxExists (function)
Syntax ComboBoxExists(name$ | id)
Description Returns True if the specified combo box exists within the current window or dialog
box; returns False otherwise.
Comments The ComboBoxExists function takes the following parameters:
Parameter Description
Example 'This code fragment checks to ensure that a combo box exists and
'is enabled before selecting the last item.
Sub Main()
If ComboBoxExists("Filename:") Then
If ComboBoxEnabled("Filename:") Then
NumItems = GetComboBoxItemCount("Filename:")
SelectComboBoxItem "Filename:",NumItems
End If
End If
End Sub
Description Returns the argument from the command line used to start the application.
Comments Command$ returns a string, whereas Command returns a String variant.
Example 'This example gets the command line and parameters, checks to
'see whether the string "/s" is present, and displays the result.
Sub Main()
cmd$ = Command$
If (InStr(cmd$,"/s")) <> 0 Then
MsgBox "Application was started with the /s switch."
Else
MsgBox "Application was started without the /s switch."
End If
If cmd$ <> "" Then
MsgBox "The command line startup options were: " & cmd$
Else
MsgBox "No command line startup options were used!"
End If
End Sub
Comments (topic)
Comments can be added to BasicScript code in the following manner:
All text between a single quotation mark and the end of the line is ignored:
MsgBox "Hello" 'Displays a message box.
The REM statement causes the compiler to ignore the entire line:
REM This is a comment.
BasicScript supports C-style multiline comment blocks /*...*/, as shown in the
following example:
MsgBox "Before comment"
/* This stuff is all commented out.
This line, too, will be ignored.
String Comparisons
If the two expressions are strings, then the operator performs a text comparison between
the two string expressions, returning True if expression1 is less than expression2. The
text comparison is case-sensitive if Option Compare is Binary; otherwise, the
comparison is case-insensitive.
When comparing letters with regard to case, lowercase characters in a string sort greater
than uppercase characters, so a comparison of "a" and "A" would indicate that "a" is
greater than "A".
Numeric Comparisons
When comparing two numeric expressions, the less precise expression is converted to
be the same type as the more precise expression.
Dates are compared as doubles. This may produce unexpected results as it is possible to
have two dates that, when viewed as text, display as the same date when, in fact, they are
different. This can be seen in the following example:
Sub Main()
Dim date1 As Date
Dim date2 As Date
date1 = Now
date2 = date1 + 0.000001 'Adds a fraction of a
'second.
MsgBox date2 = date1 'Prints False (the dates are
'different).
MsgBox date1 & "," & date2 'Prints two dates that are
'the same.
End Sub
Variant Comparisons
When comparing variants, the actual operation performed is determined at execution
time according to the following table:
And the other
If one variant is variant is Then
Numeric Numeric Compares the variants as numbers.
String String Compares the variants as text.
Numeric String The number is less than the string.
Null Any other data type Null.
Numeric Empty Compares the number with 0.
String Empty Compares the string with a zero-length
string.
See Also Operator Precedence (topic); Is (operator); Like (operator); Option Compare
(statement).
Platform(s) All.
Const (statement)
Syntax Const name [As type] = expression [,name [As type] = expression]...
Constants (topic)
Constants are variables that cannot change value during script execution. The following
constants are predefined by BasicScript.
Application State Constants (Used with AppSetState and AppGetState)
Constant Value Description
BasicScript Constants
Constant Value Description
Character Constants
Constant Value Description
Character Constants
Constant Value Description
ebCFText 1 Text.
ebCFBitmap 2 Bitmap.
ebCFMetafile 3 Metafile.
ebCFPalette 9 Palette.
Compiler Constants
Constant Value
Empty Empty
False False
Null Null
True True
ebSunday 1 Sunday.
ebMonday 2 Monday.
ebTuesday 3 Tuesday.
ebWednesday 4 Wednesday.
ebThursday 5 Thursday.
ebFriday 6 Friday.
ebSaturday 7 Saturday.
ebFirstFourDays 2 Start with first week with at least four days in the
new year.
File Constants (Used with Dir, Dir$, FileList, SetAttr, GetAttr, FileAttr)
Constant Value Description
ebDirectory 16 Subdirectory.
Math Constants
Constant Value Description
MsgBox Constants
Constant Value Description
ebSunOS 4 SunOS
ebHPUX 5 HP-UX
ebOSF1 15 OSF/1
ebVMS 16 VMS
ebLINUX 17 LINUX
You can define your own constants using the Const statement.
Preprocessor constants are defined using #Const.
Cos (function)
Syntax Cos(number)
CreateObject (function)
Syntax CreateObject(class)
Description Creates an OLE Automation object and returns a reference to that object.
Comments The class parameter specifies the application used to create the object and the type of
object being created. It uses the following syntax:
"[Link]",
where application is the application used to create the object and class is the type of the
object to create.
At runtime, CreateObject looks for the given application and runs that application if
found. Once the object is created, its properties and methods can be accessed using the
dot syntax (e.g., [Link] = value).
There may be a slight delay when an automation server is loaded (this depends on the
speed with which a server can be loaded from disk). This delay is reduced if an instance
of the automation server is already loaded.
Examples 'This first example instantiates Microsoft Excel. It then uses
'the resulting object to make Excel visible and then close Excel.
Sub Main()
Dim Excel As Object
On Error GoTo Trap1 'Set error trap.
Set Excel = CreateObject("[Link]")
[Link] = True 'Make Excel visible.
Sleep 5000 'Wait 5 seconds.
[Link] 'Close Excel.
Exit Sub 'Exit before error trap.
Trap1:
MsgBox "Can't create Excel object."'Display error message.
Exit Sub 'Reset error handler.
End Sub
'This second example uses CreateObject to instantiate a Visio
'object. It then uses the resulting object to create a new
'document.
Sub Main()
Dim Visio As Object
Dim doc As Object
Dim page As Object
Dim shape As Object
Set Visio = CreateObject("[Link]")
x = x + 1
MsgBox "Matching file " & x & " is: " & f$
f$ = Dir$
Wend
End Sub
End Sub
On Intel-based platforms, bytes are stored in memory with the most significant byte first
(known as little-endian format). Thus, the above example displays two dialog boxes, the
first one displaying the number 4 and the second displaying the number 0.
On UNIX and Macintosh platforms, bytes are stored in memory with the least
significant byte first (known as big-endian format). Thus, the above example displays
two dialog boxes, the first one displaying the number 0 and the second displaying the
number 4.
Scripts that rely on binary images of data must take the byte ordering of the current
platform into account.
When writing to text files, BasicScript uses the end-of-line appropriate to that platform.
You can retrieve the same end-of-line used by BasicScript using the [Link]$
property:
crlf = [Link]$
Print #1,"Line 1." & crlf & "Line 2."
Alignment
A major difference between platforms supported by BasicScript is the forced alignment
of data. BasicScript handles most alignment issues itself.
Integer 0
Double 0.0
Single 0.0
Long 0
Date December 31, 1899
Boolean False
Variant Empty
Object Nothing
Path Separators
Different file systems use different characters to separate parts of a pathname. For
example, under Windows, Win32, and OS/2, the backslash character is used:
s$ = "c:\sheets\[Link]"
Under UNIX, the forward slash is used:
s$ = "/sheets/[Link]"
When creating scripts that operate on any of these platforms, BasicScript recognizes the
forward slash universally as a valid path separator. Thus, the following file specification
is valid on all these platforms:
s$ = "/sheets/[Link]"
On the Macintosh, the slashes are valid filename characters. Instead, BasicScript
recognizes the colon as the valid file separator character:
s$ = "sheets:[Link]"
You can find out the path separator character for your platform using the
[Link]$ property:
s$ = "sheets" & [Link]$ & "[Link]"
Relative Paths
Specifying relative paths is different across platforms. Under UNIX, Windows, Win32,
and OS/2, a period (.) is used to specify the current directory, and two periods (..) are
used to indicate the parent directory, as shown below:
s$ = ".\[Link]" 'File in the current directory
s$ = "..\[Link]" 'File in the parent directory
On the Macintosh, double colons are used to specify the parent folder:
s$ = "::[Link]"'File in the parent folder
Drive Letters
Not all platforms support drive letters. For example, considering the following file
specification:
c:\[Link]
Under UNIX, this specifies a single file called c:\[Link]. Under Windows, this specifies
a file called [Link] in the root directory of drive c. On the Macintosh, this specifies a file
called \[Link] in a folder called c. You can use the [Link] method to
determine whether your platform supports drive letters:
Sub Main()
If [Link](1) Then s$ = "c:/" Else s$ = ""
s$ = s$ & "[Link]"
MsgBox "The platform-specific filename is: " & s$
End Sub
UNC Pathnames
Many platforms support UNC pathnames, including Windows and Win32. If you
choose to use these, make sure that UNC pathnames are supported on the platforms on
which your script will run.
CSng (function)
Syntax CSng(expression)
When used with variants, this function guarantees that the expression is converted to a
Single variant (VarType 4).
Example 'This example displays the value of a String converted to a
'Single.
Sub Main()
s$ = "100"
MsgBox "The single value is: " & CSng(s$)
End Sub
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function);
CInt (function); CLng (function); CStr (function); CVar (function); CVErr
(function); Single (data type).
Platform(s) All.
CStr (function)
Syntax CStr(expression)
Any numeric type A string containing the number without the leading space
for positive values
Date A string converted to a date using the short date format
Boolean A string containing either "True" or "False"
Null variant A runtime error
Empty variant A zero-length string
Example 'This example displays the value of a Double converted to a
'String.
Sub Main()
s# = 123.456
MsgBox "The string value is: " & CStr(s#)
End Sub
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function);
CInt (function); CLng (function); CSng (function); CVar (function); CVErr
(function); String (data type); Str, Str$ (functions).
Platform(s) All.
Description Returns the current directory on the specified drive. If no drive is specified or drive is
zero-length, then the current directory on the current drive is returned.
Comments CurDir$ returns a String, whereas CurDir returns a String variant.
BasicScript generates a runtime error if drive is invalid.
Example 'This example saves the current directory, changes to the next
'higher directory, and displays the change; then restores the
'original directory and displays the change. Note: The dot
'designators will not work with all platforms.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
save$ = CurDir$
ChDir ("..")
MsgBox "Old directory: " & save$ & crlf & "New directory: " _
& CurDir$
ChDir (save$)
MsgBox "Directory restored to: " & CurDir$
End Sub
See Also ChDir (statement); ChDrive (statement); Dir, Dir$ (functions); MkDir (statement);
RmDir (statement).
Platform(s) All.
Platform Notes UNIX: On UNIX platforms, the drive parameter is ignored. Since UNIX platforms do
not support drive letters, the current directory is always returned.
NetWare: Since NetWare does not support drive letters, the drive parameter specifies a
volume name (up to 14 characters). The returned value will have the following format:
volume:[dir[\dir]...]
Description A data type used to declare variables capable of holding fixed-point numbers with 15
digits to the left of the decimal point and 4 digits to the right.
Comments Currency variables are used to hold numbers within the following range:
Storage
Internally, currency values are 8-byte integers scaled by 10000. Thus, when appearing
within a structure, currency values require 8 bytes of storage. When used with binary or
random files, 8 bytes of storage are required.
See Also Date (data type); Double (data type); Integer (data type); Long (data type); Object
(data type); Single (data type); String (data type); Variant (data type); Boolean (data
type); DefType (statement); CCur (function).
Platform(s) All.
CVar (function)
Syntax CVar(expression)
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl (function);
CInt (function); CLng (function); CSng (function); CStr (function); CVErr
(function); Variant (data type).
Platform(s) All.
CVErr (function)
Syntax CVErr(expression)
Date Literals
Literal dates are specified using number signs, as shown below:
Dim d As Date
d = #January 1, 1990#
The interpretation of the date string (i.e., January 1, 1990 in the above example) occurs
at runtime, using the current country settings. This is a problem when interpreting dates
such as 1/2/1990. If the date format is M/D/Y, then this date is January 2, 1990. If the
date format is D/M/Y, then this date is February 1, 1990. To remove any ambiguity
when interpreting dates, use the universal date format:
date_variable = #YY/MM/DD HH:MM:SS#
The following example specifies the date June 3, 1965, using the universal date format:
Dim d As Date
d = #1965/6/3 10:23:45#
See Also Currency (data type); Double (data type); Integer (data type); Long (data type);
Object (data type); Single (data type); String (data type); Variant (data type); Boolean
(data type); DefType (statement); CDate, CVDate (functions).
Platform(s) All.
Note: In prior versions of BasicScript, the Date$ function returned the date using a
fixed date format. The date is now returned using the current short date format
(defined by the operating system), which may differ from the previous fixed format.
Example 'This example saves the current date to Cdate$, then changes
'the date and displays the result. It then changes the date
'back to the saved date and displays the result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
TheDate$ = Date$()
Date$ = "01/01/95"
MsgBox "Saved date is: " & TheDate$ & crlf _
& "Changed date is: " & Date$()
Date$ = TheDate$
MsgBox "Restored date to: " & TheDate$
End Sub
See Also CDate, CVDate (functions); Time, Time$ (functions); Date, Date$ (statements); Now
(function); Format, Format$ (functions); DateSerial (function); DateValue
(function).
Platform(s) All.
where MM is a two-digit month between 1 and 31, DD is a two-digit day between 1 and
31, and YYYY is a four-digit year between 1/1/100 and 12/31/9999.
The Date statement converts any expression to a date, including string and numeric
values. Unlike the Date$ statement, Date recognizes many different date formats,
including abbreviated and full month names and a variety of ordering options. If
newdate contains a time component, it is accepted, but the time is not changed. An error
occurs if newdate cannot be interpreted as a valid date.
Example 'This example saves the current date to Cdate$, then changes
'the date and displays the result. It then changes the date
'back to the saved date and displays the result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
TheDate$ = Date$()
Date$ = "01/01/95"
MsgBox "Saved date is: " & TheDate$ & crlf _
& "Changed date is: " & Date$()
Date$ = TheDate$
MsgBox "Restored date to: " & TheDate$
End Sub
See Also Date, Date$ (functions); Time, Time$ (statements).
Platform(s) All.
Platform Notes On some platforms, you may not have permission to change the date, causing runtime
error 70 to be generated. This can occur on all UNIX platforms, Win32, and OS/2.
The range of valid dates varies from platform to platform. The following table describes
the minimum and maximum dates accepted by various platforms:
Platform Minimum Date Maximum Date
Macintosh January 1, 1904 February 6, 2040
Windows January 1, 1980 December 31, 2099
Windows 95 January 1, 1980 December 31, 2099
OS/2 January 1, 1980 December 31, 2079
NetWare January 1, 1980 December 31, 2099
DateAdd (function)
Syntax DateAdd(interval, number, date)
Description Returns a Date variant representing the sum of date and a specified number (number) of
time intervals (interval).
Comments This function adds a specified number (number) of time intervals (interval) to the
specified date (date). The following table describes the named parameters to the
DateAdd function:
Named Parameter Description
interval String expression indicating the time interval used in the
addition.
number Integer indicating the number of time intervals you wish to
add. Positive values result in dates in the future; negative
values result in dates in the past.
date Any expression convertible to a Date string expression. An
example of a valid date/time string would be "January 1,
1993".
The interval parameter specifies what unit of time is to be added to the given date. It can
be any of the following:
Time Interval
"y" Day of the year
"yyyy" Year
"d" Day
"m" Month
"q" Quarter
"ww" Week
"h" Hour
"n" Minute
"s" Second
"w" Weekday
To add days to a date, you may use either day, day of the year, or weekday, as they are
all equivalent ("d", "y", "w").
The DateAdd function will never return an invalid date/time expression. The following
example adds two months to December 31, 1992:
s# = DateAdd("m", 2, "December 31, 1992")
In this example, s is returned as the double-precision number equal to "February 28,
1993", not "February 31, 1993".
BasicScript generates a runtime error if you try subtracting a time interval that is larger
than the time value of the date.
Example 'This example gets today's date using the Date$ function; adds
'three years, two months, one week, and two days to it; and
DateDiff (function)
Syntax DateDiff(interval, date1, date2 [, [firstdayofweek] [,firstweekofyear]])
Description Returns a Date variant representing the number of given time intervals between date1
and date2.
Comments The following describes the named parameters:
Named Parameter Description
interval String expression indicating the specific time interval you
wish to find the difference between. An error is generated if
interval is Null.
date1 Any expression convertible to a Date. An example of a valid
date/time string would be "January 1, 1994".
date2 Any expression convertible to a Date. An example of a valid
date/time string would be "January 1, 1994".
firstdayofweek Indicates the first day of the week. If omitted, then sunday is
assumed (i.e., the constant ebSunday described below).
firstweekofyear Indicates the first week of the year. If omitted, then the first
week of the year is considered to be that containing January 1
(i.e., the constant ebFirstJan1 as described bellow).
The following lists the valid time interval strings and the meanings of each. The
Format$ function uses the same expressions.
Time Interval
"y" Day of the year
"yyyy" Year
"d" Day
"m" Month
"q" Quarter
"ww" Week
"h" Hour
"n" Minute
"s" Second
"w" Weekday
To find the number of days between two dates, you may use either day or day of the
year, as they are both equivalent ("d", "y").
The time interval weekday ("w") will return the number of weekdays occurring between
date1 and date2, counting the first occurrence but not the last. However, if the time
interval is week ("ww"), the function will return the number of calendar weeks between
date1 and date2, counting the number of Sundays. If date1 falls on a Sunday, then that
day is counted, but if date2 falls on a Sunday, it is not counted.
The firstdayofweek parameter, if specified, can be any of the following constants:
Constant Value Description
DatePart (function)
Syntax DatePart(interval, date [, [firstdayofweek] [,firstweekofyear]])
See Also Day (function); Minute (function); Second (function); Month (function); Year
(function); Hour (function); Weekday (function); Format, Format$ (functions).
Platform(s) All.
DateSerial (function)
Syntax DateSerial(year, month, day)
MsgBox "The DateSerial value for August 22, 1993, is: " _
& tdate#
End Sub
See Also DateValue (function); TimeSerial (function); TimeValue (function); CDate, CVDate
(functions).
Platform(s) All.
DateValue (function)
Syntax DateValue(date)
Description Returns a Date variant representing the date contained in the specified string argument.
Example 'This example returns the day of the month for today's date.
Sub Main()
tdate$ = Date$
tday = DateValue(tdate$)
MsgBox tdate & " date value is: " & tday$
End Sub
See Also TimeSerial (function); TimeValue (function); DateSerial (function).
Platform(s) All.
Platform Notes Windows: Under Windows, date specifications vary depending on the international
settings contained in the "intl" section of the [Link] file. The date items must follow the
ordering determined by the current date format settings in use by Windows..
Day (function)
Syntax Day(date)
See Also Minute (function); Second (function); Month (function); Year (function); Hour
(function); Weekday (function); DatePart (function).
Platform(s) All.
DDB (function)
Syntax DDB(cost, salvage, life, period [,factor])
Description Calculates the depreciation of an asset for a specified period of time using the
double-declining balance method.
Comments The double-declining balance method calculates the depreciation of an asset at an
accelerated rate. The depreciation is at its highest in the first period and becomes
progressively lower in each additional period. DDB uses the following formula to
calculate the depreciation:
DDB =((Cost-Total_depreciation_from_all_other_periods) * 2)/Life
The DDB function uses the following named parameters:
Named Parameter Description
Next yy
MsgBox s$
End Sub
DDEExecute (statement)
Syntax DDEExecute channel, command$
DDEInitiate (function)
Syntax DDEInitiate(application$, topic$)
Description Initializes a DDE link to another application and returns a unique number subsequently
used to refer to the open DDE channel.
Comments The DDEInitiate statement takes the following parameters:
Parameter Description
application$ String containing the name of the application (the server) with
which a DDE conversation will be established.
topic$ String containing the name of the topic for the conversation.
The possible values for this parameter are described in the
documentation for the server application.
This function returns 0 if BasicScript cannot establish the link. This will occur under
any of the following circumstances:
• The specified application is not running.
• The topic was invalid for that application.
• Memory or system resources are insufficient to establish the DDE link.
Example 'This example selects a range of cells in an Excel spreadsheet.
Sub Main()
q$ = Chr(34)
ch% = DDEInitiate("Excel","c:\sheets\[Link]")
cmd$ = "Select(" & q$ & "R1C1:R8C1" & q$ & ")"
DDEExecute ch%,cmd$
DDETerminate ch%
End Sub
See Also DDEExecute (statement); DDEPoke (statement); DDERequest, DDERequest$
(functions); DDESend (function); DDETerminate (statement); DDETerminateAll
(statement); DDETimeout (statement).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows: Under Windows, the DDEML library is required for DDE support. This
library is loaded when the first DDEInitiate statement is encountered and remains
loaded until the BasicScript system is terminated. Thus, the DDEML library is required
only if DDE statements are used within a script.
DDEPoke (statement)
Syntax DDEPoke channel, DataItem, value
Description Sets the value of a data item in the receiving application associated with an open DDE
link.
Comments The DDEPoke statement takes the following parameters:
Parameter Description
channel Integer containing the DDE channel number returned from
DDEInitiate. An error will result if channel is invalid.
DataItem Data item to be set. This parameter can be any expression
convertible to a String. The format depends on the server.
value The new value for the data item. This parameter can be any
expression convertible to a String. The format depends on the
server. A runtime error is generated if value is Null.
Example 'This example pokes a value into an Excel spreadsheet.
Sub Main()
ch% = DDEInitiate("Excel","c:\sheets\[Link]")
DDEPoke ch%,"R1C1","980"
DDETerminate ch%
End Sub
See Also DDEExecute (statement); DDEInitiate (function); DDERequest, DDERequest$
(functions); DDESend (function); DDETerminate (statement); DDETerminateAll
(statement); DDETimeout (statement).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows: Under Windows, the DDEML library is required for DDE support. This
library is loaded when the first DDEInitiate statement is encountered and remains
loaded until the BasicScript system is terminated. Thus, the DDEML library is required
only if DDE statements are used within a script.
Description Returns the value of the given data item in the receiving application associated with the
open DDE channel.
Comments DDERequest$ returns a String, whereas DDERequest returns a String variant.
DDESend (statement)
Syntax DDESend application$, topic$, DataItem, value
Description Initiates a DDE conversation with the server as specified by application$ and topic$ and
sends that server a new value for the specified item.
Comments The DDESend statement takes the following parameters:
Parameter Description
application$ String containing the name of the application (the server) with
which a DDE conversation will be established.
topic$ String containing the name of the topic for the conversation.
The possible values for this parameter are described in the
documentation for the server application.
DataItem Data item to be set. This parameter can be any expression
convertible to a String. The format depends on the server.
Parameter Description
value New value for the data item. This parameter can be any
expression convertible to a String. The format depends on the
server. A runtime error is generated if value is Null.
The DDESend statement performs the equivalent of the following statements:
ch% = DDEInitiate(application$, topic$)
DDEPoke ch%, item, data
DDETerminate ch%
Example 'This code fragment sets the content of the first cell in an
'Excel spreadsheet.
Sub Main()
On Error Goto Trap1
DDESend "Excel","c:\excel\[Link]","R1C1","Hello, world."
On Error Goto 0
'Add more lines here.
Trap1:
MsgBox "Error sending data to Excel."
Exit Sub'Reset error handler.
End Sub
DDETerminate (statement)
Syntax DDETerminate channel
q$ = Chr(34)
ch% = DDEInitiate("Excel","c:\sheets\[Link]")
cmd$ = "Select(" & q$ & "R1C1:R8C1" & q$ & ")"
DDEExecute ch%,cmd$
DDETerminate ch%
End Sub
See Also DDEExecute (statement); DDEInitiate (function); DDEPoke (statement);
DDERequest, DDERequest$ (functions); DDESend (function); DDETerminateAll
(statement); DDETimeout (statement).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows: Under Windows, the DDEML library is required for DDE support. This
library is loaded when the first DDEInitiate statement is encountered and remains
loaded until the BasicScript system is terminated. Thus, the DDEML library is required
only if DDE statements are used within a script.
DDETerminateAll (statement)
Syntax DDETerminateAll
DDETimeout (statement)
Syntax DDETimeout milliseconds
Description Sets the number of milliseconds that must elapse before any DDE command times out.
Comments The milliseconds parameter is a Long and must be within the following range:
0 <= milliseconds <= 2,147,483,647
The default is 10,000 (10 seconds).
Example Sub Main()
q$ = Chr(34)
ch% = DDEInitiate("Excel","c:\sheets\[Link]")
DDETimeout(20000)
cmd$ = "Select(" & q$ & "R1C1:R8C1" & q$ & ")"
DDEExecute ch%,cmd$
DDETerminate ch%
End Sub
Declare (statement)
Syntax Declare {Sub | Function} name[TypeChar] [CDecl | Pascal | System |
StdCall] [Lib "LibName$" [Alias "AliasName$"]] [([ParameterList])]
[As type]
Where ParameterList is a comma-separated list of the following (up to 30 parameters
are allowed):
[Optional] [ByVal | ByRef] ParameterName[()] [As ParameterType]
Description Creates a prototype for either an external routine or a BasicScript routine that occurs
later in the source module or in another source module.
Comments Declare statements must appear outside of any Sub or Function declaration.
Declare statements are only valid during the life of the script in which they appear.
Parameter Description
AliasName$ Alias name that must be given to provide the name of the
routine if the name parameter is not the routine's real name. For
example, the following two statements declare the same routine:
Declare Function GetCurrentTime Lib "user"
() As Integer
Declare Function GetTime Lib "user" Alias
"GetCurrentTime" _
As Integer
Use an alias when the name of an external routine conflicts with
the name of a BasicScript internal routine or when the external
routine name contains invalid characters.
The AliasName$ parameter must appear within quotes.
type Indicates the return type for functions.
For external functions, the valid return types are: Integer,
Long, String, Single, Double, Date, Boolean, and data objects.
Note: Currency, Variant, fixed-length strings, arrays,
user-defined types, and OLE Automation objects cannot be
returned by external functions.
Optional Keyword indicating that the parameter is optional. All optional
parameters must be of type Variant. Furthermore, all
parameters that follow the first optional parameter must also be
optional.
If this keyword is omitted, then the parameter being defined is
required when calling this subroutine or function.
ByVal Optional keyword indicating that the caller will pass the
parameter by value. Parameters passed by value cannot be
changed by the called routine.
ByRef Optional keyword indicating that the caller will pass the
parameter by reference. Parameters passed by reference can be
changed by the called routine. If neither ByVal or ByRef are
specified, then ByRef is assumed.
Parameter Description
ParameterName Name of the parameter, which must follow BasicScript naming
conventions:
1. Must start with a letter.
2. May contain letters, digits, and the underscore character
(_). Punctuation and type-declaration characters are not
allowed. The exclamation point (!) can appear within the
name as long as it is not the last character, in which case it
is interpreted as a type-declaration character.
3. Must not exceed 80 characters in length.
Additionally, ParameterName can end with an optional
type-declaration character specifying the type of that parameter
(i.e., any of the following characters: %, &, !, #, @).
() Indicates that the parameter is an array.
ParameterType Specifies the type of the parameter (e.g., Integer, String,
Variant, and so on). The As ParameterType clause should only
be included if ParameterName does not contain a
type-declaraction character.
In addition to the default BasicScript data types,
ParameterType can specify any user-defined structure, data
object, or OLE Automation object. If the data type of the
parameter is not known in advance, then the Any keyword can
be used. This forces the BasicScript compiler to relax type
checking, allowing any data type to be passed in place of the
given argument.
Declare Sub Convert Lib "mylib" (a As Any)
The Any data type can only be used when passing parameters to
external routines.
Passing Parameters
By default, BasicScript passes arguments by reference. Many external routines require a
value rather than a reference to a value. The ByVal keyword does this. For example, this
C routine
void MessageBeep(int);
would be declared as follows:
Declare Sub MessageBeep Lib "user" (ByVal n As Integer)
As an example of passing parameters by reference, consider the following C routine
which requires a pointer to an integer as the third parameter:
int SystemParametersInfo(int,int,int *,int);
This routine would be declared as follows (notice the ByRef keyword in the third
parameter):
Declare Function SystemParametersInfo Lib "user" (ByVal _
action As Integer, ByVal uParam As Integer,ByRef pInfo _
As Integer, ByVal updateINI As Integer) As Integer
Strings can be passed by reference or by value. When they are passed by reference, a
pointer to a pointer to a null-terminated string is passed. When they are passed by value,
BasicScript passes a pointer to a null-terminated string (i.e., a C string).
When passing a string by reference, the external routine can change the pointer or
modify the contents of the existing. If an external routine modifies a passed string
variable (regardless of whether the string was passed by reference or by value), then
there must be sufficient space within the string to hold the returned characters. This can
be accomplished using the Space function, as shown in the following example which
calls a Windows 16-bit DLL:
Declare Sub GetWindowsDirectory Lib "kernel" (ByVal _
dirname$, ByVal length%)
Sub Main()
Dim s As String
s = Space(128)
GetWindowsDirectory s,128
End Sub
Another alternative to ensure that a string has sufficient space is to declare the string
with a fixed length:
Declare Sub GetWindowsDirectory Lib "kernel" (ByVal _
dirname$, ByVal length%)
Sub Main
Dim s As String * 128
GetWindowsDirectory s,len(s)
End Sub
The following table describes BasicScript’s calling conventions and how these translate
to those supported by C.
BasicScript C Calling
Calling Convention Convention Characteristics
StdCall _stdcall Arguments are pushed right to left.
The called function performs stack
cleanup.
Pascal pascal Arguments are pushed left to right.
The called function performs stack
cleanup
System _System Arguments are pushed right to left.
The caller performs stack cleanup.
The number of arguments is specified in
the ax 1 register.
CDecl cdec1 Arguments are pushed right to left.
The caller performs stack cleanup.
The following table shows which calling conventions are supported on which platform,
and indicates what the default calling convention is when no explicit calling convention
is specified in the Declare statement.
Platform Supported Calling Conventions Default Calling Convention
Windows Pascal, CDecl Pascal
Win32/Intel Pascal, CDecl, StdCall StdCall
Win32/PPC CDecl CDecl
Macintosh On the 68K, the Macintosh supports On the 68K, the default
only the CDecl calling convention. calling convention is CDecl.
The PowerMac supports a single On the 68K, a runtime error
calling convention that evaluates occurs if any explicit calling
parameters left to right. No special convention keyword is
calling convention keywords are specified.
required.
OS/2 System, Pascal, CDecl System
NetWare CDecl, Pascal CDecl
UNIX CDecl CDecl
Note: Use caution when using the ByVal keyword in this way. The external routine
Foo expects to receive a pointer to an Integer—a 32-bit value; using ByVal causes
BasicScript to pass the Integer by value—a 16-bit value. Passing data of the wrong
size to any external routine will have unpredictable results.
See Also Call (statement); Sub...End Sub (statement); Function...End Function (statement).
Platform(s) All platforms support Declare for forward referencing.
The following platforms currently support the use of Declare for referencing external
routines: Windows, Win32/Intel, Win32/PPC, Macintosh, OS/2, NetWare, and some
UNIX platforms. See below for details.
Platform Notes Windows: Under Windows, external routines are contained in DLLs. The libraries
containing the routines are loaded when the routine is called for the first time (i.e., not
when the script is loaded). This allows a script to reference external DLLs that
potentially do not exist.
All the Windows API routines are contained in DLLs, such as "user", "kernel", and
"gdi". The file extension ".exe" is implied if another extension is not given.
If the LibName$ parameter does not contain an explicit path to the DLL, the following
search will be performed for the DLL (in this order):
Note: You cannot execute routines contained in 16-bit Windows DLLs from the
32-bit version of BasicScript.
All the Win32 API routines are contained in DLLs, such as "user32", "kernel32", and
"gdi32". The file extension ".exe" is implied if another extension is not given.
The Pascal and StdCall calling conventions are identical on Win32 platforms.
Furthermore, on this platform, the arguments are passed using C ordering regardless of
the calling convention—right to left on the stack.
If the LibName$ parameter does not contain an explicit path to the DLL, the following
search will be performed for the DLL (in this order):
1. The directory containing BasicScript
2. The current directory
3. The Windows system directory
4. The Windows directory
5. All directories listed in the path environment variable
If the first character of AliasName$ is #, then the remainder of the characters specify the
ordinal number of the routine to be called. For example, the following two statements
are equivalent (under Win32, GetCurrentTime is defined as GetTickCount, ordinal
300, in [Link]):
Declare Function GetTime Lib "[Link]" Alias
"GetTickCount" () As Long
Declare Function GetTime Lib "[Link]" Alias "#300" () As
Long
Under Win32, name and AliasName$ are case-sensitive.
Under Win32, all string passed by value are converted to MBCS strings. Similarly, any
string returned from an external routine is assumes to be a null-terminated MBCS
string.
BasicScript does not perform an increment on OLE automation objects before passing
them to external routines. When returned from an external function, BasicScript
assumes that the properties and methods of the OLE automation object are UNICODE
and that the object uses the default system locale.
Platform Notes NetWare: Under NetWare, external routines are contained within NLMs. If no file
extension is specified in LibName$, then ".nlm" is assumed.
Since the standard C library is implemented as an NLM under NetWare, it is possible to
call many C routines directly from BasicScript. For example, the following code calls
Printf with a String and an Integer:
Declare Sub Printf Lib "[Link]" (ByVal F$,ByVal s$,ByVal i%)
Sub Main()
Printf "Hello, ","world.",10
End Sub
If LibName$ does not contain an explicit path, then NetWare looks in the system
directory. The NLM specified by LibName$ is loaded when the first call to an external
in that module is accessed, thus allowing execution of scripts containing calls to NLMs
that do not exist. (If the NLM is already loaded, then no work is done.)
Under NetWare, the name and AliasName$ parameters are case-sensitive.
Platform Notes Macintosh: On the Macintosh, external routines are contained in code fragments as
specified by the LibName$ parameter. BasicScript uses the following rules for locating
your code fragment:
1. If LibName$ contains an explicit path, that code fragment will be loaded.
2. If no path is specified in LibName$, then BasicScript will look in the folder
containing BasicScript, then the System folder.
3. If both of the above fail, then BasicScript will search for a code fragment whose
CFRG resource name is the same as LibName$. The search is performed in the
folder containing BasicScript, then the System folder.
The name is compared case-sensitive.
The name, AliasName$, and LibName$ parameters are case-sensitive.
For more information on the calling conventions for code fragments, Apple publishes
the following books:
1. Inside Macintosh: PowerPC System Software
2. Building CFM-68K Runtime Programs for Macintosh Computers
Platform Notes OS/2: If the LibName$ parameter does not contain an explicit path to the DLL, the
following search will be performed for the DLL (in this order):
1. The current directory.
2. All directories listed in the path environment variable.
The Declare statement under OS/2 supports calling both 16-bit and 32-bit routines. The
following table shows how this relates to the supported calling conventions:
Calling Convention Supports 16-Bit Calls Supports 32-Bit Calls
System No Yes
Pascal Yes Yes
CDec1 Yes No
Note: BasicScript does not support passing of Single and Double values to external
16-bit subroutines or functions. These data types are also not supported as return
values from external 16-bit functions.
If the first character of AliasName$ is #, then the remainder of the characters specify the
ordinal number of the routine to be called. The following example shows an ordinal
used to access the DosQueryCurrentDisk function contained in the [Link]
module:
Declare Function System DosQueryCurrentDisk Lib "[Link]"
Alias "#275" _
(ByRef Drive As Long,ByRef Map As Long) As Integer
Under OS/2, the name and AliasName$ parameters are case-sensitive.
Note: All external routines contained in the [Link] module require the use of an
ordinal.
Platform Notes UNIX: The Declare statement can be used to reference routines contained in shared
libraries on the following UNIX platforms: HP-UX, Solaris.
If LibPath$ does not contain an explicit path, then a search is made for the shared
library in each path in the colon separated list as specified by the following environment
variable:
Platform Environment Variable
HP-UX SHLIB_PATH
Solaris LD_LIBRARY_PATH
The following example shows how to call the printf function on the HP-UX platform:
Declare Sub PrintString Lib "/lib/[Link]" Alias "_printf" _
(ByVal FormatString As String,ByVal s As String)
Sub Main
PrintString "Hello, ","world."
End Sub
A special note when passing Single values to external routines on HP-UX: When
passing Single values to external routines compiled in ANSI mode, the parameter in the
Declare statement should be specified as Double. External routines compiled in K&R
mode should have float parameters defined as Single as normal. This is due to calling
convention differences between these two standards: In ANSI mode, floats are
promoted to double prior to passing.
DefType (statement)
Syntax DefInt letterrange
DefLng letterrange
DefStr letterrange
DefSng letterrange
DefDbl letterrange
DefCur letterrange
DefObj letterrange
DefVar letterrange
DefBool letterrange
DefDate letterrange
Description Establishes the default type assigned to undeclared or untyped variables.
Comments The DefType statement controls automatic type declaration of variables. Normally, if a
variable is encountered that hasn't yet been declared with the Dim, Public, or Private
statement or does not appear with an explicit type-declaration character, then that
variable is declared implicitly as a variant (DefVar A–Z). This can be changed using the
DefType statement to specify starting letter ranges for Type other than integer. The
letterrange parameter is used to specify starting letters. Thus, any variable that begins
with a specified character will be declared using the specified Type.
The syntax for letterrange is:
letter [-letter] [,letter [-letter]]...
DefType variable types are superseded by an explicit type declarationusing either a
type-declaration character or the Dim, Public, or Private statement.
The DefType statement only affects how BasicScript compiles scripts and has no effect
at runtime.
The DefType statement can only appear outside all Sub and Function declarations.
The following table describes the data types referenced by the different variations of the
DefType statement:
Statement Data Type
DefInt Integer
DefLng Long
DefStr String
DefSng Single
DefDbl Double
DefCur Currency
DefObj Object
DefVar Variant
DefBool Boolean
DefDate Date
Example DefStr a-l
DefLng m-r
DefSng s-u
DefDbl v-w
DefInt x-z
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a = 100.52
m = 100.52
s = 100.52
v = 100.52
x = 100.52
message = "The values are:"
message = message & "(String) a: " & a
message = message & "(Long) m: " & m
message = message & "(Single) s: " & s
message = message & "(Double) v: " & v
message = message & "(Integer) x: " & x
MsgBox message
End Sub
See Also Currency (data type); Date (data type); Double (data type); Long (data type); Object
(data type); Single (data type); String (data type); Variant (data type); Boolean (data
type); Integer (data type).
Platform(s) All.
DeleteSetting (statement)
Syntax DeleteSetting appname [,section [,key]]
Comments You can control the behavior of DeleteSetting by omitting parameters. If you specify
all three parameters, then DeleteSetting deletes your specified setting. If you omit key,
then DeleteSetting deletes all of the keys from section. If both section and key are
omitted, then DeleteSetting removes that application’s entry from the system registry.
The following table describes the named parameters to the DeleteSetting statement:
Named Parameter Description
appname String expression indicating the name of the application
whose setting will be deleted.
section String expression indicating the name of the section whose
setting will be deleted.
key String expression indicating the name of the setting to be
deleted from the registry.
Example 'The following example adds two entries to the Windows registry
'if run under Win32 or to [Link] on other platforms,
'using the SaveSetting statement. It then uses DeleteSetting
'first to remove the Startup section, then to remove
'the NewApp key altogether.
Sub Main()
SaveSetting appname := "NewApp", section := "Startup", _
key := "Height", setting := 200
SaveSetting appname := "NewApp", section := "Startup", _
key := "Width", setting := 320
Windows, OS/2: Settings are stored in INI files. The name of the INI file is specified by
appname. If appname is omitted, then this command operates on the [Link] file. For
example, to delete the sLanguage setting from the intl section of the [Link] file, you
could use the following statement:
s$ = DeleteSetting(,"intl","sLanguage")
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax [Link] ControlPanelItemName$
[Link] (method)
Syntax [Link] filename$, isTile
Example 'This example reads a list of .BMP files from the Windows
'directory and allows the user to select any of these as
'wallpaper.
Sub Main()
Dim list$()
' Create the prefix for the bitmap filenames
d$ = [Link]$
If Right(d$,1) <> "\" Then d$ = d$ & "\"
f$ = d$ & "*.BMP"
FileList list$,f$'Get list of bitmaps from Windows directory
'Were there any bitmaps?
If ArrayDims(list$) = 0 Then
MsgBox "There aren't any bitmaps in the Windows directory"
Exit Sub
End If
'Add "(none)".
ReDim Preserve list$ (UBound(list$) + 1)
list$(UBound(list$)) = "(none)"
SelectAgain:'Allow user to select item
[Link] (method)
Syntax [Link] [spec]
Description Takes a snapshot of a particular section of the screen and saves it to the Clipboard.
Comments The spec parameter is an Integer specifying the screen area to be saved. It can be any of
the following:
0 Entire screen
Before the snapshot is taken, each application is updated. This ensures that any
application that is in the middle of drawing will have a chance to finish before the
snapshot is taken.
There is a slight delay if the specified window is large.
Example 'This example takes a snapshot of Program Manager and pastes
'the resulting bitmap into Windows Paintbrush.
Sub Main()
AppActivate "Program Manager"'Activate Program Manager.
Platform(s) Windows.
Platform Notes Windows: Under Windows, pictures are placed into the Clipboard in bitmap format.
[Link] (method)
Syntax [Link]
Dialog (function)
Syntax Dialog(DialogVariable [,[DefaultButton] [,Timeout]])
Description Displays the dialog box associated with DialogVariable, returning an Integer indicating
which button was clicked.
Comments The Dialog function returns any of the following values:
–1 The OK button was clicked.
PushButton CancelButton
OKButton PictureButton
Example 'This example displays an abort/retry/ignore disk error dialog
'box.
Sub Main()
Begin Dialog DiskErrorTemplate 16,32,152,48,"Disk Error"
Text 8,8,100,8,"The disk drive door is open."
PushButton 8,24,40,14,"Abort",.Abort
PushButton 56,24,40,14,"Retry",.Retry
PushButton 104,24,40,14,"Ignore",.Ignore
End Dialog
Dim DiskError As DiskErrorTemplate
r% = Dialog(DiskError,3,0)
MsgBox "You selected button: " & r%
End Sub
See Also CancelButton (statement); CheckBox (statement); ComboBox (statement); Dialog
(statement); DropListBox (statement); GroupBox (statement); ListBox (statement);
OKButton (statement); OptionButton (statement); OptionGroup (statement); Picture
(statement); PushButton (statement); Text (statement); TextBox (statement); Begin
Dialog (statement); PictureButton (statement); HelpButton (statement).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
Dialog (statement)
Syntax Dialog DialogVariable [,[DefaultButton] [,Timeout]]
Description Same as the Dialog function, except that the Dialog statement does not return a value.
(See Dialog [function].)
Example 'This example displays an abort/retry/ignore disk error dialog
'box.
Sub Main()
Begin Dialog DiskErrorTemplate 16,32,152,48,"Disk Error"
Text 8,8,100,8,"The disk drive door is open."
PushButton 8,24,40,14,"Abort",.Abort
PushButton 56,24,40,14,"Retry",.Retry
PushButton 104,24,40,14,"Ignore",.Ignore
End Dialog
Dim DiskError As DiskErrorTemplate
Dialog DiskError,3,0
End Sub
Dialogs (topic)
Dialogs are supported on the following platforms: Windows, Win32, OS/2, UNIX, and
Macintosh. The following table describes the default font use by BasicScript to display
all runtime dialogs:
Default Font in Dialog Boxes
Platform Default Font
When Help is enabled within a dialog, the help key is enabled as described in the
following table:
Help Key in BasicScript Dialogs
Platform Help Key
Windows F1
Win32 F1
OS/2 F1
Macintosh Command+?
UNIX The default help key is F1, unless if has been redefined in
your X resource files.
Dim (statement)
Syntax Dim name [(<subscripts>)] [As [New] type] [,name [(<subscripts>)] [As
[New] type]]...
Description Declares a list of local variables and their corresponding types and sizes.
Comments If a type-declaration character is used when specifying name (such as %, @, &, $, or !),
the optional [As type] expression is not allowed. For example, the following are
allowed:
Dim Temperature As Integer
Dim Temperature%
The subscripts parameter allows the declaration of dynamic and fixed arrays. The
subscripts parameter uses the following syntax:
[lower to] upper [,[lower to] upper]...
The lower and upper parameters are integers specifying the lower and upper bounds of
the array. If lower is not specified, then the lower bound as specified by Option Base is
used (or 1 if no Option Base statement has been encountered). BasicScript supports a
maximum of 60 array dimensions.
The total size of an array (not counting space for strings) is limited to 64K.
Dynamic arrays are declared by not specifying any bounds:
Dim a()
The type parameter specifies the type of the data item being declared. It can be any of
the following data types: String, Integer, Long, Single, Double, Currency, Object,
data object, built-in data type, or any user-defined data type. When specifying explicit
object types, you can use the following syntax for type:
[Link]
Where module is the name of the module in which the object is defined and class is the
type of object. For example, to specify the OLE automation variable for Excel’s
Application object, you could use the following code:
Dim a As [Link]
Note: Explicit object types can only be specified for data objects and early bound
OLE automation objects—i.e., objects whose type libraries have been registered with
BasicScript.
Fixed-Length Strings
Fixed-length strings are declared by adding a length to the String type-declaration
character:
Dim name As String * length
where length is a literal number specifying the string's length.
Initial Values
All declared variables are given initial values, as described in the following table:
Data Type Initial Value
Integer 0
Long 0
Double 0.0
Single 0.0
Date December 31, 1899 00:00:00
Currency 0.0
Boolean False
Object Nothing
Variant Empty
String "" (zero-length string)
User-defined type Each element of the structure is given an initial value, as
described above.
Arrays Each element of the array is given an initial value, as described
above.
Naming Conventions
Variable names must follow these naming rules:
1. Must start with a letter.
2. May contain letters, digits, and the underscore character (_); punctuation is not
allowed. The exclamation point (!) can appear within the name as long as it is not
the last character, in which case it is interpreted as a type-declaration character.
3. The last character of the name can be any of the following type-declaration
characters: #, @, %, !, &, and $.
4. Must not exceed 80 characters in length.
5. Cannot be a reserved word.
Examples 'The following examples use the Dim statement to declare various
'variable types.
Sub Main()
Dim i As Integer
Dim l& 'Long
Dim s As Single
Dim d# 'Double
Dim c$ 'String
Dim MyArray(10) As Integer'10 element integer array
Dim MyStrings$(2,10)'2-10 element string arrays
Dim Filenames$(5 to 10)'6 element string array
Dim Values(1 to 10, 100 to 200)'111 element variant array
End Sub
See Also Redim (statement); Public (statement); Private (statement); Option Base (statement).
Platform(s) All.
Description Returns a String containing the first or next file matching pathname.
If pathname is specified, then the first file matching that pathname is returned. If
pathname is not specified, then the next file matching the initial pathname is returned.
Comments Dir$ returns a String, whereas Dir returns a String variant.
The Dir$/Dir functions take the following named parameters:
Named Parameter Description
pathname String containing a file specification.
If this parameter is specified, then Dir$ returns the first file
matching this file specification. If this parameter is omitted, then
the next file matching the initial file specification is returned.
If no path is specified in pathname, then all files are returned
from the current directory.
An error is generated if pathname$ is Null.
filetype Indicates the type of file to return. If pathname is also specified,
then files of this type are returned from that directory. Otherwise,
files of this type are returned from the current directory.
File types are specified using the MacID function.
attributes Integer specifying attributes of files you want included in the
list, as described below. If this parameter is omitted, then only
the normal, read-only, and archive files are returned.
An error is generated if Dir$ is called without first calling it with a valid pathname.
If there is no matching pathname, then a zero-length string is returned.
Wildcards
The pathname argument can include wildcards, such as * and ?. The * character
matches any sequence of zero or more characters, whereas the ? character matches any
single character. Multiple *'s and ?'s can appear within the expression to form complete
searching patterns. The following table shows some examples:
This pattern Matches these files Doesn't match these files
*S*.TXT [Link] SAMPLE
[Link] [Link]
[Link]
C*[Link] [Link] [Link]
[Link]
C*T CAT [Link]
[Link]
C?T CAT [Link]
CUT CAPIT
CT
* (All files)
Attributes
You can control which files are included in the search by specifying the optional
attributes parameter. The Dir, Dir$ functions always return all normal, read-only, and
archive files (ebNormal Or ebReadOnly Or ebArchive). To include additional files,
you can specify any combination of the following attributes (combined with the Or
operator):
Constant Value Includes
ebNormal 0 Read-only, archive, subdir, and none
ebHidden 2 Hidden files
ebSystem 4 System files
ebVolume 8 Volume label
ebDirectory 16 Subdirectories
Example 'This example dimensions a null array and fills it with
'directory entries. The result is displayed in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim a$(10)
a(1) = Dir$("*.*")
i% = 1
While (a(i%) <> "") And (i% < 10)
i% = i% + 1
a(i%) = Dir$
Wend
MsgBox a(1) & crlf & a(2) & crlf & a(3) & crlf & a(4)
End Sub
See Also ChDir (statement); ChDrive (statement); CurDir, CurDir$ (functions); MkDir
(statement); RmDir (statement); FileList (statement).
Platform(s) All.
Platform Notes Macintosh: The Macintosh does not support wildcard characters such as * and ?. These
are valid filename characters. Instead of wildcards, the Macintosh uses the MacID
function to specify a collection of files of the same type. The syntax for this function is:
Dir$(pathname,MacID(text$) [,attributes])
The text$ parameter is a four-character string containing a file type, a resource type, an
application signature, or an Apple event. A runtime error occurs if the MacID function
is used on platforms other than the Macintosh.
When the MacID function is used, the pathname parameter specifies the directory in
which to search for files of the indicated type.
Platform Notes Windows: For compatibility with DOS wildcard matching, BasicScript special-cases
the pattern "*.*" to indicate all files, not just files with a periods in their names.
UNIX: On UNIX platforms, the hidden file attribute corresponds to files without the
read or write attributes.
DiskDrives (statement)
Syntax DiskDrives array()
Description Fills the specified String or Variant array with a list of valid drive letters.
Comments The array() parameter specifies either a zero- or a one-dimensioned array of strings or
variants. The array can be either dynamic or fixed.
If array() is dynamic, then it will be redimensioned to exactly hold the new number of
elements. If there are no elements, then the array will be redimensioned to contain no
dimensions. You can use the LBound, UBound, and ArrayDims functions to
determine the number and size of the new array's dimensions.
If the array is fixed, each array element is first erased, then the new elements are placed
into the array. If there are fewer elements than will fit in the array, then the remaining
elements are initialized to zero-length strings (for String arrays) or Empty (for Variant
arrays). A runtime error results if the array is too small to hold the new elements.
Example 'This example builds and displays an array containing the first
'three available disk drives.
Sub Main()
Dim drive$()
DiskDrives drive$
r% = SelectBox("Available Disk Drives",,drive$)
End Sub
DiskFree (function)
Syntax DiskFree&([drive$])
Description Returns a Long containing the free space (in bytes) available on the specified drive.
Comments If drive$ is zero-length or not specified, then the current drive is assumed.
Only the first character of the drive$ string is used.
On systems that do not support drive letters, the drive$ parameter specifies the name of
the path from which to retrieve the free disk space.
Example 'This example uses DiskFree to set the value of i and then
'displays the result in a message box.
Sub Main()
s$ = "c"
i# = DiskFree(s$)
MsgBox "Free disk space on drive '" & s$ & "' is: " & i#
End Sub
DlgCaption (function)
Syntax DlgCaption[()]
Description Returns a string containing the caption of the active user-defined dialog box.
Comments This function returns a zero-length string if the active dialog has no caption.
DlgCaption (statement)
Syntax DlgCaption text
DlgControlId (function)
Syntax DlgControlId(ControlName$)
Description Returns an Integer containing the index of the specified control as it appears in the
dialog box template.
Comments The first control in the dialog box template is at index 0, the second is at index 1, and so
on.
The ControlName$ parameter contains the name of the .Identifier parameter associated
with that control in the dialog box template.
The BasicScript statements and functions that dynamically manipulate dialog box
controls identify individual controls using either the .Identifier name of the control or
the control's index. Using the index to refer to a control is slightly faster but results in
code that is more difficult to maintain.
Example Function DlgProc(ControlName$,Action%,SuppValue%) As Integer
'If a control is clicked, disable the next three controls.
If Action% = 2 Then
'Enable the next three controls.
start% = DlgControlId(ControlName$)
For i = start% + 1 To start% + 3
DlgEnable i,True
Next i
DlgProc = 1'Don't close the dialog box.
End If
End Function
See Also DlgEnable (function); DlgEnable (statement); DlgFocus (function); DlgFocus
(statement); DlgListBoxArray (function); DlgListBoxArray (statement);
DlgSetPicture (statement); DlgText (statement); DlgText$ (function); DlgValue
(function); DlgValue (statement); DlgVisible (statement); DlgVisible (function).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
DlgEnable (function)
Syntax DlgEnable(ControlName$ | ControlIndex)
Description Returns True if the specified control is enabled; returns False otherwise.
Comments Disabled controls are dimmed and cannot receive keyboard or mouse input.
The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. A case-insensitive comparison is used to
locate the specific control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its index in the dialog box
template (0 is the first control in the template, 1 is the second, and so on).
If you attempt to disable the control with the focus, BasicScript will automatically set
the focus to the next control in the tab order.
Example If DlgEnable("SaveOptions") Then
DlgEnable (statement)
Syntax DlgEnable {ControlName$ | ControlIndex} [,isOn]
DlgFocus (function)
Syntax DlgFocus$[()]
Description Returns a String containing the name of the control with the focus.
Comments The name of the control is the .Identifier parameter associated with the control in the
dialog box template.
Example 'This code fragment makes sure that the control being disabled
'does not currently have the focus (otherwise, a runtime error
'would occur).
If DlgFocus$ = "Files" Then'Does it have the focus?
DlgFocus "OK" 'Change the focus to another control.
End If
DlgEnable "Files", False'Now we can disable the control.
DlgFocus (statement)
Syntax DlgFocus ControlName$ | ControlIndex
The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. A case-insensitive comparison is used to
locate the specific control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its index in the dialog box
template (0 is the first control in the template, 1 is the second, and so on).
Example 'This code fragment makes sure that the control being disabled
'does not currently have the focus (otherwise, a runtime error
'would occur).
If DlgFocus$ = "Files" Then'Does it have the focus?
DlgFocus "OK"'Change the focus to another control.
End If
DlgEnable "Files", False'Now we can disable the control.
DlgListBoxArray (function)
Syntax DlgListBoxArray({ControlName$ | ControlIndex}, ArrayVariable)
Description Fills a list box, combo box, or drop list box with the elements of an array, returning an
Integer containing the number of elements that were actually set into the control.
Comments The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. A case-insensitive comparison is used to
locate the specific control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its index in the dialog box
template (0 is the first control in the template, 1 is the second, and so on).
DlgListBoxArray (statement)
Syntax DlgListBoxArray {ControlName$ | ControlIndex}, ArrayVariable
Description Fills a list box, combo box, or drop list box with the elements of an array.
Comments The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. A case-insensitive comparison is used to
locate the specific control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its index in the dialog box
template (0 is the first control in the template, 1 is the second, and so on).
DlgProc (function)
Syntax Function DlgProc(ControlName$, Action, SuppValue) As Integer
Description Describes the syntax, parameters, and return value for dialog functions.
Comments Dialog functions are called by BasicScript during the processing of a custom dialog box.
The name of a dialog function (DlgProc) appears in the Begin Dialog statement as the
.DlgProc parameter.
Dialog functions require the following parameters:
Parameter Description
ControlName$ String containing the name of the control associated with
Action.
Action Integer containing the action that called the dialog function.
SuppValue Integer of extra information associated with Action. For some
actions, this parameter is not used.
When BasicScript displays a custom dialog box, the user may click on buttons, type text
into edit fields, select items from lists, and perform other actions. When these actions
occur, BasicScript calls the dialog function, passing it the action, the name of the control
on which the action occurred, and any other relevant information associated with the
action.
The following table describes the different actions sent to dialog functions:
Action Description
1 This action is sent immediately before the dialog box is shown for the
first time. This gives the dialog function a chance to prepare the dialog
box for use. When this action is sent, ControlName$ contains a
zero-length string, and SuppValue is 0.
The return value from the dialog function is ignored in this case.
Action Description
Action Description
3 This action is sent when the content of a text box or combo box has
been changed. This action is only sent when the control loses focus.
When this action is sent, ControlName$ contains the name of the text
box or combo box, and SuppValue contains the length of the new
content.
The dialog function's return value is ignored with this action.
4 This action is sent when a control gains the focus. When this action is
sent, ControlName$ contains the name of the control gaining the
focus, and SuppValue contains the index of the control that lost the
focus (0-based).
The dialog function's return value is ignored with this action.
5 This action is sent continuously when the dialog box is idle. If the
dialog function returns 1 in response to this action, then the idle action
will continue to be sent. If the dialog function returns 0, then
BasicScript will not send any additional idle actions.
When the idle action is sent, ControlName$ contains a zero-length
string, and SuppValue contains the number of times the idle action has
been sent so far.
6 This action is sent when the dialog box is moved. The ControlName$
parameter contains a zero-length string, and SuppValue is 0.
The dialog function's return value is ignored with this action.
User-defined dialog boxes cannot be nested. In other words, the dialog function of one
dialog box cannot create another user-defined dialog box. You can, however, invoke any
built-in dialog box, such as MsgBox or InputBox$.
Within dialog functions, you can use the following additional BasicScript statements
and functions. These statements allow you to manipulate the dialog box controls
dynamically.
DlgVisible DlgText$ DlgText
DlgEnable DlgControlId
For compatibility with previous versions of BasicScript, the dialog function can
optionally be declared to return a Variant. When returning a variable, BasicScript will
attempt to convert the variant to an Integer. If the returned variant cannot be converted
to an Integer, then 0 is assumed to be returned from the dialog function.
Example 'This dialog function enables/disables a group of option buttons
DlgSetPicture (statement)
Syntax DlgSetPicture {ControlName$ | ControlIndex},PictureName$,PictureType
Description Changes the content of the specified picture or picture button control.
Comments The DlgSetPicture statement accepts the following parameters:
Parameter Description
ControlName$ String containing the name of the .Identifier parameter
associated with a control in the dialog box template. A
case-insensitive comparison is used to locate the specified
control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its
index in the dialog box template (0 is the first control in the
template, 1 is the second, and so on).
Note: When ControlIndex is specified, OptionGroup
statements do not count as a control.
Parameter Description
Picture libraries on the Macintosh are files with collections of named PICT resources.
The PictureName$ parameter corresponds to the name of one the resources as it appears
within the file..
DlgText (statement)
Syntax DlgText {ControlName$ | ControlIndex}, NewText$
DlgText$ (function)
Syntax DlgText$(ControlName$ | ControlIndex)
The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. A case-insensitive comparison is used to
locate the specific control within the template. Alternatively, by specifying the
ControlIndex parameter, a control can be referred to using its index in the dialog box
template (0 is the first control in the template, 1 is the second, and so on).
DlgValue (function)
Syntax DlgValue(ControlName$ | ControlIndex)
Option group The index of the selected option button within the group (0 is the
first option button, 1 is the second, and so on).
List box The index of the selected item.
Drop list box The index of the selected item.
Check box 1 if the check box is checked; 0 otherwise.
A runtime error is generated if DlgValue is used with controls other than those listed in
the above table.
The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. Alternatively, by specifying the ControlIndex
parameter, a control can be referred to using its index in the dialog box template (0 is
the first control in the template, 1 is the second, and so on).
DlgValue (statement)
Syntax DlgValue {ControlName$ | ControlIndex},Value
DlgVisible (function)
Syntax DlgVisible(ControlName$ | ControlIndex)
Description Returns True if the specified control is visible; returns False otherwise.
The ControlName$ parameter contains the name of the .Identifier parameter associated
with a control in the dialog box template. Alternatively, by specifying the ControlIndex
parameter, a control can be referred to using its index in the template (0 is the first
control in the template, 1 is the second, and so on).
DlgVisible (statement)
Syntax DlgVisible {ControlName$ | ControlIndex} [,isOn]
If you hide the control that currently has the focus, BasicScript will automatically set
focus to the next control in the tab order.
Picture Caching
When the dialog box is first created and before it is shown, BasicScript calls the dialog
function with action set to 1. At this time, no pictures have been loaded into the picture
controls contained in the dialog box template. After control returns from the dialog
function and before the dialog box is shown, BasicScript will load the pictures of all
visible picture controls. Thus, it is possible for the dialog function to hide certain picture
controls, which prevents the associated pictures from being loaded and causes the dialog
box to load faster. When a picture control is made visible for the first time, the
associated picture will then be loaded.
Example 'This example creates a dialog box with two panels. The
'DlgVisible statement is used to show or hide the controls of
'the different panels.
Sub EnableGroup(start%, finish%)
For i = 6 To 13 'Disable all options.
DlgVisible i, False
Next i
For i = start% To finish% 'Enable only the right ones.
DlgVisible i, True
Next i
End Sub
Function DlgProc(ControlName$, Action%, SuppValue%)
If Action% = 1 Then
DlgValue "WhichOptions",0 'Set to save options.
EnableGroup 6, 8 'Enable the save options.
End If
If Action% = 2 And ControlName$ = "SaveOptions" Then
EnableGroup 6, 8 'Enable the save options.
DlgProc = 1 'Don't close the dialog box.
End If
If Action% = 2 And ControlName$ = "EditingOptions" Then
EnableGroup 9, 13 'Enable the editing options.
DlgProc = 1 'Don't close the dialog box.
End If
End Function
Sub Main()
Begin Dialog OptionsDlg 33, 33, 171, 134, "Options", .DlgProc
'Background (controls 0-5)
GroupBox 8, 40, 152, 84, ""
OptionGroup .WhichOptions
OptionButton 8, 8, 59, 8, "Save Options",.SaveOptions
OptionButton 8, 20, 65, 8, _
"Editing Options",.EditingOptions
OKButton 116, 7, 44, 14
CancelButton 116, 24, 44, 14
'Save options (controls 6-8)
CheckBox 20, 56, 88, 8, "Always create backup",.CheckBox1
CheckBox 20, 68, 65, 8, "Automatic save",.CheckBox2
CheckBox 20, 80, 70, 8, "Allow overwriting",.CheckBox3
'Editing options (controls 9-13)
CheckBox 20, 56, 65, 8, "Overtype mode",.OvertypeMode
CheckBox 20, 68, 69, 8, "Uppercase only",.UppercaseOnly
CheckBox 20, 80, 105, 8, _
"Automatically check syntax",.AutoCheckSyntax
CheckBox 20, 92, 73, 8, _
"Full line selection",.FullLineSelection
CheckBox 20, 104, 102, 8, _
"Typing replaces selection",.TypingReplacesText
End Dialog
Dim OptionsDialog As OptionsDlg
Dialog OptionsDialog
End Sub
Do...Loop (statement)
Syntax 1 Do {While | Until} condition statements Loop
Syntax 2 Do
statements
Loop {While | Until} condition
Syntax 3 Do
statements
Loop
Description Repeats a block of BasicScript statements while a condition is True or until a condition
is True.
Comments If the {While | Until} conditional clause is not specified, then the loop repeats the
statements forever (or until BasicScript encounters an Exit Do statement).
The condition parameter specifies any Boolean expression.
Examples Sub Main()
'This first example uses the Do...While statement, which
'performs the iteration, then checks the condition, and repeats
'if the condition is True.
Dim a$(100)
i% = -1
Do
i% = i% + 1
If i% = 0 Then
a(i%) = Dir$("*")
Else
a(i%) = Dir$
End If
Loop While (a(i%) <> "" And i% <= 99)
r% = SelectBox(i% & " files found",,a)
'This second example uses the Do While...Loop, which checks the
'condition and then repeats if the condition is True.
Dim a$(100)
i% = 0
a(i%) = Dir$("*")
Do While a(i%) <> "" And i% <= 99
i% = i% + 1
a(i%) = Dir$
Loop
r% = SelectBox(i% & " files found",,a)
'This third example uses the Do Until...Loop, which does the
DoEvents (function)
Syntax DoEvents[()]
DoEvents (statement)
Syntax DoEvents
Platform(s) All.
Platform Notes Win32: Under Win32, this statement does nothing. Since Win32 systems are
preemptive, use of this statement under these platforms is not necessary.
DoKeys (statement)
Syntax DoKeys KeyString$ [,time]
Description A data type used to declare variables capable of holding real numbers with 15–16 digits
of precision.
Comment Double variables are used to hold numbers within the following ranges:
Sign Range
Negative –1.797693134862315E308 <= double <=
–4.94066E-324
Positive 4.94066E-324 <= double <= 1.797693134862315E308
The type-declaration character for Double is #.
Storage
Internally, doubles are 8-byte (64-bit) IEEE values. Thus, when appearing within a
structure, doubles require 8 bytes of storage. When used with binary or random files, 8
bytes of storage are required.
Each Double consists of the following
• A 1-bit sign
• An 11-bit exponent
• A 53-bit significand (mantissa)
See Also Currency (data type); Date (data type); Integer (data type); Long (data type); Object
(data type); Single (data type); String (data type); Variant (data type); Boolean (data
type); DefType (statement); CDbl (function).
Platform(s) All.
DropListBox (statement)
Syntax DropListBox x, y, width, height, ArrayVariable, .Identifier
• The user cannot type into a drop list box. Only items from the list box may be
selected. With combo boxes, the user can type the name of an item from the list
directly or type the name of an item that is not contained within the combo box.
This statement can only appear within a dialog box template (i.e., between the Begin
Dialog and End Dialog statements).
The DropListBox statement requires the following parameters:
Parameter Description
[Link] = 1
Dialog FindDialog
End Sub
EditEnabled (function)
Syntax EditEnabled(name$ | id)
Description Returns True if the given text box is enabled within the active window or dialog box;
returns False otherwise.
Comments The EditEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the text box.
The name of a text box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a text box.
id Integer specifying the ID of the text box.
A runtime error is generated if a text box control with the given name or ID cannot be
found within the active window.
If enabled, the text box can be given the focus using the ActivateControl statement.
Note: The EditEnabled function is used to determine whether a text box is enabled
in another application's dialog box. Use the DlgEnable function in dynamic dialog
boxes.
Example 'This example adjusts the left margin if this control is enabled.
Sub Main()
Menu "[Link]"
If EditEnabled("Left:") Then
SetEditText "Left:","5 pt"
End If
End Sub
EditExists (function)
Syntax EditExists(name$ | id)
Description Returns True if the given text box exists within the active window or dialog box; returns
False otherwise.
Note: The EditExists function is used to determine whether a text box exists in
another application's dialog box. There is no equivalent function for use with
dynamic dialog boxes.
Example 'This example adjusts the left margin if this control exists and
'is enabled.
Sub Main()
Menu "[Link]"
If EditExists("Left:") Then
If EditEnabled("Left:") Then
SetEditText "Left:","5 pt"
End If
End If
End Sub
See Also EditEnabled (function); GetEditText$ (function); SetEditText (statement).
Platform(s) Windows.
End (statement)
Syntax End
Description Terminates execution of the current script, closing all open files.
Example 'This example uses the End statement to stop execution.
Sub Main()
MsgBox "The next line will terminate the script."
End
End Sub
See Also Close (statement); Stop (statement); Exit For (statement); Exit Do (statement); Exit
Function (statement); Exit Sub (statement).
Platform(s) All.
Example 'This example looks for the DOS Comspec variable and displays
'the value in a dialog box.
Sub Main()
Dim a$(1)
a$(1) = Environ$("COMSPEC")
MsgBox "The DOS Comspec variable is set to: " & a$(1)
End Sub
EOF (function)
Syntax EOF(filenumber)
Description Returns True if the end-of-file has been reached for the given file; returns False
otherwise.
Comments The filenumber parameter is an Integer used by BasicScript to refer to the open file—
the number passed to the Open statement.
With sequential files, EOF returns True when the end of the file has been reached (i.e.,
the next file read command will result in a runtime error).
With Random or Binary files, EOF returns True after an attempt has been made to read
beyond the end of the file. Thus, EOF will only return True when Get was unable to
read the entire record.
Example 'This example opens the [Link] file and reads lines from
'the file until the end-of-file is reached.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim s$
Open "c:\[Link]" For Input As #1
Do While Not EOF(1)
Input #1,s$
Loop
Close
MsgBox "The last line was:" & crlf & s$
End Sub
See Also Open (statement); Lof (function).
Platform(s) All.
Eqv (operator)
Syntax result = expression1 Eqv expression2
Description Performs a logical or binary equivalence on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or Null variants, then a logical
equivalence is performed as follows:
If expression1 is and expression2 is then the result is
Binary Equivalence
If the two expressions are Integer, then a binary equivalence is performed, returning an
Integer result. All other numeric types (including Empty variants) are converted to
Long and a binary equivalence is then performed, returning a Long result.
Binary equivalence forms a new value based on a bit-by-bit comparison of the binary
representations of the two expressions, according to the following table:
If bit in expression1 is and bit in expression2 is the result is
1 1 1
0 1 0
Erase (statement)
Syntax Erase array1 [,array2]...
Erl (function)
Syntax Erl[()]
[Link] (method)
Syntax [Link]
[Link] ""
[Link] 0
[Link] ""
[Link] 0
[Link] 0
[Link] ""
The properties of the Err object are automatically reset when any of the following
statements are executed:
Resume Exit Function
On Error Exit Sub
Example 'The following script gets input from the user using error
'checking.
Sub Main()
Dim x As Integer
On Error Resume Next
x = InputBox("Type in a number")
If [Link] <> 0 Then
[Link]
x = 0
End If
MsgBox x
End Sub
See Also Error Handling (topic); [Link] (property); [Link] (property);
[Link] (property); [Link] (property); [Link] (property);
[Link] (property).
Platform(s) All.
[Link] (property)
Syntax [Link] [= stringexpression]
[Link] (property)
Syntax [Link] [= contextid]
Description Sets or retrieves the help context ID that identifies the help topic for information on the
error.
Comments The [Link] property, together with the [Link] property, contain
sufficient information to display help for the error.
When BasicScript generates an error, the [Link] property is set to 0 and the
[Link] property is set to ""; the value of the [Link] property is sufficient
for displaying help in this case. The exception is with errors generated by an OLE
automation server; both the [Link] and [Link] properties are set by
the server to values appropriate for the generated error.
When generating your own user-define errors, you should set the [Link]
property and the [Link] property appropriately for your error. If these are not set,
then BasicScript displays its own help at an appropriate place.
Example 'This example defines a replacement for InputBox that deals
'specifically with Integer values. If an error occurs, the
'function generates a user-defined error that can be trapped
'by the caller.
Function InputInteger(Prompt,Optional Title,Optional Def)
On Error Resume Next
Dim x As Integer
x = InputBox(Prompt,Title,Def)
If [Link] Then
[Link] = "[Link]"
[Link] = 2
[Link] = "Integer value expected"
InputInteger = Null
[Link] 3000
End If
InputInteger = x
End Function
Sub Main
Dim x As Integer
Do
On Error Resume Next
x = InputInteger("Enter a number:")
If [Link] = 3000 then
Msgbox "You didn’t type in a valid number, press ""F1"" _
"to invoke help file."
End If
Loop Until [Link] <> 3000
End Sub
See Also Error Handling (topic); [Link] (method); [Link] (property); [Link]
(property); [Link] (property); [Link] (property); [Link]
(property).
Platform(s) All.
[Link] (property)
Syntax [Link] [= filename]
Description Sets or retrieves the name of the help file associated with the error.
Comments The [Link] property, together with the [Link] property, contain
sufficient information to display help for the error.
When BasicScript generates an error, the [Link] property is set to 0 and the
[Link] property is set to ""; the value of the [Link] property is sufficient
for displaying help in this case. The exception is with errors generated by an OLE
automation server; both the [Link] and [Link] properties are set by
the server to values appropriate for the generated error.
When generating your own user-define errors, you should set the [Link]
property and the [Link] property appropriately for your error. If these are not set,
then BasicScript displays its own help at an appropriate place.
Example 'This example defines a replacement for InputBox that deals
'specifically with Integer values. If an error occurs, the
'function generates a user-defined error that can be trapped
'by the caller.
Function InputInteger(Prompt,Optional Title,Optional Def)
On Error Resume Next
Dim x As Integer
x = InputBox(Prompt,Title,Def)
If [Link] Then
[Link] = "[Link]"
[Link] = 2
[Link] = "Integer value expected"
InputInteger = Null
[Link] 3000
End If
InputInteger = x
End Function
Sub Main
Dim x As Integer
Do
On Error Resume Next
x = InputInteger("Enter a number:")
If [Link] = 3000 Then
Msgbox "You didn’t type in a valid number, press ""F1""_
"to invoke helpfile."
End If
[Link] (property)
Syntax [Link]
Description Returns the last error generated by an external call—i.e., a call to a routine declared
with the Declare statement that resides in an external module.
Comments The [Link] property is automatically set when calling a routine defined in
an external module. If no error occurs within the external call, then this property will
automatically be set to 0.
The [Link] property will always return 0 on platform where this property
is not supported.,
Example 'The following script calls the GetCurrentDirectoryA. If an
'error occurs, this Win32 function sets the [Link]
'property which can be checked for.
Declare Sub GetCurrentDirectoryA Lib "kernel32" (ByVal DestLen _
As Integer,ByVal lpDest As String)
Sub Main()
Dim dest As String * 256
[Link]
GetCurrentDirectoryA len(dest),dest
If [Link] <> 0 Then
MsgBox "Error " & [Link] & " occurred."
Else
MsgBox "Current directory is " & dest
End If
End Sub
Platform Notes Win32: On this platform, this property is set by DLL routines that set the last error
using the Win32 function SetLastError(). BasicScript uses the Win32 function
GetLastError() to retrieve the value of this property. The value 0 is returned when
calling DLL routines that do not set an error.
[Link] (property)
Syntax [Link] [= errornumber]
Err = 999
End If
Resume Next
End Sub
[Link] (method)
Syntax [Link] number [,[source] [,[description] [,[helpfile] [,helpcontext]]]]
Description Generates a runtime error, setting the specified properties of the Err object.
Comments The [Link] method has the following named parameters:
Named Parameter Description
number A Long value indicating the error number to be generated.
This parameter is required.
Error predefined by BasicScript are in the range between 0
and 1000.
source An optional String expression specifying the source of the
error—i.e., the object or module that generated the error.
If omitted, then BasicScript uses the name of the currently
executing script.
description An optional String expression describing the error.
If omitted and number maps to a predefined BasicScript error
number, then the corresponding predefined description is
used. Otherwise, the error "Application-defined or
object-define error" is used.
helpfile An optional String expression specifying the name of the
help file containing context-sensitive help for this error.
If omitted and number maps to a predefined BasicScript error
number, then the default help file is assumed.
helpcontext An optional Long value specifying the topic within helpfile
containing context-sensitive help for this error.
If some arguments are omitted, then the current property values of the Err object are
used.
This method can be used in place of the Error statement for generating errors. Using the
[Link] method gives you the opportunity to set the desired properties of the Err
object in one statement.
Example 'The following example uses the [Link] method to generate
'a user-defined error.
Sub Main()
Dim x As Variant
On Error Goto TRAP
x = InputBox("Enter a number:")
If Not IsNumber(x) Then
[Link] 3000,,"Invalid number specified","[Link]",30
End If
MsgBox x
Exit Sub
TRAP:
MsgBox [Link]
End Sub
See Also Error (statement); Error Handling (topic); [Link] (method); [Link]
(property); [Link] (property); [Link] (property); [Link]
(property); [Link] (property).
Platform(s) All.
[Link] (property)
Syntax [Link] [= stringexpression]
[Link] = "InputInteger"
[Link] = "Integer value expected"
InputInteger = Null
[Link] 3000
End If
InputInteger = x
End Function
Sub Main
On Error Resume Next
x = InputInteger("Enter a number:")
If [Link] Then MsgBox [Link] & ":" & [Link]
End Sub
Error (statement)
Syntax Error errornumber
Error Handlers
BasicScript supports nested error handlers. When an error occurs within a subroutine,
BasicScript checks for an On Error handler within the currently executing subroutine
or function. An error handler is defined as follows:
Sub foo()
On Error Goto catch
'Do something here.
Exit Sub
catch:
'Handle error here.
End Sub
Error handlers have a life local to the procedure in which they are defined. The error is
reset when any of the following conditions occurs:
• An On Error or Resume statement is encountered.
• When [Link] is set to -1.
• When the [Link] method is called.
• When an Exit Sub, Exit Function, End Function, End Sub is encountered.
Cascading Errors
If a runtime error occurs and no On Error handler is defined within the currently
executing procedure, then BasicScript returns to the calling procedure and executes the
error handler there. This process repeats until a procedure is found that contains an error
handler or until there are no more procedures. If an error is not trapped or if an error
occurs within the error handler, then BasicScript displays an error message, halting
execution of the script.
Once an error handler has control, it should address the condition that caused the error
and resume execution with the Resume statement. This statement resets the error
handler, transferring execution to an appropriate place within the current procedure. The
error is reset if the procedure exits without first executing Resume.
Description Returns a String containing the text corresponding to the given error number or the
most recent error.
Comments Error$ returns a String, whereas Error returns a String variant.
The errornumber parameter is an Integer containing the number of the error message to
retrieve. If this parameter is omitted, then the function returns the text corresponding to
the most recent runtime error (i.e., the same as returned by the [Link]
property). If no runtime error has occurred, then a zero-length string is returned.
If the Error statement was used to generate a user-defined runtime error, then this
function will return a zero-length string ("").
Example 'This example forces error 10, with a subsequent transfer to
'the TestError label. TestError tests the error and, if not
'error 55, resets Err to 999 (user-defined error) and returns
'to the Main subroutine.
Sub Main()
On Error Goto TestError
Error 10
MsgBox "The returned error is: '" & Err() & " - " _
& Error$ & "'"
Exit Sub
TestError:
If Err = 55 Then 'File already open.
MsgBox "Cannot copy an open file. Close it and try again."
Else
MsgBox "Error '" & Err & "' has occurred."
Err = 999
End If
Resume Next
End Sub
Exit Do (statement)
Syntax Exit Do
Description Causes execution to continue on the statement following the Loop clause.
Comments This statement can only appear within a Do...Loop statement.
Example 'This example will load an array with directory entries unless
'there are more than ten entries--in which case, the Exit Do
'terminates the loop.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim a$(5)
Do
i% = i% + 1
If i% = 1 Then
a(i%) = Dir$("*")
Else
a(i%) = Dir$
End If
If i% >= 10 Then Exit Do
Loop While (a(i%) <> "")
If i% = 10 Then
MsgBox i% & " entries processed!"
Else
MsgBox "Less than " & i% & " entries processed!"
End If
End Sub
See Also Stop (statement); Exit For (statement); Exit Function (statement); Exit Sub
(statement); End (statement); Do...Loop (statement).
Platform(s) All.
Description Causes execution to exit the innermost For loop, continuing execution on the line
following the Next statement.
Comments This statement can only appear within a For...Next block.
Example 'This example will fill an array with directory entries until a
'null entry is encountered or 100 entries have been processed--
'at which time, the loop is terminated by an Exit For statement.
'The dialog box displays a count of files found and then some
'entries from the array.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim a$(100)
For i = 1 To 100
If i = 1 Then
a$(i) = Dir$("*")
Else
a$(i) = Dir$
End If
If (a$(i) = "") Or (i >= 100) Then Exit For
Next i
message = "There are " & i & " files found." & crlf
MsgBox message & a$(1) & crlf & a$(2) & crlf & a$(3) & crlf &
a$(10)
End Sub
See Also Stop (statement); Exit Do (statement); Exit Function (statement); Exit Sub
(statement); End (statement); For...Next (statement).
Platform(s) All.
Description Causes execution to exit the current function, continuing execution on the statement
following the call to this function.
Comments This statement can only appear within a function.
Example 'This function displays a message and then terminates with Exit
'Function.
Function Test_Exit() As Integer
MsgBox "Testing function exit, returning to Main()."
Test_Exit = 0
Exit Function
MsgBox "This line should never execute."
End Function
Sub Main()
a% = Test_Exit()
MsgBox "This is the last line of Main()."
End Sub
See Also Stop (statement); Exit For (statement); Exit Do (statement); Exit Sub (statement); End
(statement); Function...End Function (statement).
Platform(s) All.
Description Causes execution to exit the current subroutine, continuing execution on the statement
following the call to this subroutine.
Comments This statement can appear anywhere within a subroutine. It cannot appear within a
function.
Example 'This example displays a dialog box and then exits. The last
'line should never execute because of the Exit Sub statement.
Sub Main()
MsgBox "Terminating Main()."
Exit Sub
Exp (function)
Syntax Exp(number)
Type Coercion
BasicScript performs numeric type conversion automatically. Automatic conversions
sometimes result in overflow errors, as shown in the following example:
d# = 45354
i% = d#
In this example, an overflow error is generated because the value contained in d# is
larger than the maximum size of an Integer.
Rounding
When floating-point values (Single or Double) are converted to integer values (Integer
or Long), the fractional part of the floating-point number is lost, rounding to the nearest
integer value. BasicScript uses Baker's rounding:
• If the fractional part is larger than .5, the number is rounded up.
• If the fractional part is smaller than .5, the number is rounded down.
• If the fractional part is equal to .5, then the number is rounded up if it is odd and
down if it is even.
The following table shows sample values before and after rounding:
Before Rounding After Rounding to Whole Number
2.1 2
4.6 5
2.5 2
3.5 4
Default Properties
When an OLE object variable or an Object variant is used with numerical operators
such as addition or subtraction, then the default property of that object is automatically
retrieved. For example, consider the following:
Dim Excel As Object
Set Excel = GetObject(,"[Link]")
MsgBox "This application is " & Excel
The above example displays "This application is Microsoft Excel" in a dialog box.
When the variable Excel is used within the expression, the default property is
automatically retrieved, which, in this case, is the string "Microsoft Excel." Considering
that the default property of the Excel object is .Value, then the following two statements
are equivalent:
FileAttr (function)
Syntax FileAttr(filenumber, returntype)
Description Returns an Integer specifying the file mode (if returntype is 1) or the operating system
file handle (if returntype is 2).
Comments The FileAttr function takes the following named parameters:
Named Parameter Description
See Also FileLen (function); GetAttr (function); FileType (function); FileExists (function);
Open (statement); SetAttr (statement).
Platform(s) All.
FileCopy (statement)
Syntax FileCopy source, destination
End Sub
See Also Kill (statement); Name (statement).
Platform(s) All.
FileDateTime (function)
Syntax FileDateTime(pathname)
Description Returns a Date variant representing the date and time of the last modification of a file.
Comments This function retrieves the date and time of the last modification of the file specified by
pathname (wildcards are not allowed). A runtime error results if the file does not exist.
The value returned can be used with the date/time functions (i.e., Year, Month, Day,
Weekday, Minute, Second, Hour) to extract the individual elements.
Some operating systems (such as Win32) store the file creation date, last modification
date, and the date the file was last written to. The FileDateTime function only returns
the last modification date.
Example 'This example gets the file date/time of the [Link] file
'and displays it in a dialog box.
Sub Main()
If FileExists("c:\[Link]") Then
a# = FileDateTime("c:\[Link]")
MsgBox "The date/time information for the file is: " _
& Year(a#) & "-" & Month(a#) & "-" & Day(a#)
Else
MsgBox "The file does not exist."
End If
End Sub
See Also FileLen (function); GetAttr (function); FileType (function); FileAttr (function);
FileExists (function).
Platform(s) All.
FileDirs (statement)
Syntax FileDirs array() [,dirspec$]
Description Fills a String or Variant array with directory names from disk.
FileExists (function)
Syntax FileExists(filename$)
Note: On some file systems, the directories "." and ".." will be returned.
FileLen (function)
Syntax FileLen(pathname)
FileList (statement)
Syntax FileList array() [,[filespec$] [,[include_attr] [,exclude_attr]]]
Wildcards
The * character matches any sequence of zero or more characters, whereas the ?
character matches any single character. Multiple *'s and ?'s can appear within the
expression to form complete searching patterns. The following table shows some
examples:
This pattern Matches these files Doesn't match these files
*S.*TXT SAMPLE. TXT SAMPLE
[Link] [Link]
[Link]
C*[Link] [Link] [Link]
[Link]
C*T CAT [Link]
[Link]
C?T CAT [Link]
CUT CAPIT
CT
* (All files)
File Attributes
These numbers can be any combination of the following:
Constant Value Includes
ebNormal 0 Read-only, archive, subdir, none
ebReadOnly 1 Read-only files
ebHidden 2 Hidden files
ebSystem 4 System files
ebVolume 8 Volume label
ebDirectory 16 Subdirectories
ebArchive 32 Files that have changed since the last backup
ebNone 64 Files with no attributes
Example 'This example fills an array a with the directory of the current
'drive for all files that have normal or no attributes and
'excludes those with system attributes. The dialog box displays
'four filenames from the array.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim a$()
FileList a$,"*.*", (ebNormal + ebNone), ebSystem
If ArrayDims(a$) > 0 Then
MsgBox a$(1) & crlf & a$(2) & crlf & a$(3) & crlf & a$(4)
Else
MsgBox "No files found."
End If
End Sub
See Also FileDirs (statement); Dir, Dir$ (functions).
Platform(s) All.
Platform Notes Windows: For compatibility with DOS wildcard matching, BasicScript special-cases
the pattern "*.*" to indicate all files, not just files with a periods in their names.
UNIX: On UNIX platforms, the hidden file attribute corresponds to files without the
read or write attributes.
FileParse$ (function)
Syntax FileParse$(filename$[, operation])
Description Returns a String containing a portion of filename$ such as the path, drive, or file
extension.
Comments The filename$ parameter can specify any valid filename (it does not have to exist). For
example:
..\[Link]
c:\sheets\[Link]
[Link]
A runtime error is generated if filename$ is a zero-length string.
The optional operation parameter is an Integer specifying which portion of the
filename$ to extract. It can be any of the following values.
Value Meaning Example
If operation is not specified, then the full name is returned. A runtime error will result if
operation is not one of the above values.
A runtime error results if filename$ is empty.
On systems that do not support drive letters, operation 1 will return a zero-length string.
Example 'This example parses the file string "c:\testsub\[Link]"
'into its component parts and displays them in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim a$(6)
For i = 1 To 5
a$(i) = FileParse$("c:\testsub\[Link]",i - 1)
Next i
MsgBox a$(1) & crlf & a$(2) & crlf & a$(3) & crlf & a$(4) &
crlf & a$(5)
End Sub
See Also FileLen (function); GetAttr (function); FileType (function); FileAttr (function);
FileExists (function).
Platform(s) All.
Platform Notes Windows, Win32, OS/2: The path separator is different on different platforms. Under
Windows, OS/2, and Win32, the backslash and forward slash can be used
interchangeably. For example, "c:\[Link]" is the same as "c:/[Link]".
UNIX: Under UNIX systems, the backslash and colon are valid filename characters.
Macintosh: On the Macintosh, all characters are valid within filenames except colons,
which are seen as path separators.
NetWare: Under NetWare, operation 1 returns the volume name (up to 14 characters).
FileType (function)
Syntax FileType(filename$)
Fix (function)
Syntax Fix(number)
member Name of the variable used for each iteration of the loop. If
group is an array, then member must be a Variant variable. If
group is a collection, then member must be an Object variable,
an explicit OLE automation object, or a Variant.
group Name of a collection or array.
statements Any number of BasicScript statements.
BasicScript supports iteration through the elements of OLE collections or arrays, unless
the arrays contain user-defined types or fixed-length strings. The iteration variable is a
copy of the collection or array element in the sense thata change to the value of member
within the loop has no effect on the collection or array.
The For Each...Next statement traverses array elements in the same order the elements
are stored in memory. For example, the array elements contained in the array defined by
the statement
Dim a(1 To 2,3 To 4)
are traversed in the following order: (1,3), (1,4), (2,3), (2,4). The order in which the
elements are traversed should not be relevant to the correct operation of the script.
The For Each...Next statement continues executing until there are no more elements in
group or until an Exit For statement is encountered.
For Each...Next statements can be nested. In such a case, the Next [member] statement
applies to the innermost For Each...Next or For...Next statement. Each member
variable of nested For Each...Next statements must be unique.
A Next statement appearing by itself (with no member variable) matches the innermost
For Each...Next or For...Next loop.
Example ’The following subroutine iterates through the elements
’of an array using For Each...Next.
Sub Main()
Dim a(3 To 10) As Single
Dim i As Variant
Dim s As String
For i = 3 To 10
a(i) = Rnd()
Next i
For Each i In a
i = i + 1
Next i
s = ""
For Each i In a
If s <> "" Then s = s & ","
s = s & i
Next i
MsgBox s
End Sub
’The following subroutine displays the names of each worksheet
’in an Excel workbook.
Sub Main()
Dim Excel As Object
Dim Sheets As Object
Set Excel = CreateObject("[Link]")
[Link] = 1
[Link]
Set Sheets = [Link]
For Each a In Sheets
MsgBox [Link]
Next a
End Sub
For...Next (statement)
Syntax For counter = start To end [Step increment]
[statements]
[Exit For]
[statements]
Next [counter [,nextcounter]... ]
Description Repeats a block of statements a specified number of times, incrementing a loop counter
by a given increment each time through the loop.
Comments The For statement takes the following parameters:
Parameter Description
counter Name of a numeric variable. Variables of the following types
can be used: Integer, Long, Single, Double, Variant.
start Initial value for counter. The first time through the loop,
counter is assigned this value.
end Final value for counter. The statements will continue executing
until counter is equal to end.
increment Amount added to counter each time through the loop. If end is
greater than start, then increment must be positive. If end is less
than start, then increment must be negative.
If increment is not specified, then 1 is assumed. The expression
given as increment is evaluated only once. Changing the step
during execution of the loop will have no effect.
statements Any number of BasicScript statements.
The For...Next statement continues executing until an Exit For statement is
encountered when counter is greater than end.
For...Next statements can be nested. In such a case, the Next [counter] statement
applies to the innermost For...Next.
The Next clause can be optimized for nested next loops by separating each counter with
a comma. The ordering of the counters must be consistent with the nesting order
(innermost counter appearing before outermost counter). The following example shows
two equivalent For statements:
For i = 1 To 10 For i = 1 To 10
For j = 1 To 10 For j = 1 To 10
Next j Next j,i
Next i
A Next clause appearing by itself (with no counter variable) matches the innermost For
loop.
The counter variable can be changed within the loop but will have no effect on the
number of times the loop will execute.
Example 'This example constructs a truth table for the OR statement
'using nested For...Next loops.
Sub Main()
Dim m As String
For x = -1 To 0
For y = -1 To 0
z = x Or y
m = m & Format(Abs(x),"0") & " Or "
m = m & Format(Abs(y),"0") & " = "
m = m & Format(Z,"True/False") & [Link]$
Next y
Next x
MsgBox m
End Sub
Built-In Formats
To format numeric expressions, you can specify one of the built-in formats. There are
two categories of built-in formats: one deals with numeric expressions and the other
with date/time [Link] following tables list the built-in numeric and date/time format
strings, followed by an explanation of what each does.
Numeric Formats
Format Description
Date/Time Formats
Format Description
General date Displays the date and time. If there is no fractional part in
the numeric expression, then only the date is displayed. If
there is no integral part in the numeric expression, then
only the time is displayed. Output is in the following form:
1/1/95 01:00:00 AM.
Long time Displays the long time. The default is: h:mm:ss.
Medium time Displays the time using a 12-hour clock. Hours and
minutes are displayed, and the AM/PM designator is at the
end.
Short time Displays the time using a 24-hour clock. Hours and
minutes are displayed.
User-Defined Formats
In addition to the built-in formats, you can specify a user-defined format by using
characters that have special meaning when used in a format expression. The following
tables list the characters you can use for numeric, string, and date/time formats and
explain their functions.
Numeric Formats
Character Meaning
"ABC" Displays the text between the quotation marks, but not the
quotation marks. To designate a double quotation mark
within a format string, use two adjacent double quotation
marks.
Numeric formats can contain one to three parts. Each part is separated by a semicolon.
If you specify one format, it applies to all values. If you specify two formats, the first
applies to positive values and the second to negative values. If you specify three
formats, the first applies to positive values, the second to negative values, and the third
to 0s. If you include semicolons with no format between them, the format for positive
values is used.
String Formats
Character Meaning
Date/Time Formats
Character Meaning
c Displays the date as ddddd and the time as ttttt. Only the
date is displayed if no fractional part exists in the numeric
expression. Only the time is displayed if no integral portion
exists in the numeric expression.
Platform(s) All.
Platform Notes Windows, Win32: Under Windows and Win32, default date/time formats are read from
the [Intl] section of the [Link] file.
FreeFile (function)
Syntax FreeFile [([rangenumber])]
Part Description
Public Indicates that the function being defined can be called from
other scripts. If both the Private and Public keywords are
missing, then Public is assumed.
Static Recognized by the compiler but currently has no effect.
name Name of the function, which must follow BasicScript naming
conventions:
1. Must start with a letter.
2. May contain letters, digits, and the underscore character
(_). Punctuation and type-declaration characters are not
allowed. The exclamation point (!) can appear within the
name as long as it is not the last character, in which case it
is interpreted as a type-declaration character.
3. Must not exceed 80 characters in length.
Additionally, the name parameter can end with an optional
type-declaration character specifying the type of data returned
by the function (i.e., any of the following characters: %, &, !, #,
@).
Optional Keyword indicating that the parameter is optional. All optional
parameters must be of type Variant. Furthermore, all
parameters that follow the first optional parameter must also be
optional.
If this keyword is omitted, then the parameter is required.
Note: You can use the IsMissing function to determine whether
an optional parameter was actually passed by the caller.
ByVal Keyword indicating that parameter is passed by value.
ByRef Keyword indicating that parameter is passed by reference. If
neither the ByVal nor the ByRef keyword is given, then ByRef
is assumed.
parameter Name of the parameter, which must follow the same naming
conventions as those used by variables. This name can include a
type-declaration character, appearing in place of As type.
type Type of the parameter (Integer, String, and so on). Arrays are
indicated with parentheses. For example, an array of integers
would be declared as follows:
Function Test(a() As Integer)
End Function
Part Description
ReturnType Type of data returned by the function. If the return type is not
given, then Variant is assumed. The ReturnType can only be
specified if the function name (i.e., the name parameter) does
not contain an explicit type-declaration character.
A function returns to the caller when either of the following statements is encountered:
End Function
Exit Function
Functions can be recursive.
Optional Parameters
BasicScript allows you to skip parameters when calling functions, as shown in the
following example:
Function Test(a%,b%,c%) As Variant
End Function
Sub Main
a = Test(1,,4) 'Parameter 2 was skipped.
End Sub
You can skip any parameter, with the following restrictions:
1. The call cannot end with a comma. For instance, using the above example, the
following is not valid:
a = Test(1,,)
2. The call must contain the minimum number of parameters as required by the called
function. For instance, using the above example, the following are invalid:
a = Test(,1) 'Only passes two out of three required
'parameters.
a = Test(1,2) 'Only passes two out of three required
'parameters.
When you skip a parameter in this manner, BasicScript creates a temporary variable and
passes this variable instead. The value of this temporary variable depends on the data
type of the corresponding parameter in the argument list of the called function, as
described in the following table:
Value Data Type
0 Integer, Long, Single, Double, Currency
Zero-length string String
Nothing Object (or any data object)
Error Variant
December 30, 1899 Date
False Boolean
Within the called function, you will be unable to determine whether a parameter was
skipped unless the parameter was declared as a variant in the argument list of the
function. In this case, you can use the IsMissing function to determine whether the
parameter was skipped:
Function Test(a,b,c)
If IsMissing(a) Or IsMissing(b) Then Exit Sub
End Function
Fv (function)
Syntax Fv(rate, nper, pmt, pv, due)
Description Calculates the future value of an annuity based on periodic fixed payments and a
constant rate of interest.
Get (statement)
Syntax Get [#] filenumber, [recordnumber], variable
Description Retrieves data from a random or binary file and stores that data into the specified
variable.
Comments The Get statement accepts the following parameters:
Parameter Description
filenumber Integer used by BasicScript to identify the file. This is the same
number passed to the Open statement.
recordnumber Long specifying which record is to be read from the file.
For binary files, this number represents the first byte to be read
starting with the beginning of the file (the first byte is 1). For
random files, this number represents the record number starting
with the beginning of the file (the first record is 1). This value
ranges from 1 to 2147483647.
If the recordnumber parameter is omitted, the next record is
read from the file (if no records have been read yet, then the first
record in the file is read). When this parameter is omitted, the
commas must still appear, as in the following example:
Get #1,,recvar
If recordnumber is specified, it overrides any previous change
in file position specified with the Seek statement.
variable Variable into which data will be read. The type of the variable
determines how the data is read from the file, as described
below.
With random files, a runtime error will occur if the length of the data being read exceeds
the reclen parameter specified with the Open statement. If the length of the data being
read is less than the record length, the file pointer is advanced to the start of the next
record. With binary files, the data elements being read are contiguousthe file pointer
is never advanced.
Variable Types
The type of the variable parameter determines how data will be read from the file. It can
be any of the following types:
Variable Type File Storage Description
Integer 2 bytes are read from the file.
Long 4 bytes are read from the file.
See Also Open (statement); Put (statement); Input# (statement); Line Input# (statement);
Input, Input$, InputB, InputB$ (functions).
Platform(s) All.
GetAllSettings (function)
Syntax GetAllSettings(appname [,section])
Description Returns all of the keys within the specified section, or all of the sections within the
specified application from the system registry.
Comments The GetAllSettings function takes the following named parameters:
Named Parameter Description
appname A String expression specifying the name of the application
from which settings or keys will be returned.
section A String expression specifying the name of the section from
which keys will be returned. If omitted, then all of the section
names within appname will be returned.
GetAttr (function)
Syntax GetAttr(pathname)
Platform Notes Windows: Under Windows, these attributes are the same as those used by DOS.
UNIX: On UNIX platforms, the hidden file attribute corresponds to files without the
read or write attributes.
GetCheckBox (function)
Syntax GetCheckBox(name$ | id)
Description Returns an Integer representing the state of the specified check box.
Comments This function is used to determine the state of a check box, given its name or ID. The
returned value will be one of the following:
Returned Value Description
0 Check box contains no check.
1 Check box contains a check.
2 Check box is grayed.
The GetCheckBox function takes the following parameters:
Parameter Description
name$ String containing the name of the check box.
id Integer specifying the ID of the check box.
Note: The GetCheckBox function is used to retrieve the state of a check box in
another application's dialog box. Use the DlgValue function to retrieve the state of a
check box in a dynamic dialog box.
Example 'This example toggles the Match Case check box in the Find
'dialog box.
Sub Main()
Menu "[Link]"
If GetCheckBox("Match Case") = 0 Then
SetCheckBox "Match Case",1
Else
SetCheckBox "Match Case",0
End If
End Sub
GetComboBoxItem$ (function)
Syntax GetComboBoxItem$(name$ | id [,ItemNumber])
Description Returns a String containing the text of an item within a combo box.
Comments The GetComboBoxItem$ function takes the following parameters:
Parameter Description
name$ String specifying the name of the combo box containing the
item to be returned.
The name of a combo box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a combo box. A runtime error is
generated if a combo box with that name cannot be found within
the active window.
id Integer specifying the ID of the combo box containing the item
to be returned.
ItemNumber Integer containing the line number of the desired combo box
item to be returned. If omitted, then the currently selected item in
the combo box is returned.
The combo box must exist within the current window or dialog box; otherwise, a
runtime error is generated.
A zero-length string will be returned if the combo box does not contain textual items.
Example 'This example retrieves the last item from a combo box.
Sub Main()
last% = GetComboBoxItemCount("Directories:")
s$ = GetComboBoxItem$("Directories:",last% - 1) 'Number is
'0-based.
MsgBox "The last item in the combo box is " & s$
End Sub
See Also ComboBoxEnabled (function); ComboBoxExists (function);
GetComboBoxItemCount (function); SelectComboBoxItem (statement).
Platform(s) Windows.
GetComboBoxItemCount (function)
Syntax GetComboBoxItemCount(name$ | id)
Description Returns an Integer containing the number of items in the specified combo box.
Comments The GetComboBoxItemCount function takes the following parameters:
Parameter Description
name$ String containing the name of the combo box.
The name of a combo box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a combo box. A runtime error is
generated if a combo box with that name cannot be found within
the active window.
id Integer specifying the ID of the combo box.
A runtime error is generated if the specified combo box does not exist within the current
window or dialog box.
Example 'This example copies all the items out of a combo box and into
'an array.
Sub Main()
Dim MyList$()
last% = GetComboBoxItemCount("Directories:")
ReDim MyList$(0 To last - 1)
For i = 0 To last - 1
MyList$(i) = GetComboBoxItem$("Directories:",i)
Next i
End Sub
See Also ComboBoxEnabled (function); ComboBoxExists (function); GetComboBoxItem$
(function); SelectComboBoxItem (statement).
Platform(s) Windows.
GetEditText$ (function)
Syntax GetEditText$(name$ | id)
Description Returns a String containing the content of the specified text box control.
Note: The GetEditText$ function is used to retrieve the content of a text box in
another application's dialog box. Use the DlgText$ function to retrieve the content of
a text box in a dynamic dialog box.
Example 'This example retrieves the filename and prepends it with the
'current directory.
Sub Main()
s$ = GetEditText$("Filename:")'Retrieve edit control content.
s$ = CurDir$ & [Link] & s$'Prepend current dir.
SetEditText "Filename:",s$'Put it back.
End Sub
See Also EditEnabled (function); EditExists (function); SetEditText (statement).
Platform(s) Windows.
GetListBoxItem$ (function)
Syntax GetListBoxItem$(name$ | id,[item])
Parameter Description
The name of a list box is determined by scanning the window list
looking for a text control with the given name that is
immediately followed by a list box. A runtime error is generated
if a list box with that name cannot be found within the active
window.
id Integer specifying the ID of the list box containing the item to
be returned.
item Integer containing the line number of the desired list box item to
be returned. This number must be between 1 and the number of
items in the list box.
If omitted, then the currently selected item in the list box is
returned.
A runtime error is generated if the specified list box cannot be found within the active
window.
Note: The GetListBoxItem$ function is used to retrieve an item from a list box in
another application's dialog box. There is no equivalent function for use with
dynamic dialog boxes.
GetListBoxItemCount (function)
Syntax GetListBoxItemCount(name$ | id)
Description Returns an Integer containing the number of items in a specified list box.
GetObject (function)
Syntax GetObject(pathname [, class])
Description Returns the object specified by pathname or returns a previously instantiated object of
the given class.
Comments This function is used to retrieve an existing OLE Automation object, either one that
comes from a file or one that has previously been instantiated.
The pathname argument specifies the full pathname of the file containing the object to
be activated. The application associated with the file is determined by OLE at runtime.
For example, suppose that a file called c:\docs\[Link] was created by a word
processor called [Link]. The following statement would invoke [Link],
load the file called c:\docs\[Link], and assign that object to a variable:
Dim doc As Object
Set doc = GetObject("c:\docs\[Link]")
To activate a part of an object, add an exclamation point to the filename followed by a
string representing the part of the object that you want to activate. For example, to
activate the first three pages of the document in the previous example:
GetOption (function)
Syntax GetOption(name$ | id)
Parameter Description
Note: The GetOption function is used to retrieve the state of an option button in
another application's dialog box. Use the DlgValue function to retrieve the state of
an option button in a dynamic dialog box.
Example 'This example figures out which option is set in the Desktop
'dialog box of the Control Panel.
Sub Main()
id = Shell("control",7)'Run the Control Panel.
WinActivate "Control Panel"'Activate the Control Panel window.
Menu "[Link]"'Select Desktop dialog box.
WinActivate "Control Panel|Desktop"'Activate it.
If GetOption("Tile") Then'Retrieve which option is set.
MsgBox "Your wallpaper is tiled."
Else
MsgBox "Your wallpaper is centered."
End If
End Sub
See Also OptionEnabled (function); OptionExists (function); SetOption (statement).
Platform(s) Windows.
GetSetting (function)
Syntax GetSetting([appname], section, key[, default])
Global (statement)
Description See Public (statement).
Platform(s) All.
GoSub (statement)
Syntax GoSub label
Goto (statement)
Syntax Goto label
The label must appear within the same subroutine or function as the Goto.
Labels are identifiers that follow these rules:
1. Must begin with a letter.
2. May contain letters, digits, and the underscore character.
3. Must not exceed 80 characters in length.
4. Must be followed by a colon (:).
Labels are not case-sensitive.
Example 'This example gets a name from the user and then branches to a
'statement, depending on the input name. If the name is not
'MICHAEL, it is reset to MICHAEL unless it is null or the user
'clicks Cancel--in which case, the program displays a message
'and terminates.
Sub Main()
uname$ = Ucase$(InputBox$("Enter your name:","Enter Name"))
If uname$ = "MICHAEL" Then
Goto RightName
Else
Goto WrongName
End If
WrongName:
If (uname$ = "") Then
MsgBox "No name? Clicked Cancel? I'm shutting down."
Else
MsgBox "I am renaming you MICHAEL!"
uname$ = "MICHAEL"
Goto RightName
End If
Exit Sub
RightName:
MsgBox "Hello, MICHAEL!"
End Sub
GroupBox (statement)
Syntax GroupBox x,y,width,height,title$ [,.Identifier]
HelpButton (statement)
Syntax HelpButton x,y,width,height,HelpFileName$,HelpContext, [,.Identifier]
x,y Integer position of the control (in dialog units) relative to the
upper left corner of the dialog box.
width,height Integer dimensions of the control in dialog units.
HelpFileName$ String expression specifying the name of the help file to be
invoked when the button is selected.
HelpContext Long expression specifying the ID of the topic within
HelpFileName$ containing context-sensitive help.
.Identifier Name by which this control can be referenced by statements
in a dialog function (such as DlgFocus and DlgEnable).
When the user selects a help button, the associated help file is located at the indicated
topic. Selecting a help button does not remove the dialog. Similarly, no actions are sent
to the dialog procedure when a help button is selected.
When a help button is present within a dialog, it can be automatically selected by
pressing the help key (F1 on most platforms).
Example Sub Main()
Begin Dialog HelpDialogTemplate ,,180,96,"Untitled"
OKButton 132,8,40,14
CancelButton 132,28,40,14
HelpButton 132,48,40,14,"", 10
Text 16,12,88,12,"Please click ""Help"".",.Text1
End Dialog
Dim HelpDialog As
HelpDialogTemplat
e
Dialog HelpDialog End Sub
HLine (statement)
Syntax HLine [lines]
Description Scrolls the window with the focus left or right by the specified number of lines.
Comments The lines parameter is an Integer specifying the number of lines to scroll. If this
parameter is omitted, then the window is scrolled right by one line.
Example 'This example scrolls the Notepad window to the left by three
'"amounts." Each "amount" is equivalent to clicking the right
'arrow of the horizontal scroll bar once.
Sub Main()
AppActivate "Notepad"
HLine 3 'Move 3 lines in.
End Sub
Hour (function)
Syntax Hour(time)
Description Returns the hour of the day encoded in the specified time parameter.
Comments The value returned is as an Integer between 0 and 23 inclusive.
The time parameter is any expression that converts to a Date.
Example 'This example takes the current time; extracts the hour, minute,
'and second; and displays them as the current time.
Sub Main()
xt# = TimeValue(Time$())
xh# = Hour(xt#)
xm# = Minute(xt#)
xs# = Second(xt#)
MsgBox "The current time is: " & xh# & ":" & xm# & ":" & xs#
End Sub
See Also Day (function); Minute (function); Second (function); Month (function); Year
(function); Weekday (function); DatePart (function).
Platform(s) All.
HPage (statement)
Syntax HPage [pages]
Description Scrolls the window with the focus left or right by the specified number of pages.
Comments The pages parameter is an Integer specifying the number of pages to scroll. If this
parameter is omitted, then the window is scrolled right by one page.
Example 'This example scrolls the Notepad window to the left by three
'"amounts." Each "amount" is equivalent to clicking within the
'horizontal scroll bar on the right side of the thumb mark.
Sub Main()
AppActivate "Notepad"
HPage 3 'Move 3 pages down.
End Sub
HScroll (statement)
Syntax HScroll percentage
Description Sets the thumb mark on the horizontal scroll bar attached to the current window.
Comments The position is given as a percentage of the total range associated with that scroll bar.
For example, if the percentage parameter is 50, then the thumb mark is positioned in the
middle of the scroll bar.
Example 'This example centers the thumb mark on the horizontal scroll
'bar of the Notepad window.
Sub Main()
AppActivate "Notepad"
HScroll 50 'Jump to the middle of the document.
End Sub
See Also HLine (statement); HPage (statement).
Platform(s) Windows, Win32.
HWND (object)
Syntax Dim name As HWND
Comments This data type is used to hold references to physical windows in the operating
environment. The following commands operate on HWND objects:
WinActivate WinClose WinFind WinList
WinSize
The above language elements support both string and HWND window specifications.
Example 'This example activates the "Main" MDI window within Program
'Manager.
Sub Main()
Dim ProgramManager As HWND
Dim ProgramManagerMain As HWND
Set ProgramManager = WinFind("Program Manager")
If ProgramManager Is Not Nothing Then
WinActivate ProgramManager
WinMaximize ProgramManager
Set ProgramManagerMain = WinFind("Program Manager|Main")
If ProgramManagerMain Is Not Nothing Then
WinActivate ProgramManagerMain
WinRestore ProgramManagerMain
Else
MsgBox "Your Program Manager doesn't have a Main group."
End If
Else
MsgBox "Program Manager is not running."
End If
End Sub
[Link] (property)
Syntax [Link]
Description The default property of an HWND object that returns a Variant containing a HANDLE
to the physical window of an HWND object variable.
Comments The Value property is used to retrieve the operating environment–specific value of a
given HWND object. The size of this value depends on the operating environment in
which the script is executing and thus should always be placed into a Variant variable.
This property is read-only.
Example 'This example displays a dialog box containing the class name of
'Program Manager's Main window. It does so using the .Value
'property, passing it directly to a Windows external routine.
Declare Sub GetClassName Lib "user" (ByVal Win%,ByVal
ClsName$,ByVal ClsNameLen%)
Sub Main()
Dim ProgramManager As HWND
Set ProgramManager = WinFind("Program Manager")
ClassName$ = Space(40)
GetClassName [Link],ClassName$,Len(ClassName$)
MsgBox "The program classname is: " & ClassName$
End Sub
See Also HWND (object).
Platform(s) Windows, Win32.
Platform Notes Under Windows, this value is an Integer. Under Win32, this value is a Long.
If...Then...Else (statement)
Syntax 1 If condition Then statements [Else else_statements]
Parameter Description
statements One or more statements to be executed when condition is
True.
else_condition Any expression evaluating to a Boolean value. The
else_condition is evaluated if condition is False.
elseif_statements One or more statements to be executed when condition is
False and else_condition is True.
else_statments One or more statements to be executed when both
condition and else_condition are False.
There can be as many ElseIf conditions as required.
Example 'This example inputs a name from the user and checks to see
'whether it is MICHAEL or MIKE using three forms of the
'If...Then...Else statement. It then branches to a statement
'that displays a welcome message depending on the user's name.
Sub Main()
uname$ = UCase$(InputBox$("Enter your name:","Enter Name"))
If uname$ = "MICHAEL" Then GoSub MikeName
If uname$ = "MIKE" Then
GoSub MikeName
Exit Sub
End If
If uname$ = "" Then
MsgBox "Since you don't have a name, I'll call you MIKE!"
uname$ = "MIKE"
GoSub MikeName
ElseIf uname$ = "MICHAEL" Then
GoSub MikeName
Else
GoSub OtherName
End If
Exit Sub
MikeName:
MsgBox "Hello, MICHAEL!"
Return
OtherName:
MsgBox "Hello, " & uname$ & "!"
Return
End Sub
See Also Choose (function); Switch (function); IIf (function); Select...Case (statement).
Platform(s) All.
IIf (function)
Syntax IIf(expression, truepart, falsepart)
IMEStatus (function)
Syntax IMEStatus[()]
Note: You can test for the different bits using the And operator as follows:
a = IMEStatus()
If a And 1 Then ... 'Test for bit 0
If a And 2 Then ... 'Test for bit 1
If a And 4 Then ... 'Test for bit 2
If a And 8 Then ... 'Test for bit 3
If a And 16 Then ... ’Test for bit 4
Imp (operator)
Syntax result = expression1 Imp expression2
Description Performs a logical or binary implication on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or Null variants, then a logical
implication is performed as follows:
If expression1 is and expression2 is then the result is
Binary Implication
If the two expressions are Integer, then a binary implication is performed, returning an
Integer result. All other numeric types (including Empty variants) are converted to
Long and a binary implication is then performed, returning a Long result.
Binary implication forms a new value based on a bit-by-bit comparison of the binary
representations of the two expressions, according to the following table:
If bit in expression1 is and bit in expression2 is the result is
1 1 1
0 1 1
1 0 0
0 0 1
Example 'This example compares the result of two expressions to
'determine whether one implies the other.
Sub Main()
a = 10 : b = 20 : c = 30 : d = 40
If (a < b) Imp (c < d) Then
MsgBox "a less than b implies that c is less than d."
Else
MsgBox "a less than b does not imply that c is less than d."
End If
If (a < b) Imp (c > d) Then
MsgBox "a less than b implies that c is greater than d."
Else
MsgBox "a less than b does not imply that c greater than d."
End If
End Sub
See Also Operator Precedence (topic); Or (operator); Xor (operator); Eqv (operator); And
(operator).
Platform(s) All.
Inline (statement)
Syntax Inline name [parameters]
anytext
End Inline
Description Allows execution or interpretation of a block of text.
Comments The Inline statement takes the following parameters:
Parameter Description
name Identifier specifying the type of inline statement
parameters Comma-separated list of parameters.
anytext Text to be executed by the Inline statement. This text must
be in a format appropriate for execution by the Inline
statement.
The end of the text is assumed to be the first occurrence of
the words End Inline appearing on a line.
Example Sub Main()
Inline MacScript
-- AppleScript comment.
Beep
Display Dialog "AppleScript" buttons "OK"
End Inline
End Sub
Input# (statement)
Syntax Input [#]filenumber%,variable[,variable]...
Description Reads data from the file referenced by filenumber into the given variables.
Comments Each variable must be type-matched to the data in the file. For example, a String
variable must be matched to a string in the file.
The following parsing rules are observed while reading each variable in the variable list:
1. Leading white space is ignored (spaces and tabs).
2. When reading String variables, if the first character on the line is a quotation mark,
then characters are read up to the next quotation mark or the end of the line,
whichever comes first. Blank lines are read as empty strings. If the first character
read is not a quotation mark, then characters are read up to the first comma or the
end of the line, whichever comes first. String delimiters (quotes, comma,
end-of-line) are not included in the returned string. Spaces are trimmed from the
end of unquoted strings.
3. When reading numeric variables, scanning of the number stops when the first
non-numeric character (such as a comma, a letter, or any other unexpected
character) is encountered. Numeric errors are ignored while reading numbers from
a file. The resultant number is automatically converted to the same type as the
variable into which the value will be placed. If there is an error in conversion, then
0 is stored into the variable.
After reading the number, input is skipped up to the next delimiter—a comma, an
end-of-line, or an end-of-file.
Numbers must adhere to any of the following syntaxes:
[-|+]digits[.digits][E[-|+]digits][!|#|%|&|@]
&Hhexdigits[!|#|%|&]
&[O]octaldigits[!|#|%|&|@]
4. When reading Boolean variables, the first character must be #; otherwise, a runtime
error occurs. If the first character is #, then input is scanned up to the next delimiter
(a comma, an end-of-line, or an end-of-file). If the input matches #FALSE#, then
False is stored in the Boolean; otherwise, True is stored.
5. When reading Date variables, the first character must be #; otherwise, a runtime
error occurs. If the first character is #, then the input is scanned up to the next
delimiter (a comma, an end-of-line, or an end-of-file). If the input ends in a # and
the text between the #'s can be correctly interpreted as a date, then the date is
stored; otherwise, December 31, 1899, is stored.
Normally, dates that follow the universal date format are input from sequential files.
These dates use this syntax:
#YYYY-MM-DD HH:MM:SS#
where YYYY is a year between 100 and 9999, MM is a month between 1 and 12, DD
is a day between 1 and 31, HH is an hour between 0 and 23, MM is a minute
between 0 and 59, and SS is a second between 0 and 59.
6. When reading Variant variables, if the data begins with a quotation mark, then a
string is read consisting of the characters between the opening quotation mark and
the closing quotation mark, end-of-line, or end-of-file.
If the input does not begin with a quotation mark, then input is scanned up to the
next comma, end-of-line, or end-of-file and a determination is made as to what data
is being represented. If the data cannot be represented as a number, Date, Error,
Boolean, or Null, then it is read as a string.
The following table describes how special data is interpreted as variants:
Blank line Read as an Empty variant.
#NULL# Read as a Null variant.
TRUE# Read as a Boolean variant.
#FALSE# Read as a Boolean variant.
ERROR code# Read as a user-defined error.
date# Read as a Date variant.
"text" Read as a String variant.
7. If an error occurs in interpretation of the data as a particular type, then that data is
read as a String variant.
8. When reading numbers into variants, the optional type-declaration character
determines the VarType of the resulting variant. If no type-declaration character is
specified, then BasicScript will read the number according to the following rules:
• Rule 1: If the number contains a decimal point or an exponent, then the number is
read as Currency. If there is an error converting to Currency, then the number is
treated as a Double.
• Rule 2: If the number does not contain a decimal point or an exponent, then the
number is stored in the smallest of the following data types that most accurately
represents that value: Integer, Long, Currency, Double.
9. End-of-line is interpreted as either a single line feed, a single carriage return, or a
carriage-return/line-feed pair. Thus, text files from any platform can be interpreted
using this command.
The filenumber parameter is a number that is used by BasicScript to refer to the
open filethe number passed to the Open statement.
The filenumber must reference a file opened in Input mode. It is good practice to
use the Write statement to write date elements to files read with the Input
statement to ensure that the variable list is consistent between the input and output
routines.
10. Null characters are ignored.
Example 'This example creates a file called [Link] and writes a series
'of variables into it. Then the variables are read using the
'Input# function.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Open "[Link]" For Output As #1
Write #1,2112,"David","McCue","123-45-6789"
Close
Open "[Link]" For Input As #1
Input #1,x%,st1$,st2$,st3$
message = "Employee " & x% & " Information" & crlf & crlf
message = message & "First Name: " & st1$ & crlf
message = message & "Last Name: "& st2$ & crlf
message = message & "Social Security Number: " & sy3$
MsgBox message
Close
Kill "[Link]"
End Sub
See Also Open (statement); Get (statement); Line Input# (statement); Input, Input$, InputB,
InputB$ (functions).
Platform(s) All.
Parameter Description
See Also Open (statement); Get (statement); Input# (statement); Line Input# (statement).
Platform(s) All.
Description Displays a dialog box with a text box into which the user can type.
Comments The content of the text box is returned as a String (in the case of InputBox$) or as a
String variant (in the case of InputBox). A zero-length string is returned if the user
selects Cancel.
Description Returns the first character position of string find within string search.
Comments The InStr function takes the following parameters:
Parameter Description
start Integer specifying the character position (for Instr) or byte
position (for InstrB) where searching begins. The start
parameter must be between 1 and 32767.
If this parameter is omitted, then the search starts at the
beginning (start = 1).
search Text to search. This can be any expression convertible to a
String.
find Text for which to search. This can be any expression
convertible to a String.
compare Integer controlling how string comparisons are performed.
It can be any of the following values:
0 String comparisons are case-sensitive.
1 String comparisons are case-insensitive.
Any other value produces a runtime error.
If this parameter is omitted, then string comparisons use
the current Option Compare setting. If no Option
Compare statement has been encountered, then Binary is
used (i.e., string comparisons are case-sensitive).
If the string is found, then its character position within search is returned, with 1 being
the character position of the first character.
The InStr and InStrB functions observe the following additional rules:
• If either search or find is Null, then Null is returned.
• If the compare parameter is specified, then start must also be specified. In other
words, if there are three parameters, then it is assumed that these parameters
correspond to start, search, and find.
• A runtime error is generated if start is Null.
• A runtime error is generated if compare is not 0 or 1.
• If search is Empty, then 0 is returned.
• If find is Empty, then start is returned. If start is greater than the length of search,
then 0 is returned.
• A runtime error is generated if start is less than or equal to zero.
The InStr and InStrB functions operate on character and byte data respectively. The
Instr function interprets the start parameter as a character, performs a textual
comparisons, and returns a character position. The InStrB function, on the other hand,
interprets the start parameter as a byte position, performs binary comparisons, and
returns a byte position.
On SBCS platforms, the InStr and InStrB functions are identical.
Example 'This example checks to see whether one string is in another
'and, if it is, then it copies the string to a variable and
'displays the result.
Sub Main()
a$ = "This string contains the name Stuart."
x% = InStr(a$,"Stuart",1)
If x% <> 0 Then
b$ = Mid$(a$,x%,6)
MsgBox b$ & " was found."
Exit Sub
Else
MsgBox "Stuart not found."
End If
End Sub
See Also Mid, Mid$, MidB, MidB$ (functions); Option Compare (statement); Item$
(function); Word$ (function); Line$ (function).
Platform(s) All.
Int (function)
Syntax Int(number)
Sub Main()
a# = -1234.5224
b% = Int(a#)
MsgBox "The integer part of -1234.5224 is: " & b%
End Sub
Description A data type used to declare whole numbers with up to four digits of precision.
Comments Integer variables are used to hold numbers within the following range:
–32768 <= integer <= 32767
Internally, integers are 2-byte short values. Thus, when appearing within a structure,
integers require 2 bytes of storage. When used with binary or random files, 2 bytes of
storage are required.
When passed to external routines, Integer values are sign-extended to the size of an
integer on that platform (either 16 or 32 bits) before pushing onto the stack.
The type-declaration character for Integer is %.
See Also Currency (data type); Date (data type); Double (data type); Long (data type); Object
(data type); Single (data type); String (data type); Variant (data type); Boolean (data
type); DefType (statement); CInt (function).
Platform(s) All.
IPmt (function)
Syntax IPmt(rate, per, nper, pv, fv, due)
Description Returns the interest payment for a given period of an annuity based on periodic, fixed
payments and a fixed interest rate.
Comments An annuity is a series of fixed payments made to an insurance company or other
investment company over a period of time. Examples of annuities are mortgages,
monthly savings plans, and retirement plans.
See Also NPer (function); Pmt (function); PPmt (function); Rate (function).
Platform(s) All.
IRR (function)
Syntax IRR(valuearray(),guess)
Description Returns the internal rate of return for a series of periodic payments and receipts.
Comments The internal rate of return is the equivalent rate of interest for an investment consisting
of a series of positive and/or negative cash flows over a period of regular intervals. It is
usually used to project the rate of return on a business investment that requires a capital
investment up front and a series of investments and returns on investment over time.
The IRR function requires the following named parameters:
Named Parameter Description
valuearray() Array of Double numbers that represent payments and
receipts. Positive values are payments, and negative values
are receipts.
There must be at least one positive and one negative value
to indicate the initial investment (negative value) and the
amount earned by the investment (positive value).
guess Double containing your guess as to the value that the IRR
function will return. The most common guess is .1 (10
percent).
The value of IRR is found by iteration. It starts with the value of guess and cycles
through the calculation adjusting guess until the result is accurate within 0.00001
percent. After 20 tries, if a result cannot be found, IRR fails, and the user must pick a
better guess.
Example 'This example illustrates the purchase of a lemonade stand for
'$800 and a series of incomes from the sale of lemonade over 12
'months. The projected incomes for this example are generated
'in two For...Next Loops, and then the internal rate of return
Is (operator)
Syntax object Is [object | Nothing]
Description Returns True if the two operands refer to the same object; returns False otherwise.
Comments This operator is used to determine whether two object variables refer to the same object.
Both operands must be object variables of the same type (i.e., the same data object type
or both of type Object).
The Nothing constant can be used to determine whether an object variable is
uninitialized:
If MyObject Is Nothing Then MsgBox "MyObject is
uninitialized."
Uninitialized object variables reference no object.
Example 'This function inserts the date into a Microsoft Word document.
Sub InsertDate(ByVal WinWord As Object)
If WinWord Is Nothing Then
MsgBox "Object variant is not set."
Else
[Link] Date$
End If
End Sub
Sub Main()
Dim WinWord As Object
On Error Resume Next
WinWord = CreateObject("[Link]")
InsertDate WinWord
End Sub
IsDate (function)
Syntax IsDate(expression)
Description Returns True if expression can be legally converted to a date; returns False otherwise.
Example Sub Main()
Dim a As Variant
Retry:
a = InputBox("Enter a date.", "Enter Date")
If IsDate(a) Then
IsEmpty (function)
Syntax IsEmpty(expression)
Description Returns True if expression is a Variant variable that has never been initialized; returns
False otherwise.
Comments The IsEmpty function is the same as the following:
(VarType(expression) = ebEmpty)
Example Sub Main()
Dim a As Variant
If IsEmpty(a) Then
a = 1.0# 'Give uninitialized data a Double value 0.0.
MsgBox "The variable has been initialized to: " & a
Else
MsgBox "The variable was already initialized!"
End If
End Sub
See Also Variant (data type); IsDate (function); IsError (function); IsObject (function);
VarType (function); IsNull (function).
Platform(s) All.
IsError (function)
Syntax IsError(expression)
Description Returns True if expression is a user-defined error value; returns False otherwise.
Example 'This example creates a function that divides two numbers. If
'there is an error dividing the numbers, then a variant of type
'"error" is returned. Otherwise, the function returns the result
'of the division. The IsError function is used to determine
See Also Variant (data type); IsEmpty (function); IsDate (function); IsObject (function);
VarType (function); IsNull (function).
Platform(s) All.
IsMissing (function)
Syntax IsMissing(argname)
Description Returns True if argname was passed to the current subroutine or function; returns False
if omitted.
Comments The IsMissing function is used with variant variables passed as optional parameters
(using the Optional keyword) to the current subroutine or function. For nonvariant
variables or variables that were not declared with the Optional keyword, IsMissing will
always return True.
Example 'The following function runs an application and optionally
'minimizes it. If the optional isMinimize parameter is not
'specified by the caller, then the application is not minimized.
Sub Test(AppName As String,Optional isMinimize As Variant)
app = Shell(AppName)
If Not IsMissing(isMinimize) Then
AppMinimize app
Else
AppMaximize app
End If
End Sub
Sub Main
Test "Notepad"'Maximize this application
IsNull (function)
Syntax IsNull(expression)
Description Returns True if expression is a Variant variable that contains no valid data; returns
False otherwise.
Comments The IsNull function is the same as the following:
(VarType(expression) = ebNull)
IsNumeric (function)
Syntax IsNumeric(expression)
Description Returns True if expression can be converted to a number; returns False otherwise.
Comments If passed a number or a variant containing a number, then IsNumeric always returns
True.
If a String or String variant is passed, then IsNumeric will return True only if the
string can be converted to a number. The following syntaxes are recognized as valid
numbers:
&Hhexdigits[&|%|!|#|@]
&[O]octaldigits[&|%|!|#|@]
[-|+]digits[.[digits]][E[-|+]digits][!|%|&|#|@]
If an Object variant is passed, then the default property of that object is retrieved and
one of the above rules is applied.
IsNumeric returns False if expression is a Date.
Example Sub Main()
Dim s$ As String
s$ = InputBox("Enter a number.","Enter Number")
If IsNumeric(s$) Then
MsgBox "You did good!"
Else
MsgBox "You didn't do so good!"
End If
End Sub
See Also Variant (data type); IsEmpty (function); IsDate (function); IsError (function);
IsObject (function); VarType (function); IsNull (function).
Platform(s) All.
IsObject (function)
Syntax IsObject(expression)
Description Returns True if expression is a Variant variable containing an Object; returns False
otherwise.
Example 'This example will attempt to find a running copy of Excel and
'create an Excel object that can be referenced as any other
'object in BasicScript.
Sub Main()
Dim v As Variant
On Error Resume Next
Set v = GetObject(,"[Link]")
If IsObject(v) Then
MsgBox"The default object value is: " & v = [Link]'Access
value property of the object.
Else
MsgBox "Excel not loaded."
End If
End Sub
See Also Variant (data type); IsEmpty (function); IsDate (function); IsError (function);
VarType (function); IsNull (function).
Platform(s) All.
Item$ (function)
Syntax Item$(text$,first [,[last] [,delimiters$]])
Description Returns all the items between first and last within the specified formatted text list.
Comments The Item$ function takes the following parameters:
Parameter Description
text$ String containing the text from which a range of items is
returned.
first Integer containing the index of the first item to be
returned. If first is greater than the number of items in
text$, then a zero-length string is returned.
last Integer containing the index of the last item to be returned.
All of the items between first and last are returned. If last is
greater than the number of items in text$, then all items
from first to the end of text are returned.
If last is missing, then only the item specified by first is
returned. An "Invalid use of Null" error is returned if this
parameter is Null.
delimiters$ String containing different item delimiters.
By default, items are separated by commas and
end-of-lines. This can be changed by specifying different
delimiters in the delimiters$ parameter.
The Item$ function treats embedded null characters as regular characters.
An empty string is returned if first is less than 1. If last is less than first, the values are
swapped.
Example 'This example creates two delimited lists and extracts a range
'from each, then displays the result in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
ilist$ = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
slist$ = "1/2/3/4/5/6/7/8/9/10/11/12/13/14/15"
list1$ = Item$(ilist$,5,12)
list2$ = Item$(slist$,2,9,"/")
MsgBox "The returned lists are: " & crlf & list1$ & crlf &
list2$
End Sub
See Also ItemCount (function); Line$ (function); LineCount (function); Word$ (function);
WordCount (function).
Platform(s) All.
ItemCount (function)
Syntax ItemCount(text$ [,delimiters$])
Description Returns an Integer containing the number of items in the specified delimited text.
Comments Items are substrings of a delimited text string. Items, by default, are separated by
commas and/or end-of-lines. This can be changed by specifying different delimiters in
the delimiters$ parameter. For example, to parse items using a backslash:
n = ItemCount(text$,"\")
The ItemCount function treats embedded null characters as regular characters.
Example 'This example creates two delimited lists and then counts the
'number of items in each. The counts are displayed in a dialog
'box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
ilist$ = "1,2,3,4,5,6,7,8,9,10,11,12,13,14,15"
slist$ = "1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/17/18/19"
l1% = ItemCount(ilist$)
l2% = ItemCount(slist$,"/")
message = "The first lists contains: " & l1% & " items." & crlf
message = message & "The second list contains: " _
& l2% & " items."
MsgBox message
End Sub
See Also Item$ (function); Line$ (function); LineCount (function); Word$ (function);
WordCount (function).
Platform(s) All.
Keywords (topic)
A keyword is any word or symbol recognized by BasicScript as part of the language. All
of the following are keywords:
Access Alias And Any
Xor
Restrictions
All keywords are reserved by BasicScript, in that you cannot create a variable, function,
constant, or subroutine with the same name as a keyword. However, you are free to use
all keywords as the names of structure members.
For all other keywords in BasicScript (such as MsgBox, Str, and so on), the following
restrictions apply:
• You can create a subroutine or function with the same name as a keyword.
• You can create a variable with the same name as a keyword as long as the variable
is first explicitly declared with a Dim, Private, or Public statement.
Platform(s) All.
Kill (statement)
Syntax Kill pathname
Kill pathname [,filetype]
Kill filetype
Description Deletes all files matching pathname.
Close
End If
If FileExists ("[Link]") Then
MsgBox "File [Link] exists."
Kill "test?.dat"
End If
If FileExists ("[Link]") Then
MsgBox "File [Link] still exists."
Else
MsgBox "test?.dat sucessfully deleted."
End If
End Sub
LBound (function)
Syntax LBound(ArrayVariable() [,dimension])
Description Returns an Integer containing the lower bound of the specified dimension of the
specified array variable.
Comments The dimension parameter is an integer specifying the desired dimension. If this
parameter is not specified, then the lower bound of the first dimension is returned.
The LBound function can be used to find the lower bound of a dimension of an array
returned by an OLE Automation method or property:
LBound([Link] [,dimension])
LBound([Link] [,dimension])
Examples Sub Main()
'This example dimensions two arrays and displays their lower
'bounds.
Description Returns the leftmost length characters (for Left and Left$) or bytes (for LeftB and
LeftB$) from a given string.
Comments Left$ returns a String, whereas Left returns a String variant.
The length parameter is an Integer value specifying the number of characters to return.
If length is 0, then a zero-length string is returned. If length is greater than or equal to
the number of characters in the specified string, then the entire string is returned.
The LeftB and LeftB$ functions are used to return a sequence of bytes from a string
containing byte data. In this case, length specifies the number of bytes to return. If
length is greater than the number of bytes in string, then the entire string is returned.
Null is returned if string is Null.
Example 'This example shows the Left$ function used to change uppercase
'names to lowercase with an uppercase first letter.
Sub Main()
lname$ = "WILLIAMS"
fl$ = Left$(lname$,1)
rest$ = Mid$(lname$,2,Len(lname$))
lname$ = fl$ & LCase$(rest$)
MsgBox "The converted name is: " & lname$
End Sub
See Also Right, Right$, RightB, RightB$ (functions).
Platform(s) All.
Description Returns the number of characters (for Len) or bytes (for LenB) in String expression or
the number of bytes required to store the specified variable.
Comments If expression evaluates to a String, then Len returns the number of characters in a given
string or 0 if the string is empty. When used with a Variant variable, the length of the
variant when converted to a String is returned. If expression is a Null, then Len returns
a Null variant.
The LenB function is used to return the number of bytes in a given string. On SBCS
systems, the LenB and Len functions are identical.
If used with a non-String or non-Variant variable, these functions returns the number
of bytes occupied by that data element.
When used with user-defined data types, these functions return the combined size of
each member within the structure. Since variable-length strings are stored elsewhere,
the size of each variable-length string within a structure is 2 bytes.
The following table describes the sizes of the individual data elements when appearing
within a structure:
Data Element Size
Integer 2 bytes.
Long 4 bytes.
Float 4 bytes.
Double 8 bytes.
Currency 8 bytes.
String (variable-length) 2 bytes
String (fixed-length) The length of the string as it appears in the string's
declaration in characters for Len and bytes for LenB.
Objects 0 bytes. Both data object variables and variables of
type Object are always returned as 0 size.
User-defined type Combined size of each structure member.
Variable-length strings within structures require 2
bytes of storage.
Arrays within structures are fixed in their dimensions.
The elements for fixed arrays are stored within the
structure and therefore require the number of bytes for
each array element multiplied by the size of each array
dimension:
element_size*dimension1*dimension2...
The Len and LenB functions always returns 0 with object variables or any data object
variable.
Examples Const crlf = Chr$(13) + Chr$(10)
Sub Main()
'This example shows the Len function used in a routine to
'change uppercase names to lowercase with an uppercase first
'letter.
lname$ = "WILLIAMS"
fl$ = Left$(lname$,1)
ln% = Len(lname$)
rest$ = Mid$(lname$,2,ln%)
Let (statement)
Syntax [Let] variable = expression
End Sub
See Also = (operator); Expression Evaluation (topic).
Platform(s) All.
Like (operator)
Syntax expression Like pattern
Description Compares two strings and returns True if the expression matches the given pattern;
returns False otherwise.
Comments Case sensitivity is controlled by the Option Compare setting.
The pattern expression can contain special characters that allow more flexible matching:
Character Evaluates To
? Matches a single character.
* Matches one or more characters.
# Matches any digit.
[range] Matches if the character in question is within the specified
range.
[!range] Matches if the character in question is not within the specified
range.
A range specifies a grouping of characters. To specify a match of any of a group of
characters, use the syntax [ABCDE]. To specify a range of characters, use the syntax
[A-Z]. Special characters must appear within brackets, such as []*?#.
If expression or pattern is not a string, then both expression and pattern are converted to
String variants and compared, returning a Boolean variant. If either variant is Null, then
Null is returned.
The following table shows some examples:
expression True If pattern Is False If pattern Is
See Also Open (statement); Get (statement); Input# (statement); Input, Input$, InputB,
InputB$ (functions).
Platform(s) All.
Line$ (function)
Syntax Line$(text$,first[,last])
Description Returns a String containing a single line or a group of lines between first and last.
Comments Lines are delimited by carriage return, line feed, or carriage-return/line-feed pairs.
Embedded null characters are treated as regular characters.
The Line$ function takes the following parameters:
Parameter Description
text$ String containing the text from which the lines will be
extracted.
first Integer representing the index of the first line to return. If last
is omitted, then this line will be returned. If first is greater
than the number of lines in text$, then a zero-length string is
returned.
last Integer representing the index of the last line to return
Example 'This example reads five lines of the [Link] file,
'extracts the third and fourth lines with the Line$ function,
'and displays them in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Open "c:\[Link]" For Input As #1
For x = 1 To 5
Line Input #1,lin$
txt = txt & lin$ & crlf
Next x
lines$ = Line$(txt,3,4)
MsgBox lines$
End Sub
See Also Item$ (function); ItemCount (function); LineCount (function); Word$ (function);
WordCount (function).
Platform(s) All.
LineCount (function)
Syntax LineCount(text$)
See Also Item$ (function); ItemCount (function); Line$ (function); Word$ (function);
WordCount (function).
Platform(s) All.
ListBox (statement)
Syntax ListBox x,y,width,height,ArrayVariable,.Identifier
ListBox 76,16,56,72,dirs$,.Dirs
OKButton 140,4,40,14
CancelButton 140,24,40,14
End Dialog
FileList files
FileDirs dirs
Dim ListBoxDialog As ListBoxTemplate
rc% = Dialog(ListBoxDialog)
End Sub
ListBoxEnabled (function)
Syntax ListBoxEnabled(name$ | id)
Description Returns True if the given list box is enabled within the active window or dialog box;
returns False otherwise.
Comments This function is used to determine whether a list box is enabled within the current
window or dialog box. If there is no active window, False will be returned.
The ListBoxEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the list box.
The name of a list box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a list box. A runtime error is
generated if a list box with that name cannot be found within
the active window.
id Integer specifying the ID of the list box.
Example 'This example checks to see whether the list box is enabled
'before setting the focus to it.
Sub Main()
ListBoxExists (function)
Syntax ListBoxExists(name$ | id)
Description Returns True if the given list box exists within the active window or dialog box; returns
False otherwise.
Comments This function is used to determine whether a list box exists within the current window or
dialog box. If there is no active window, False will be returned.
The ListBoxExists function takes the following parameters:
Parameter Description
name$ String containing the name of the list box.
The name of a list box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a list box. A runtime error is
generated if a list box with that name cannot be found within
the active window.
id Integer specifying the ID of the list box.
Note: The ListBoxExists function is used to determine whether a list box exists in
another application's dialog box. There is no equivalent function for use with
dynamic dialog boxes.
Example 'This example checks to see whether the list box exists and is
'enabled before setting the focus to it.
Sub Main()
If ListBoxExists("Files:") Then
If ListBoxEnabled("Files:") Then
ActivateControl "Files:"
End If
End If
End Sub
See Also GetListBoxItem$ (function); GetListBoxItemCount (function); ListBoxEnabled
(function); SelectListBoxItem (statement).
Platform(s) Windows.
Literals (topic)
Literals are values of a specific type. The following table shows the different types of
literals supported by BasicScript:
Literal Description
10 Integer whose value is 10.
43265 Long whose value is 43,265.
5# Double whose value is 5.0. A number's type can be explicitly
set using any of the following type-declaration characters:
% Integer
& Long
# Double
! Single
5.5 Double whose value is 5.5. Any number with decimal point is
considered a double.
5.4E100 Double expressed in scientific notation.
&HFF Integer expressed in hexadecimal.
&O47 Integer expressed in octal.
&HFF# Double expressed in hexadecimal.
"hello" String of five characters: hello.
"""hello""" String of seven characters: "hello". Quotation marks can be
embedded within strings by using two consecutive quotation
marks.
#1/1/1994# Date value whose internal representation is 34335.0. Any valid
date can appear with #'s. Date literals are interpreted at
execution time using the locale settings of the host environment.
To ensure that date literals are correctly interpreted for all
locales, use the international date format:
YYYY-MM-DD HH:MM:SS#
Constant Folding
BasicScript supports constant folding where constant expressions are calculated by the
compiler at compile time. For example, the expression
i% = 10 + 12
Loc (function)
Syntax Loc(filenumber)
Description Returns a Long representing the position of the file pointer in the given file.
Comments The filenumber parameter is an Integer used by BasicScript to refer to the number
passed by the Open statement to BasicScript.
The Loc function returns different values depending on the mode in which the file was
opened:
File Mode Returns
Description Locks or unlocks a section of the specified file, granting or denying other processes
access to that section of the file.
Comments The Lock statement locks a section of the specified file, preventing other processes from
accessing that section of the file until the Unlock statement is issued. The Unlock
statement unlocks a section of the specified file, allowing other processes access to that
section of the file.
The Lock and Unlock statements require the following parameters:
Parameter Description
filenumber Integer used by BasicScript to refer to the open file—the
number passed to the Open statement.
record Long specifying which record to lock or unlock.
start Long specifying the first record within a range to be locked or
unlocked.
end Long specifying the last record within a range to be locked or
unlocked.
For sequential files, the record, start, and end parameters are ignored. The entire file is
locked or unlocked.
The section of the file is specified using one of the following:
Syntax Description
No parameters Locks or unlocks the entire file (no record specification is
given).
record Locks or unlocks the specified record number (for Random
files) or byte (for Binary files).
To end Locks or unlocks from the beginning of the file to the specified
record (for Random files) or byte (for Binary files).
start To end Locks or unlocks the specified range of records (for Random
files) or bytes (for Binary files).
The lock range must be the same as that used to subsequently unlock the file range, and
all locked ranges must be unlocked before the file is closed. Ranges within files are not
unlocked automatically by BasicScript when your script terminates, which can cause
file access problems for other processes. It is a good idea to group the Lock and Unlock
statements close together in the code, both for readability and so subsequent readers can
see that the lock and unlock are performed on the same range. This practice also reduces
errors in file locks.
Example 'This example creates a file named [Link] and fills it with
'ten string variable records. These are displayed in a dialog
'box. The file is then reopened for read/write, and each record
'is locked, modified, rewritten, and unlocked. The new records
'are then displayed in a dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = "This is record number: "
b$ = "0"
rec$ = ""
message = ""
Open "[Link]" For Random Access Write Shared As #1
For x = 1 To 10
rec$ = a$ & x
Lock #1,x
Put #1,,rec$
Unlock #1,x
message = message & rec$ & crlf
Next x
Close
MsgBox "The records are:" & crlf & message
message = ""
Open "[Link]" For Random Access Read Write Shared As #1
For x = 1 To 10
rec$ = Mid$(rec$,1,23) & (11 - x)
Lock #1,x
Put #1,x,rec$
Unlock #1,x
message = message & rec$ & crlf
Next x
MsgBox "The records are: " & crlf & message
Close
Kill "[Link]"
End Sub
Lof (function)
Syntax Lof(filenumber)
Description Returns a Long representing the number of bytes in the given file.
Comments The filenumber parameter is an Integer used by BasicScript to refer to the open
filethe number passed to the Open statement.
The file must currently be open.
Example 'This example creates a test file, writes ten records into it,
'then finds the length of the file and displays it in a message
'box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = "This is record number: "
Open "[Link]" For Random Access Write Shared As #1
For x = 1 To 10
rec$ = a$ & x
put #1,,rec$
message = message & rec$ & crlf
Next x
Close
Open "[Link]" For Random Access Read Write Shared As #1
r% = Lof(1)
Close
MsgBox "The length of [Link] is: " & r%
End Sub
Log (function)
Syntax Log(number)
End Sub
See Also Exp (function).
Platform(s) All.
Description Long variables are used to hold numbers (with up to ten digits of precision) within the
following range:
–2,147,483,648 <= Long <= 2,147,483,647
Internally, longs are 4-byte values. Thus, when appearing within a structure, longs
require 4 bytes of storage. When used with binary or random files, 4 bytes of storage are
required.
The type-declaration character for Long is &.
See Also Currency (data type); Date (data type); Double (data type); Integer (data type);
Object (data type); Single (data type); String (data type); Variant (data type); Boolean
(data type); DefType (statement); CLng (function).
Platform(s) All.
LSet (statement)
Syntax 1 LSet dest = source
Description Left-aligns the source string in the destination string or copies one user-defined type to
another.
Comments Syntax 1
The LSet statement copies the source string source into the destination string dest. The
dest parameter must be the name of either a String or Variant variable. The source
parameter is any expression convertible to a string.
If source is shorter in length than dest, then the string is left-aligned within dest, and the
remaining characters are padded with spaces. If source$ is longer in length than dest,
then source is truncated, copying only the leftmost number of characters that will fit in
dest.
Syntax 2
The source structure is copied byte for byte into the destination structure. This is useful
for copying structures of different types. Only the number of bytes of the smaller of the
two structures is copied. Neither the source structure nor the destination structure can
contain strings.
Example 'This example replaces a 40-character string of asterisks (*)
'with an RSet and LSet string and then displays the result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim message, tmpstr$
tmpstr$ = String$(40, "*")
message = "Here are two strings that have been right-" + crlf
message = message & "and left-justified in " & _
"a 40-character string."
message = message & crlf & crlf
RSet tmpstr$ = "Right->"
message = message & tmpstr$ & crlf
LSet tmpstr$ = "<-Left"
message = message & tmpstr$ & crlf
MsgBox message
End Sub
MacID (function)
Syntax MacID(constant)
MacScript (statement)
Syntax MacScript script
Main (statement)
Syntax Sub Main()
End Sub
Description Defines the subroutine where execution begins.
Example Sub Main()
MsgBox "This is the Main() subroutine and entry point."
End Sub
Platform(s) All.
Mci (function)
Syntax Mci(command$,result$ [,error$])
Description Executes an Mci command, returning an Integer indicating whether the command was
successful.
Comments The Mci function takes the following parameters:
Parameter Description
End If
rc = Mci("play song","","")'Play in the background.
MsgBox "Press OK to stop the music.",ebOKOnly
rc = Mci("close song","","")
End Sub
Menu (statement)
Syntax Menu MenuItem$
Description Issues the specified menu command from the active window of the active application.
Comments The MenuItem$ parameter specifies the complete menu item name, with each menu
level being separated by a period. For example, the "Open" command on the "File"
menu is represented by "[Link]". Cascading menu items may have multiple periods,
one for each pop-up menu, such as "[Link]". Menu items can also be
specified using numeric index values. For example, to select the third menu item from
the File menu, use "File.#3". To select the fourth item from the third menu, use "#3.#4".
Items from an application's system menu can be selected by beginning the menu item
specification with a period, such as ".Restore" or ".Minimize".
A runtime error will result if the menu item specification does not specify a menu item.
For example, "File" specifies a menu pop-up rather than a menu item, and "[Link]
Blah" is not a valid menu item.
When comparing menu item names, this statement removes periods (.), spaces, and the
ampersand. Furthermore, all characters after a backspace or tab are removed. Thus, the
menu item "&Open...\aCtrl+F12" translates simply to "Open".
A runtime error is generated if the menu item cannot be found or is not enabled at the
time that this statement is encountered.
Examples Sub Main()
Menu "[Link]"
Menu "[Link]"
Menu ".Restore"'Command from system menu
Menu "File.#2"
End Sub
Platform(s) Windows.
MenuItemChecked (function)
Syntax MenuItemChecked(MenuItemName$)
Description Returns True if the given menu item exists and is checked; returns False otherwise.
Comments The MenuItemName$ parameter specifies a complete menu item or menu item pop-up
following the same format as that used by the Menu statement.
Example 'This example turns the ruler off if it is on.
Sub Main()
If MenuItemChecked("[Link]") Then Menu "[Link]"
End Sub
See Also Menu (statement); MenuItemEnabled (function); MenuItemExists (function).
Platform(s) Windows.
MenuItemEnabled (function)
Syntax MenuItemEnabled(MenuItemName$)
Description Returns True if the given menu item exists and is enabled; returns False otherwise.
Comments The MenuItemName$ parameter specifies a complete menu item or menu item pop-up
following the same format as that used by the Menu statement.
Example 'This example only pastes if there is something in the Clipboard.
Sub Main()
If MenuItemEnabled("[Link]") Then
Menu "[Link]"
Else
MsgBox "There is nothing in the Clipboard.",ebOKOnly
End If
End Sub
See Also Menu (statement); MenuItemChecked (function); MenuItemExists (function).
Platform(s) Windows.
MenuItemExists (function)
Syntax MenuItemExists(MenuItemName$)
Description Returns True if the given menu item exists; returns False otherwise.
Comments The MenuItemName$ parameter specifies a complete menu item or menu item pop-up
following the same format as that used by the Menu statement.
Examples Sub Main()
If MenuItemExists("[Link]") Then Beep
If MenuItemExists("File") Then MsgBox "There is a File menu."
End Sub
Description Returns a substring of the specified string, beginning with start, for length characters
(for Mid and Mid$) or bytes (for MidB and MidB$).
Comments The Mid and Mid$ functions return a substring starting at character position start and
will be length characters long. The MidB and MidB functions return a substring
starting at byte position start and will be length bytes long.
The Mid$ and MidB$ functions return a String, whereas the Mid and MidB functions
return a String variant.
These functions take the following named parameters:
Named Parameter Description
string Any String expression containing the text from which data
are returned.
start Integer specifying the position where the substring begins. If
start is greater than the length of string, then a zero-length
string is returned.
length Integer specifying the number of characters or bytes to
return. If this parameter is omitted, then the entire string is
returned, starting at start.
The Mid function will return Null if string is Null.
The MidB and MidB$ functions are used to return a substring of bytes from a string
containing byte data.
Example 'This example displays a substring from the middle of a string
'variable using the Mid$ function and replaces the first four
Minute (function)
Syntax Minute(time)
Description Returns the minute of the day encoded in the specified time parameter.
Comments The value returned is as an Integer between 0 and 59 inclusive.
The time parameter is any expression that converts to a Date.
Example 'This example takes the current time; extracts the hour, minute,
'and second; and displays them as the current time.
Sub Main()
xt# = TimeValue(Time$())
xh# = Hour(xt#)
xm# = Minute(xt#)
xs# = Second(xt#)
MsgBox "The current time is: " & xh# & ":" & xm# & ":" & xs#
End Sub
See Also Day (function); Second (function); Month (function); Year (function); Hour
(function); Weekday (function); DatePart (function).
Platform(s) All.
MIRR (function)
Syntax MIRR(valuearray(),financerate,reinvestrate)
Description Returns a Double representing the modified internal rate of return for a series of
periodic payments and receipts.
Comments The modified internal rate of return is the equivalent rate of return on an investment in
which payments and receipts are financed at different rates. The interest cost of
investment and the rate of interest received on the returns on investment are both factors
in the calculations.
MkDir (statement)
Syntax MkDir path
See Also ChDir (statement); ChDrive (statement); CurDir, CurDir$ (functions); Dir, Dir$
(functions); RmDir (statement).
Platform(s) All.
Platform Notes Windows: This command behaves the same as the DOS "mkdir" command.
Mod (operator)
Syntax expression1 Mod expression2
Description Returns the remainder of expression1 / expression2 as a whole number.
Comments If both expressions are integers, then the result is an integer. Otherwise, each expression
is converted to a Long before performing the operation, returning a Long.
A runtime error occurs if the result overflows the range of a Long.
If either expression is Null, then Null is returned. Empty is treated as 0.
Example 'This example uses the Mod operator to determine the value of a
'randomly selected card where card 1 is the ace (1) of clubs
'and card 52 is the king (13) of spades. Since the values recur
Month (function)
Syntax Month(date)
Description Returns the month of the date encoded in the specified date parameter.
Comments The value returned is as an Integer between 1 and 12 inclusive.
The date parameter is any expression that converts to a Date.
Example 'This example returns the current month in a dialog box.
Sub Main()
mons$ = "Jan., Feb., Mar., Apr., May, Jun., "
mons$ = "Jul., Aug., Sep., Oct., Nov., Dec."
tdate$ = Date$
tmonth! = Month(DateValue(tdate$))
MsgBox "The current month is: " & Item$(mons$,tmonth!)
End Sub
See Also Day (function); Minute (function); Second (function); Year (function); Hour
(function); Weekday (function); DatePart (function).
Platform(s) All.
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax [Link] prompt,timeout,cancel,thermometer [,XPos,YPos]
Description Displays a message in a dialog box with an optional Cancel button and thermometer.
Comments The [Link] method takes the following named parameters:
Parameter Description
Parameter Description
[Link] (property)
Syntax [Link] [= newtext$]
Description Changes the text within an open message dialog box (one that was previously opened
with the [Link] method).
Comments The message dialog box is not resized to accommodate the new text.
A runtime error will result if a message dialog box is not currently open (using
[Link]).
Example 'This example creates a modeless message box, leaving room in
'the message text for the record number. This box contains a
'Cancel button.
Sub Main()
[Link] "Reading Record",0,True,False
For i = 1 To 100
'Read a record here.
'Update the modeless message box.
Sleep 100
[Link] ="Reading record " & i
Next i
[Link]
End Sub
See Also [Link] (method); [Link] (method); [Link] (property).
Platform(s) Windows, Win32.
[Link] (property)
Syntax [Link] [= percentage]
Description Changes the percentage filled indicated within the thermometer of a message dialog box
(one that was previously opened with the [Link] method).
Comments A runtime error will result if a message box is not currently open (using [Link]) or
if the value of percentage is not between 0 and 100 inclusive.
Example 'This example create a modeless message box with a thermometer
'and a Cancel button. This example also shows how to process the
'clicking of the Cancel button.
Sub Main()
On Error Goto ErrorTrap
[Link] "Reading records from file...",0,True,True
For i = 1 To 100
'Read a record here.
'Update the modeless message box.
[Link] =i
DoEvents
Sleep 50
Next i
[Link]
On Error Goto 0'Turn error trap off.
Exit Sub
ErrorTrap:
MsgBox (function)
Syntax MsgBox(prompt [, [buttons] [,[title] [,helpfile,context]]])
Description Displays a message in a dialog box with a set of predefined buttons, returning an
Integer representing which button was selected.
Comments The MsgBox function takes the following named parameters:
Named Parameter Description
prompt Message to be displayed—any expression convertible to a
String.
End-of-lines can be used to separate lines (either a carriage
return, line feed, or both). If a given line is too long, it will be
word-wrapped. If prompt contains character 0, then only the
characters up to the character 0 will be displayed.
The width and height of the dialog box are sized to hold the
entire contents of prompt.
A runtime error is generated if prompt is Null.
buttons Integer specifying the type of dialog box (see below).
title Caption of the dialog box. This parameter is any expression
convertible to a String. If it is omitted, then "BasicScript" is
used.
A runtime error is generated if title is Null.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also
be specified.
context Number specifying the ID of the topic within helpfile for this
dialog's help. If this parameter is specified, then helpfile must
also be specified.
If both the helpfile and context parameters are specified, then context-sensitive help can
be invoked using the help key (F1 on most platforms). Invoking help does not remove
the dialog.
MsgBox (statement)
Syntax MsgBox prompt [, [buttons] [,[title] [, helpfile, context]]]
Description This command is the same as the MsgBox function, except that the statement form does
not return a value. See MsgBox (function).
Example Sub Main()
MsgBox "This is text displayed in a message box." 'Display
'text.
MsgBox "The result is: " & (10 * 45)'Display a number.
End Sub
See Also AskBox, AskBox$ (functions); AskPassword, AskPassword$ (functions); InputBox,
InputBox$ (functions); OpenFileName$ (function); SaveFileName$ (function);
SelectBox (function); AnswerBox (function).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
Name (statement)
Syntax Name oldfile$ As newfile$
Example ’This example creates a file called [Link] and then renames it
’to [Link].
Sub Main()
On Error Resume Next
If FileExists("[Link]") Then
Name "[Link]" As "[Link]"
If Err <> 0 Then
message = "File exists and cannot be renamed! Error: " _
& Err
Else
message = "File exists and renamed to [Link]."
End If
Else
Open "[Link]" For Output As #1
Close
Name "[Link]" As "[Link]"
If Err <> 0 Then
message = "File created but not renamed! Error: " & Err
Else
message = "File created and renamed to [Link]."
End If
End If
MsgBox message
End Sub
Using named parameter makes your code easier to read, while at the same time removes
you from knowing the order of parameter. With function that require many parameters,
most of which are optional (such as MsgBox), code becomes significantly easier to
write and maintain.
When supported, the names of the named parameter appear in the description of that
language element.
When using named parameter, you must observe the following rules:
• Named parameter must use the parameter name as specified in the description of
that language element. Unrecognized parameter names cause compiler errors.
• All parameters, whether named or positional, are separated by commas.
• The parameter name and its associated value are separated with :=
• If one parameter is named, then all subsequent parameter must also be named as
shown below:
MsgBox "Hello, world", Title:="Title" ’OK
MsgBox Prompt:="Hello, world.",,"Title" ’WRONG!!!
[Link] (method)
Syntax [Link] netpath$,[password$],[localname$] [,[username$]
[,permanent]]
Description Redirects a local device (a disk drive or printer queue) to the specified shared device or
remote server.
Comments The [Link] method takes the following parameters:
Parameter Description
netpath$ String containing the name of the shared device or the name of a
remote server. This parameter can contain the name of a shared
printer queue (such as that returned by [Link][1]) or the
name of a network path (such as that returned by
[Link][0]).
password$ String containing the password for the given device or server.
This parameter is mainly used to specify the password on a
remote server.
If password$ is not specified, then the default password is used.
localname$ String containing the name of the local device being redirected,
such as "LPT1" or "D:".
If localname$ is not specified, then a connection is made to the
network resource without redirecting a local device.
username$ Specifies the name of the user making the connection.
permanent Specifies if the connection should be restored during subsequent
logon operations. Only a successful connection will persist in
this manner.
Connections are assumed to be permanent if this parameter is
omitted. Connections established when localname$ is missing
are never permanent.
A runtime error will result if no network is present.
Example ’This example sets N: so that it refers to the network path
’SYS:\PUBLIC.
Sub Main()
[Link] "SYS:\PUBLIC","","N:"
End Sub
See Also [Link] (method); [Link]$ (method).
Platform(s) Windows, Win32.
Platform Notes Windows: On Windows platforms, the localname$ parameter cannot be omitted. The
username$ and permanent parameters are ignored.
Win32: On Win32 platforms, if username$ is omitted, then the default user for the
current process is used. The permanent parameter is always True under Win32s.
[Link]$ (method)
Syntax [Link]$(type)
Description Calls the currently installed network's browse dialog box, requesting a particular type of
information.
Comments The type parameter is an Integer specifying the type of dialog box to display:
Type Description
0 Displays a dialog box that allows the user to browse network
volumes and directories. Choosing OK returns the completed
pathname as a String.
1 Displays a dialog box that allows the user to browse the network's
printer queues. Choosing OK returns the complete name of that
printer queue as a String. This string is the same format as required
by the [Link] method.
2 Displays the disconnect dialog for disk resources.
3 Displays the disconnect dialog for printer resources.
This dialog box differs depending on the type of network installed.
A runtime error will result if no network is present.
Example ’This example retrieves a valid network path.
Sub Main()
s$ = [Link]$(0)
If s$ <> "" Then
MsgBox "The following network path was selected: " & s$
Else
MsgBox "Dialog box was canceled."
End If
End Sub
Types 1 and 3 are only supported under Windows 95 and Windows NT version 4.0 or
later.
[Link] (method)
Syntax [Link] connection$ [,[isForce] [,isPermanent]]
[Link] (method)
Syntax [Link]
Description Displays the dialog box that allows configuration of the currently installed network.
Comments The displayed dialog box depends on the currently installed network. The dialog box is
modal—script execution will be paused until the dialog box is completed.
A runtime error will result if no network is present.
Example ’This example invokes the network driver dialog box.
Sub Main()
[Link]
End Sub
See Also [Link]$ (method).
Platform(s) Windows.
[Link] (method)
Syntax [Link](type [,localname$])
Description Returns an Integer specifying information about the network and its capabilities.
Comments The [Link] method takes the following parameters:
Parameter Description
[Link]$ (method)
Syntax [Link]$(localname$)
Description Returns the name of the network resource associated with the specified redirected local
device.
Comments The localname$ parameter specifies the name of the local device, such as "LPT1" or
"D:".
The function returns a zero-length string if the specified local device is not redirected.
A runtime error will result if no network is present.
Example ’This example finds out where drive Z is mapped.
Sub Main()
NetPath$ = [Link]$("Z:")
MsgBox "Drive Z is mapped as " & NetPath$
End Sub
[Link]$ (method)
Syntax [Link]$ [([localname$])]
New (keyword)
Syntax 1 Dim ObjectVariable As New ObjectType
Description Creates a new instance of the specified object type, assigning it to the specified object
variable.
Comments The New keyword is used to declare a new instance of the specified data object. This
keyword can only be used with data object types.
At runtime, the application or extension that defines that object type is notified that a
new object is being defined. The application responds by creating a new physical object
(within the appropriate context) and returning a reference to that object, which is
immediately assigned to the variable being declared.
When that variable goes out of scope (i.e., the Sub or Function procedure in which the
variable is declared ends), the application is notified. The application then performs
some appropriate action, such as destroying the physical object.
See Also Dim (statement); Set (statement).
Platform(s) All.
Not (operator)
Syntax Not expression
True False
False True
Null Null
Any numeric type A binary negation of the number. If the number is an
Integer, then an Integer is returned. Otherwise, the
expression is first converted to a Long, then a binary
negation is performed, returning a Long.
Empty Treated as a Long value 0.
Example ’This example demonstrates the use of the Not operator in
’comparing logical expressions and for switching a True/False
’toggle variable.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a = False
b = True
If (Not a and b) Then message = "a = False, b = True" & crlf
toggle% = True
message = message & "toggle% is now " _
& Format(toggle%,"True/False") & crlf
toggle% = Not toggle%
message = message & "toggle% is now " _
& Format(toggle%,"True/False") & crlf
Now (function)
Syntax Now[()]
Description Returns a Date variant representing the current date and time.
Example ’This example shows how the Now function can be used as an
’elapsed-time counter.
Sub Main()
t1# = Now()
MsgBox "Wait a while and click OK."
t2# = Now()
t3# = Second(t2#) - Second(t1#)
MsgBox "Elapsed time was: " & t3# & " seconds."
End Sub
NPer (function)
Syntax NPer(rate, pmt, pv, fv, due)
Description Returns the number of periods for an annuity based on periodic fixed payments and a
constant rate of interest.
Comments An annuity is a series of fixed payments paid to or received from an investment over a
period of time. Examples of annuities are mortgages, retirement plans, monthly savings
plans, and term loans.
The NPer function requires the following named parameters:
Named Parameter Description
rate Double representing the interest rate per period. If the periods
are monthly, be sure to normalize annual rates by dividing them
by 12.
See Also IPmt (function); Pmt (function); PPmt (function); Rate (function).
Platform(s) All.
Npv (function)
Syntax Npv(rate, valuearray())
Description Returns the net present value of an annuity based on periodic payments and receipts,
and a discount rate.
Comments The Npv function requires the following named parameters:
Named Parameter Description
rate Double that represents the interest rate over the length of the
period. If the values are monthly, annual rates must be divided by
12 to normalize them to monthly rates.
Platform(s) All.
Using Objects
Object variables are declared using the Dim, PUBLIC, or Private statement:
Dim MyApp As Object
Object variables can be assigned values (thereby referencing a real physical object)
using the Set statement:
Set MyApp = CreateObject("[Link]")
Set MyApp = Nothing
Properties of an Object are accessed using the dot (.) separator:
[Link] = 10
i% = [Link]
Methods of an Object are also accessed using the dot (.) separator:
[Link] "[Link]"
isSuccess = [Link]("[Link]",15)
Automatic Destruction
BasicScript keeps track of the number of variables that reference a given object so that
the object can be destroyed when there are no longer any references to it:
Sub Main() 'Number of references to object
Dim a As Object '0
Dim b As Object '0
Set a = CreateObject("[Link]) '1
Set b = a '2
Set a = Nothing '1
End Sub '0 (object
'destroyed)
See Also Currency (data type); Date (data type); Double (data type); Integer (data type); Long
(data type); Single (data type); String (data type); Variant (data type); Boolean (data
type); DefType (statement).
Platform(s) Windows, Win32, Macintosh.
Objects (topic)
BasicScript defines two types of objects: data objects and OLE Automation objects.
Syntactically, these are referenced in the same way.
What Is an Object
An object in BasicScript is an encapsulation of data and routines into a single unit. The
use of objects in BasicScript has the effect of grouping together a set of functions and
data items that apply only to a specific object type.
Objects expose data items for programmability called properties. For example, a sheet
object may expose an integer called NumColumns. Usually, properties can be both
retrieved (get) and modified (set).
Objects also expose internal routines for programmability called methods. In
BasicScript, an object method can take the form of a function or a subroutine. For
example, a OLE Automation object called MyApp may contain a method subroutine
called Open that takes a single argument (a filename), as shown below:
[Link] "c:\files\[Link]"
Collections
A collection is a set of related object variables. Each element in the set is called a
member and is accessed via an index, either numeric or text, as shown below:
[Link](0)
[Link]("Tuesday")
It is typical for collection indexes to begin with 0.
Each element of a collection is itself an object, as shown in the following examples:
Dim MyToolbarButton As Object
Set MyToolbarButton = [Link]("Save")
[Link](1).Caption = "Open"
The collection itself contains properties that provide you with information about the
collection and methods that allow navigation within that collection:
Dim MyToolbarButton As Object
NumButtons% = [Link]
[Link]
[Link] "Save"
For i = 1 To [Link]
Set MyToolbarButton = [Link](i)
[Link] = "Copy"
Next i
Predefined Objects
BasicScript predefines a few objects for use in all scripts. These are:
Clipboard System Desktop HWND
Description Returns a String containing the octal equivalent of the specified number.
OKButton (statement)
Syntax OKButton x,y,width,height [,.Identifier]
On Error (statement)
Syntax On Error {Goto label | Resume Next | Goto 0}
Description Defines the action taken when a trappable runtime error occurs.
Comments The form On Error Goto label causes execution to transfer to the specified label when
a runtime error occurs.
The form On Error Resume Next causes execution to continue on the line following
the line that caused the error.
The form On Error Goto 0 causes any existing error trap to be removed.
If an error trap is in effect when the script ends, then an error will be generated.
An error trap is only active within the subroutine or function in which it appears.
Once an error trap has gained control, appropriate action should be taken, and then
control should be resumed using the Resume statement. The Resume statement resets
the error handler and continues execution. If a procedure ends while an error is pending,
then an error will be generated. (The Exit Sub or Exit Function statement also resets
the error handler, allowing a procedure to end without displaying an error message.)
Pass:
Err = -1 'Clear error status.
MsgBox "Cleared error status and continued."
x% = a * b
x% = a / 0
Open (statement)
Syntax Open filename$ [For mode] [Access accessmode] [lock] As [#] filenumber
_
[Len = reclen]
Description Opens a file for a given mode, assigning the open file to the supplied filenumber.
Comments The filename$ parameter is a string expression that contains a valid filename.
The filenumber parameter is a number between 1 and 255. The FreeFile function can be
used to determine an available file number.
The mode parameter determines the type of operations that can be performed on that
file:
File Mode Description
Input Opens an existing file for sequential input (filename$ must
exist). The value of accessmode, if specified, must be Read.
Output Opens an existing file for sequential output, truncating its length
to zero, or creates a new file. The value of accessmode, if
specified, must be Write.
Append Opens an existing file for sequential output, positioning the file
pointer at the end of the file, or creates a new file. The value of
accessmode, if specified, must be Read Write.
Binary Opens an existing file for binary I/O or creates a new file.
Existing binary files are never truncated in length. The value of
accessmode, if specified, determines how the file can
subsequently be accessed.
Random Opens an existing file for record I/O or creates a new file.
Existing random files are truncated only if accessmode is Write.
The reclen parameter determines the record length for I/O
operations.
If the mode parameter is missing, then Random is used.
The accessmode parameter determines what type of I/O operations can be performed on
the file:
Access Description
Read Opens the file for reading only. This value is valid only for files
opened in Binary, Random, or Input mode.
Write Opens the file for writing only. This value is valid only for files
opened in Binary, Random, or Output mode.
Read Write Opens the file for both reading and writing. This value is valid
only for files opened in Binary, Random, or Append mode.
If the accessmode parameter is not specified, the following defaults are used:
File Mode Default Value for accessmode
Input Read
Output Write
Append Read Write
Binary When the file is initially opened, access is attempted three times
in the following order:
1. Read Write
2. Write
3. Read
Random Same as Binary files
The lock parameter determines what access rights are granted to other processes that
attempt to open the same file. The following table describes the values for lock:
lock Value Description
Shared Another process can both read this file and write to it.
(Deny none.)
Lock Read Another process can write to this file but not read it.
(Deny read.)
Lock Write Another process can read this file but not write to it.
(Deny write.)
Lock Read Write Another process is prevented both from reading this file
and from writing to it. (Exclusive.)
If lock is not specified, then the file is opened in Shared mode.
If the file does not exist and the lock parameter is specified, the file is opened
twiceonce to create the file and again to establish the correct sharing mode.
Files opened in Random mode are divided up into a sequence of records, each of the
length specified by the reclen parameter. If this parameter is missing, then 128 is used.
For files opened for sequential I/O, the reclen parameter specifies the size of the internal
buffer used by BasicScript when performing I/O. Larger buffers mean faster file access.
For Binary files, the reclen parameter is ignored.
For files opened in Append mode, BasicScript opens the file and positions the file
pointer after the last character in the file. The end-of-file character, if present, is not
removed by BasicScript.
Example 'This example opens several files in various configurations.
Sub Main()
Open "[Link]" For Output Access Write Lock Write As #2
Close
Open "[Link]" For Input Access Read Shared As #1
Close
Open "[Link]" For Append Access Write Lock Read Write as #3
Close
Open "[Link]" For Binary Access Read Write Shared As #4
Close
Open "[Link]" For Random Access Read Write Lock Read As #5
Close
Open "[Link]" For Input Access Read Shared As #6
Close
Kill "[Link]"
End Sub
OpenFileName$ (function)
Syntax OpenFileName$[([title$ [,[extensions$] [,helpfile,context]]])]
Description Displays a dialog box that prompts the user to select from a list of files, returning the
full pathname of the file the user selects or a zero-length string if the user selects
Cancel.
Comments This function displays the standard file open dialog box, which allows the user to select
a file. It takes the following parameters:
Parameter Description
title$ String specifying the title that appears in the dialog box's title
bar. If this parameter is omitted, then "Open" is used.
extension$ String specifying the available file types. The format for this
string depends on the platform on which BasicScript is running.
If this parameter is omitted, then all files are displayed.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also be
specified.
context Number specifying the ID of the topic within helpfile for this
dialog’s help. If this parameter is specified, then helpfile must
also be specified.
If both the helpfile and context parameters are specified, then a Help button is added in
addition to the OK and Cancel buttons. Context-sensitive help can be invoked by
selecting this button or using the help key (F1 on most platforms). Invoking help does
not remove the dialog.
Example ’This example asks the user for the name of a file, then proceeds
’to read the first line from that file.
Sub Main
Dim f As String,s As String
f$ = OpenFileName$("Open Picture","Text Files:*.TXT")
If f$ <> "" Then
Open f$ For Input As #1
Line Input #1,s$
Close #1
MsgBox "First line from " & f$ & " is " & s$
End If
End Sub
() Parentheses Highest
^ Exponentiation
- Unary minus
/, * Division and multiplication
\ Integer division
Mod Modulo
+, - Addition and subtraction
& String concatenation
=, <>, >, <, <=, >= Relational
Like, Is String and object comparison
Not Logical negation
And Logical or binary conjunction
Boolean
Integer
Long
Single
Date
Double
StrComp Like
The Option Compare statement must appear outside the scope of all subroutines and
functions. In other words, it cannot appear within a Sub or Function block.
Example 'This example shows the use of Option Compare.
Option Compare Binary
Sub CompareBinary
a$ = "This String Contains UPPERCASE."
b$ = "this string contains uppercase."
If a$ = b$ Then
MsgBox "The two strings were compared case-insensitive."
Else
MsgBox "The two strings were compared case-sensitive."
End If
End Sub
Option Compare Text
Sub CompareText
a$ = "This String Contains UPPERCASE."
b$ = "this string contains uppercase."
If a$ = b$ Then
MsgBox "The two strings were compared case-insensitive."
Else
MsgBox "The two strings were compared case-sensitive."
End If
End Sub
Sub Main()
CompareBinary 'Calls subroutine above.
CompareText 'Calls subroutine above.
End Sub
See Also Like (operator); InStr, InStrB (functions); StrComp (function); Comparison
Operators (topic).
Platform(s) All.
Description Turns on or off the ability to use C-style escape sequences within strings.
Comments When Option CStrings On is in effect, the compiler treats the backslash character as an
escape character when it appears within strings. An escape character is simply a special
character that otherwise cannot ordinarily be typed by the computer keyboard.
Escape Description Equivalent Expression
\r Carriage return Chr$(13)
\n Line Feed Chr$(10)
\a Bell Chr$(7)
\b Backspace Chr$(8)
\f Form Feed Chr$(12)
\t Tab Chr$(9)
\v Vertical tab Chr$(11)
\0 Null Chr$(0_
\" Double quote "" or Chr$(34)
\\ Backslash Chr$(92)
\? Question mark ?
\’ Single quote ’
\xhh Hexadecimal number Chr$(Val(&Hhh))
\ooo Octal number Chr$(Val(&Oooo))
\anycharacter Any character anycharacter
With hexadecimal values, BasicScript stops scanning for digits when it encounters a
nonhexadecimal digit or two digits, whichever comes first. Similarly, with octal values,
BasicScript stops scanning when it encounters a nonoctal digit or three digits,
whichever comes first.
When Option CStrings Off is in effect, then the backslash character has no special
meaning. This is the default.
Example Option CStrings On
Sub Main()
MsgBox "They said, \"Watch out for that clump of grass!\""
MsgBox "First line.\r\nSecond line."
MsgBox "Char A: \x41 \r\n Char B: \x42"
End Sub
Platform(s) All.
Description Sets the default data type of variables and function return values when not otherwise
specified.
Comments By default, the type of implicitly defined variables and function return values is
Variant. This statement is used for backward compatibility with earlier versions of
BasicScript where the default data type was Integer.
This statement must appear outside the scope of all functions and subroutines.
Currently, type can only be set to Integer.
Example 'This script sets the default data type to Integer. This fact
'is used to declare the function AddIntegers which returns an
'Integer data type.
Option Default Integer
Function AddIntegers(a As Integer,b As Integer)
Foo = a + b
End Function
Sub Main
Dim a,b,result
a = InputBox("Enter an integer:")
b = InputBox("Enter an integer:")
result = AddIntegers(a,b)
End Sub
See Also DefType (statement).
Platform(s) All.
OptionButton (statement)
Syntax OptionButton x,y,width,height,title$ [,.Identifier]
Parameter Description
title$ String containing text that appears within the option button. This
text may contain an ampersand character to denote an
accelerator letter, such as "&Portrait" for Portrait, which can be
selected by pressing the P accelerator.
.Identifier Name by which this control can be referenced by statements in a
dialog function (such as DlgFocus and DlgEnable).
Example See OptionGroup (statement).
See Also CancelButton (statement); CheckBox (statement); ComboBox (statement); Dialog
(function); Dialog (statement); DropListBox (statement); GroupBox (statement);
ListBox (statement); OKButton (statement); OptionGroup (statement); Picture
(statement); PushButton (statement); Text (statement); TextBox (statement); Begin
Dialog (statement); PictureButton (statement); HelpButton (statement).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
Platform Notes Windows, Win32, OS/2: On Windows, Win32, and OS/2 platforms, accelerators are
underlined, and the accelerator combination Alt+letter is used.
Macintosh: On the Macintosh, accelerators are normal in appearance, and the
accelerator combination Command+letter is used.
OptionEnabled (function)
Syntax OptionEnabled(name$ | id)
Description Returns True if the specified option button is enabled within the current window or
dialog box; returns False otherwise.
Comments This function is used to determine whether a given option button is enabled within the
current window or dialog box. If an option button is enabled, then its value can be set
using the SetOption statement.
The OptionEnabled statement takes the following parameters:
Parameter Description
name$ String containing the name of the option button.
id Integer specifying the ID of the option button.
Example 'This example checks to see whether the option button is enabled
'before setting it.
If OptionEnabled("Tile") Then
SetOption "Tile"
End If
See Also GetOption (function); OptionExists (function); SetOption (statement).
Platform(s) Windows.
OptionExists (function)
Syntax OptionExists(name$ | id)
Description Returns True if the specified option button exists within the current window or dialog
box; returns False otherwise.
Comments This function is used to determine whether a given option button exists within the
current window or dialog box.
The OptionExists statement takes the following parameters:
Parameter Description
name$ String containing the name of the option button.
id Integer specifying the ID of the option button.
Example 'This example checks to see whether the option button exists and
'is enabled before setting it.
If OptionExists("Tile") Then
If OptionEnabled("Tile") Then
SetOption("Tile")
End If
End If
OptionGroup (statement)
Syntax OptionGroup .Identifier
Description Specifies the start of a group of option buttons within a dialog box template.
Comments The .Identifier parameter specifies the name by which the group of option buttons can
be referenced by statements in a dialog function (such as DlgFocus and DlgEnable).
This parameter also creates an integer variable whose value corresponds to the index of
the selected option button within the group (0 is the first option button, 1 is the second
option button, and so on). This variable can be accessed using the following syntax:
[Link].
This statement can only appear within a dialog box template (i.e., between the Begin
Dialog and End Dialog statements).
When the dialog box is created, the option button specified by .Identifier will be on; all
other option buttons in the group will be off. When the dialog box is dismissed, the
.Identifier will contain the selected option button.
Example 'This example creates a group of option buttons.
Sub Main()
Begin Dialog PrintTemplate 16,31,128,65,"Print"
GroupBox 8,8,64,52,"Orientation",.Junk
OptionGroup .Orientation
OptionButton 16,20,37,8,"Portrait",.Portrait
OptionButton 16,32,51,8,"Landscape",.Landscape
OptionButton 16,44,49,8,"Don't Care",.DontCare
OKButton 80,8,40,14
End Dialog
Dim PrintDialog As PrintTemplate
Dialog PrintDialog
End Sub
Or (operator)
Syntax result = expression1 Or expression2
Description Performs a logical or binary disjunction on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or Null variants, then a logical
disjunction is performed as follows:
If expression1 is and expression2 is then the result is
True True True
True False True
True Null True
False True True
False False False
False Null Null
Null True True
Null False Null
Null Null Null
Binary Disjunction
If the two expressions are Integer, then a binary disjunction is performed, returning an
Integer result. All other numeric types (including Empty variants) are converted to
Long and a binary disjunction is then performed, returning a Long result.
Binary disjunction forms a new value based on a bit-by-bit comparison of the binary
representations of the two expressions according to the following table:
If bit in expression1 is and bit in expression2 is the result is
1 1 1
0 1 1
1 0 1
0 0 0
See Also Operator Precedence (topic); Xor (operator); Eqv (operator); Imp (operator); And
(operator).
Platform(s) All.
Picture (statement)
Syntax Picture x,y,width,height,PictureName$,PictureType [,[.Identifier]
[,style]]
The picture control extracts the actual image from either a disk file or a picture library.
In the case of bitmaps, both 2- and 16-color bitmaps are supported. In the case of
WMFs, BasicScript supports the Placeable Windows Metafile.
If PictureName$ is a zero-length string, then the picture is removed from the picture
control, freeing any memory associated with that picture.
Examples 'This first example shows how to use a picture from a file.
Sub Main()
Begin Dialog LogoDialogTemplate 16,32,288,76,"Introduction"
OKButton 240,8,40,14
Picture 8,8,224,64,"c:\bitmaps\[Link]",0,.Logo
End Dialog
Dim LogoDialog As LogoDialogTemplate
Dialog LogoDialog
End Sub
'This second example shows how to use a picture from a picture
'library with a 3D frame.
Sub Main()
Begin Dialog LogoDlg 16,31,288,76,"Introduction",,"[Link]"
OKButton 240,8,40,14
Picture 8,8,224,64,"CompanyLogo",10,.Logo,1
End Dialog
Dim LogoDialog As LogoDialogTemplate
Dialog LogoDialog
End Sub
Picture libraries on the Macintosh are files with collections of named PICT resources.
The PictureName$ parameter corresponds to the name of one the resources as it appears
within the file.
PictureButton (statement)
Syntax PictureButton x,y,width,height,PictureName$,PictureType [,.Identifier]
Examples 'This first example shows how to use a picture from a file.
Sub Main()
Begin Dialog LogoDialogTemplate 16,32,288,76,"Introduction"
OKButton 240,8,40,14
PictureButton 8,4,224,64,"c:\bitmaps\[Link]",0,.Logo
End Dialog
Dim LogoDialog As LogoDialogTemplate
Dialog LogoDialog
End Sub
Pmt (function)
Syntax Pmt(rate, nper, pv, fv, due)
Description Returns the payment for an annuity based on periodic fixed payments and a constant
rate of interest.
Comments An annuity is a series of fixed payments made to an insurance company or other
investment company over a period of time. Examples of annuities are mortgages and
monthly savings plans.
The Pmt function requires the following named parameters:
Named Parameter Description
rate Double representing the interest rate per period. If the
periods are given in months, be sure to normalize annual rates
by dividing them by 12.
nper Double representing the total number of payments in the
annuity.
pv Double representing the present value of your annuity. In the
case of a loan, the present value would be the amount of the
loan.
fv Double representing the future value of your annuity. In the
case of a loan, the future value would be 0.
due Integer indicating when payments are due for each payment
period. A 0 specifies payment at the end of each period,
whereas a 1 specifies payment at the start of each period.
The rate and nper parameters must be expressed in the same units. If rate is expressed
in months, then nper must also be expressed in months.
Positive numbers represent cash received, whereas negative numbers represent cash
paid out.
Example 'This example calculates the payment necessary to repay a
'$1,000.00 loan over 36 months at an annual rate of 10%.
'Payments are due at the beginning of the period.
Sub Main()
x = Pmt((.1/12),36,1000.00,0,1)
message = "The payment is: "
MsgBox message & Format(x,"Currency")
End Sub
See Also IPmt (function); NPer (function); PPmt (function); Rate (function).
Platform(s) All.
PopupMenu (function)
Syntax PopupMenu(MenuItems$())
Description Displays a pop-up menu containing the specified items, returning an Integer
representing the index of the selected item.
Comments If no item is selected (i.e., the pop-up menu is canceled), then a value of 1 less than the
lower bound of the array is returned.
This function creates a pop-up menu using the string elements in the given array. Each
array element is used as a menu item. A zero-length string results in a separator bar in
the menu.
The pop-up menu is created with the upper left corner at the current mouse position.
A runtime error results if MenuItems$ is not a single-dimension array.
Only one pop-up menu can be displayed at a time. An error will result if another script
executes this function while a pop-up menu is visible.
Example Sub Main()
Dim a$()
AppList a$
w% = PopupMenu(a$)
End Sub
See Also SelectBox (function).
Platform(s) Windows, Win32.
PPmt (function)
Syntax PPmt(rate, per, nper, pv, fv, due)
Description Calculates the principal payment for a given period of an annuity based on periodic,
fixed payments and a fixed interest rate.
Comments An annuity is a series of fixed payments made to an insurance company or other
investment company over a period of time. Examples of annuities are mortgages and
monthly savings plans.
The PPmt function requires the following named parameters:
Named Parameter Description
rate Double representing the interest rate per period.
per Double representing the number of payment periods. The per
parameter can be no less than 1 and no greater than nper.
See Also IPmt (function); NPer (function); Pmt (function); Rate (function).
Platform(s) All.
Print (statement)
Syntax Print [[{Spc(n) | Tab(n)}][expressionlist][{; | ,}]]
The Tab and Spc functions provide additional control over the column position. The
Tab function moves the file position to the specified column, whereas the Spc function
outputs the specified number of spaces.
Print# (statement)
Syntax Print [#]filenumber, [[{Spc(n) | Tab(n)}][expressionlist][{;|,}]]
In order to correctly read the data using the Input# statement, you should write the data
using the Write statement.
The end-of-line character is different on many platforms. On some platforms, it is
defined as a carriage-return/line-feed pair, and on other platforms, it is defined as only a
line feed. The BasicScript statements that read sequential files don't care about the
end-of-line character—either will work.
Examples Sub Main()
'This example opens a file and prints some data.
Open "[Link]" For Output As #1
i% = 10
s$ = "This is a test."
Print #1,"The value of i=";i%,"the value of s=";s$
'This example prints the value of i% in print zone 1 and s$
'in print zone 3.
Print #1,i%,,s$
'This example prints the value of i% and s$ separated by ten
'spaces.
Print #1,i%;Spc(10);s$
'This example prints the value of i in column 1 and s$ in
'column 30.
Print #1,i%;Tab(30);s$
'This example prints the value of i% and s$.
Print #1,i%;s$,
Print #1,67
Close #1
Kill "[Link]"
End Sub
PrinterGetOrientation (function)
Syntax PrinterGetOrientation[()]
Description Returns an Integer representing the current orientation of paper in the default printer.
Comments PrinterGetOrientation returns ebPortrait if the printer orientation is set to portrait;
otherwise, it returns ebLandscape. Zero is returned if there is no installed default
printer.
This function loads the printer driver and therefore may be slow.
Example 'This example toggles the printer orientation.
Sub Main()
If PrinterGetOrientation = ebLandscape Then
PrinterSetOrientation ebPortrait
Else
PrinterSetOrientation ebLandscape
End If
End Sub
PrinterSetOrientation (statement)
Syntax PrinterSetOrientation NewSetting
PrintFile (function)
Syntax PrintFile(filename$)
Description Prints the filename$ using the application to which the file belongs.
Comments PrintFile returns an Integer indicating success or failure.
If an error occurs executing the associated application, then PrintFile generates a
trappable runtime error, returning 0 for the result. Otherwise, PrintFile returns a value
representing that application to the system. This value is suitable for calling the
AppActivate statement.
Example 'This example asks the user for the name of a text file, then
'prints it.
Sub Main()
f$ = OpenFilename$("Print Text File","Text Files:*.txt")
If f$ <> "" Then
rc% = PrintFile(f$)
If rc% > 32 Then
MsgBox "File is printing."
End If
End If
End Sub
See Also Shell (function).
Platform(s) Windows.
Platform Notes Windows: This function invokes the Windows 3.1 shell functions that cause an
application to execute and print a file. The application executed by PrintFile depends
on your system's file associations.
Private (statement)
Syntax Private name [(subscripts)] [As type] [,name [(subscripts)] [As
type]]...
Description Declares a list of private variables and their corresponding types and sizes.
Comments Private variables are global to every Sub and Function within the currently executing
script.
If a type-declaration character is used when specifying name (such as %, @, &, $, or !),
the optional [As type] expression is not allowed. For example, the following are
allowed:
Private foo As Integer
Private foo%
The subscripts parameter allows the declaration of arrays. This parameter uses the
following syntax:
[lower To] upper [,[lower To] upper]...
The lower and upper parameters are integers specifying the lower and upper bounds of
the array. If lower is not specified, then the lower bound as specified by Option Base is
used (or 1 if no Option Base statement has been encountered). Up to 60 array
dimensions are allowed.
The total size of an array (not counting space for strings) is limited to 64K.
Dynamic arrays are declared by not specifying any bounds:
Private a()
The type parameter specifies the type of the data item being declared. It can be any of
the following data types: String, Integer, Long, Single, Double, Currency, Object,
data object, built-in data type, or any user-defined data type.
If a variable is seen that has not been explicitly declared with either Dim, Public, or
Private, then it will be implicitly declared local to the routine in which it is used.
Fixed-Length Strings
Fixed-length strings are declared by adding a length to the String type-declaration
character:
Private name As String * length
where length is a literal number specifying the string's length.
Initial Values
All declared variables are given initial values, as described in the following table:
Data Type Initial Value
Integer 0
Long 0
Double 0.0
Single 0.0
Currency 0.0
Object Nothing
Date December 31, 1899 00:00:00
Boolean False
Variant Empty
String "" (zero-length string)
User-defined type Each element of the structure is given a default value, as
described above.
Arrays Each element of the array is given a default value, as
described above.
Example See Public (statement).
See Also Dim (statement); Redim (statement); Public (statement); Option Base (statement).
Platform(s) All.
Public (statement)
Syntax Public name [(subscripts)] [As type] [,name [(subscripts)] [As type]]...
Description Declares a list of public variables and their corresponding types and sizes.
Comments Public variables are global to all Subs and Functions in all scripts.
If a type-declaration character is used when specifying name (such as %, @, &, $, or !),
the optional [As type] expression is not allowed. For example, the following are
allowed:
Public foo As integer
Public foo%
The subscripts parameter allows the declaration of arrays. This parameter uses the
following syntax:
[lower To] upper [,[lower To] upper]...
The lower and upper parameters are integers specifying the lower and upper bounds of
the array. If lower is not specified, then the lower bound as specified by Option Base is
used (or 1 if no Option Base statement has been encountered). Up to 60 array
dimensions are allowed.
The total size of an array (not counting space for strings) is limited to 64K.
Dynamic arrays are declared by not specifying any bounds:
Public a()
The type parameter specifies the type of the data item being declared. It can be any of
the following data types: String, Integer, Long, Single, Double, Currency, Object,
data object, built-in data type, or any user-defined data type.
If a variable is seen that has not been explicitly declared with either Dim, Public, or
Private, then it will be implicitly declared local to the routine in which it is used.
For compatibility, the keyword Global is also supported. It has the same meaning as
Public.
Fixed-Length Strings
Fixed-length strings are declared by adding a length to the String type-declaration
character:
Public name As String * length
where length is a literal number specifying the string's length.
All declared variables are given initial values, as described in the following table:
Data Type Initial Value
Integer 0
Long 0
Double 0.0
Single 0.0
Currency 0.0
Date December 31, 1899 00:00:00
Object Nothing
Boolean False
Variant Empty
String "" (zero-length string)
User-defined type Each element of the structure is given a default value, as
described above.
Arrays Each element of the array is given a default value, as
described above.
Sharing Variables
When sharing variables, you must ensure that the declarations of the shared variables
are the same in each script that uses those variables. If the public variable being shared
is a user-defined structure, then the structure definitions must be exactly the same.
Example 'This example uses a subroutine to calculate the area of ten
'circles and displays the result in a dialog box. The variables
'R and Ar are declared as Public variables so that they can be
'used in both Main and Area.
Const crlf = Chr$(13) + Chr$(10)
Public x#, ar#
Sub Area()
ar# = (x# ^ 2) * Pi
End Sub
Sub Main()
message = "The area of the ten circles are:" & crlf
For x# = 1 To 10
Area
message = message & x# & ": " & ar# & [Link]$
Next x#
MsgBox message
End Sub
See Also Dim (statement); Redim (statement); Private (statement); Option Base (statement).
Platform(s) All.
PushButton (statement)
Syntax PushButton x,y,width,height,title$ [,.Identifier]
End Sub
See Also CancelButton (statement); CheckBox (statement); ComboBox (statement); Dialog
(function); Dialog (statement); DropListBox (statement); GroupBox (statement);
ListBox (statement); OKButton (statement); OptionButton (statement);
OptionGroup (statement); Picture (statement); Text (statement); TextBox
(statement); Begin Dialog (statement); PictureButton (statement); HelpButton
(statement).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
Platform Notes Windows, Win32, OS/2: On Windows, Win32, and OS/2 platforms, accelerators are
underlined, and the accelerator combination Alt+letter is used.
Macintosh: On the Macintosh, accelerators are normal in appearance, and the
accelerator combination Command+letter is used.
Put (statement)
Syntax Put [#]filenumber, [recordnumber], variable
Description Writes data from the specified variable to a Random or Binary file.
Comments The Put statement accepts the following parameters:
Parameter Description
filenumber Integer representing the file to be written to. This is the same
value as returned by the Open statement.
recordnumber Long specifying which record is to be written to the file.
For Binary files, this number represents the first byte to be
written starting with the beginning of the file (the first byte is
1). For Random files, this number represents the record
number starting with the beginning of the file (the first record
is 1). This value ranges from 1 to 2147483647.
If the recordnumber parameter is omitted, the next record is
written to the file (if no records have been written yet, then the
first record in the file is written). When recordnumber is
omitted, the commas must still appear, as in the following
example:
Put #1,,recvar
If recordlength is specified, it overrides any previous change
in file position specified with the Seek statement.
The variable parameter is the name of any variable of any of the following types:
VariableType File Storage Description
Integer 2 bytes are written to the file.
Long 4 bytes are written to the file.
String (variable-length) In Binary files, variable-length strings are written by
first determining the specified string variable's length,
then writing that many bytes to a file.
In Random files, variable-length strings are written by
first writing a 2-byte length, then writing that many
characters to the file.
String (fixed-length) Fixed-length strings are written to Random and
Binary files in the same way: the number of characters
equal to the string's declared length are written.
Double 8 bytes are written to the file (IEEE format),
Single 4 bytes are written to the file (IEEE format).
Date 8 bytes are written to the file (IEEE double format).
Boolean 2 bytes are written to the file (either –1 for True or 0
for False).
Variant A 2-byte VarType is written to the file followed by the
data as described above. With variants of type 10
(user-defined errors), the 2-byte VarType is followed
by a 4-byte error value (the low word containing the
error value and the high word containing additional
bytes of information).
The exception is with strings, which are always
preceded by a 2-byte string length.
User-defined types Each member of a user-defined data type is written
individually.
In Binary files, variable-length strings within
user-defined types are written by first writing a 2-byte
length followed by the string's content. This storage is
different than variable-length strings outside of
user-defined types.
When writing user-defined types, the record length
must be greater than or equal to the combined size of
each element within the data type.
Arrays Arrays cannot be written to a file using the Put
statement.
See Also Open (statement); Put (statement); Write# (statement); Print# (statement).
Platform(s) All.
Pv (function)
Syntax Pv(rate, nper, pmt, fv, due)
Description Calculates the present value of an annuity based on future periodic fixed payments and a
constant rate of interest.
QueEmpty (statement)
Syntax QueEmpty
Sub Main()
AppActivate "Notepad"
QueEmpty 'Make sure the queue is empty.
QueMouseDn ebLeftButton,1440,1393
QueMouseUp ebLeftButton,4147,2363
QueFlush True
End Sub
Platform(s) Windows.
Platform Notes Windows: If a system modal dialog is invoked during queue playback, the queue
playback is temporarily disabled. Queue playback will resume once the dialog has been
dismissed. Hardware input is enabled during processing of the system modal dialog
such that the dialog can be dismissed by the user. Otherwise, hardware input is enabled
until playback is finished.
QueFlush (statement)
Syntax QueFlush isSaveState
Description Plays back events that are stored in the current event queue.
Comments After QueFlush is finished, the queue is empty.
If isSaveState is True, then QueFlush saves the state of the Caps Lock, Num Lock,
Scroll Lock, and Insert and restores the state after the QueFlush is complete. If this
parameter is False, these states are not restored.
The function does not return until the entire queue has been played.
Example 'This example pumps some keys into Notepad.
Sub Main()
AppActivate "Notepad"
QueKeys "This is a test{Enter}"
QueFlush True 'Play back the queue.
End Sub
Platform(s) Windows.
Platform Notes Windows: The QueFlush statement uses the Windows journaling mechanism to replay
the mouse and keyboard events stored in the queue. As a result, the mouse position may
be changed. Furthermore, events can be played into any Windows application, including
DOS applications running in a window.
QueKeyDn (statement)
Syntax QueKeyDn KeyString$ [,time]
Description Appends key-down events for the specified keys to the end of the current event queue.
Comments The QueKeyDn statement accepts the following parameters:
Parameter Description
KeyString$ String containing the keys to be sent. The format for KeyString$
is described under the SendKeys statement.
time Integer specifying the number of milliseconds devoted for the
output of the entire KeyString$ parameter. It must be within the
following range:
0 <= time <= 32767
For example, if time is 5000 (5 seconds) and the KeyString$
parameter contains ten keys, then a key will be output every 1/2
second. If unspecified (or 0), the keys will play back at full
speed.
The QueFlush command is used to play back the events stored in the current event
queue.
Example 'This example plays back a Ctrl + mouse click.
Sub Main()
QueEmpty
QueKeyDn "^"
QueMouseClick ebLeftButton 1024,792
QueKeyUp "^"
QueFlush True
End Sub
See Also DoKeys (statement); SendKeys (statement); QueKeys (statement); QueKeyUp
(statement); QueFlush (statement).
Platform(s) Windows.
QueKeys (statement)
Syntax QueKeys KeyString$ [,time]
Parameter Description
time Integer specifying the number of milliseconds devoted for the
output of the entire KeyString$ parameter. It must be within the
following range:
0 <= time <= 32767
For example, if time is 5000 (5 seconds) and the KeyString$
parameter contains ten keys, then a key will be output every 1/2
second. If unspecified (or 0), the keys will play back at full
speed.
The QueFlush command is used to play back the events stored in the current event
queue.
Example Sub Main()
WinActivate "Notepad"
QueEmpty
QueKeys "This is a test.{Enter}This is on a new line.{Enter}"
QueKeys "{Tab 3}This is indented with three tabs."
QueKeys "Some special characters: {~}{^}{%}{+}~"
QueKeys "Invoking the Find dialog.%Sf"'Alt+S,F
QueFlush True
End Sub
See Also DoKeys (statement); SendKeys (statement); QueKeyDn (statement); QueKeyUp
(statement); QueFlush (statement).
Platform(s) Windows.
Platform Notes Windows: Under Windows, you cannot send keystrokes to MS-DOS applications
running in a window.
QueKeyUp (statement)
Syntax QueKeyUp KeyString$ [,time]
Description Appends key-up events for the specified keys to the end of the current event queue.
Comments The QueKeyUp statement accepts the following parameters:
Parameter Description
KeyString$ String containing the keys to be sent. The format for KeyString$
is described under the SendKeys statement.
Parameter Description
time Integer specifying the number of milliseconds devoted for the
output of the entire KeyString$ parameter. It must be within the
following range:
0 <= time <= 32767
For example, if time is 5000 (5 seconds) and the KeyString$
parameter contains ten keys, then a key will be output every 1/2
second. If unspecified (or 0), the keys will play back at full
speed.
The QueFlush command is used to play back the events stored in the current event
queue.
Example See QueKeyDn (statement).
See Also DoKeys (statement); SendKeys (statement); QueKeys (statement); QueKeyDn
(statement); QueFlush (statement).
Platform(s) Windows.
QueMouseClick (statement)
Syntax QueMouseClick button,x,y [,time]
QueMouseDblClk (statement)
Syntax QueMouseDblClk button,x,y [,time]
QueMouseDblDn (statement)
Syntax QueMouseDblDn button, x, y [,time]
Description Adds a mouse double down to the end of the current event queue.
Comments The QueMouseDblDn statement takes the following parameters:
Parameter Description
button Integer specifying which mouse button to press:
ebLeftButtonPress the left mouse button.
ebRightButtonPress the right mouse button.
x, y Integer coordinates, in twips, where the mouse double down is
to be recorded.
time Integer specifying the delay in milliseconds between this event
and the previous event in the queue. If this parameter is omitted
(or 0), the mouse double down will play back at full speed.
This statement adds a mouse double down to the current event queue. A double down
consists of a mouse down/up/down at position x, y.
The QueFlush command is used to play back the events stored in the current event
queue.
Example 'This example double-clicks a word, then drags it to a new
'location.
Sub Main()
QueFlush 'Start with empty queue.
QueMouseDblDn ebLeftButton,356,4931
QueMouseMove 600,4931'Drag to new spot.
QueMouseUp ebLeftButton'Now release the mouse.
QueFlush True 'Play back the queue.
End Sub
QueMouseDn (statement)
Syntax QueMouseDn button,x,y [,time]
QueMouseMove (statement)
Syntax QueMouseMove x,y [,time]
QueMouseMoveBatch (statement)
Syntax QueMouseMoveBatch ManyMoves$
QueMouseMoveBatch _
"2895,3146,0,2911,3083,0,2926,3020,0,2942,2958,0,2973,2895,0"
QueMouseMoveBatch _
"3005,2848,0,3020,2817,0,3036,2801,0,3052,2770,0,3083,2770,0"
QueMouseMoveBatch _
"3114,2754,0,3130,2754,0,3146,2770,0,3161,2786,0,3161,2848,0"
QueMouseMoveBatch _
"3193,3005,0,3193,3193,0,3208,3255,0,3224,3318,0,3240,3349,0"
QueMouseMoveBatch _
"3255,3349,0,3286,3318,0,3380,3271,0,3474,3208,0,3553,3052,0"
QueMouseMoveBatch _
"3584,2895,0,3615,2739,0,3631,2692,0,3631,2645,0,3646,2645,0"
QueMouseMoveBatch _
"3646,2660,0,3646,2723,0,3646,2880,0,3662,2942,0,3693,2989,0"
QueMouseMoveBatch _
"3709,3005,0,3725,3005,0,3756,2989,0,3787,2973,0"
QueMouseUp ebLeftButton,3787,2973
QueMouseDn ebLeftButton,3678,2535
QueMouseMove 3678,2520
QueMouseMove 3678,2535
QueMouseUp ebLeftButton,3678,2535
QueFlush True
End Sub
QueMouseUp (statement)
Syntax QueMouseUp button,x,y [,time]
Parameter Description
time Integer specifying the delay in milliseconds between this event
and the previous event in the queue. If this parameter is omitted
(or 0), the mouse up will play back at full speed.
The QueFlush command is used to play back the events stored in the current event
queue.
Example See QueEmpty (statement).
See Also QueMouseClick (statement); QueMouseDn (statement); QueMouseDblClk
(statement); QueMouseDblDn (statement); QueMouseMove (statement);
QueMouseMoveBatch (statement); QueFlush (statement).
Platform(s) Windows.
QueSetRelativeWindow (statement)
Syntax QueSetRelativeWindow [window_object]
Description Forces all subsequent QueX commands to adjust the mouse positions relative to the
specified window.
Comments The window_object parameter is an object of type HWND. If window_object is
Nothing or omitted, then the window with the focus is used (i.e., the active window).
The QueFlush command is used to play back the events stored in the current event
queue.
Example Sub Main()
'Adjust mouse coordinates relative to Notepad.
Dim a As HWND
Set a = WinFind("Notepad")
QueSetRelativeWindow a
End Sub
Platform(s) Windows.
Random (function)
Syntax Random(min,max)
Description Returns a Long value greater than or equal to min and less than or equal to max.
Comments Both the min and max parameters are rounded to Long. A runtime error is generated if
min is greater than max.
Example 'This example uses the random number generator to generate ten
'lottery numbers.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Randomize 'Start with new random seed.
For x = 1 To 10
y = Random(0,100)'Generate numbers.
message = message & y & crlf
Next x
MsgBox "Ten numbers for the lottery: " & crlf & message
End Sub
See Also Randomize (statement); Random (function).
Platform(s) All.
Randomize (statement)
Syntax Randomize [number]
Rate (function)
Syntax Rate(nper, pmt, pv, fv, due, guess)
See Also IPmt (function); NPer (function); Pmt (function); PPmt (function).
Platform(s) All.
ReadIni$ (function)
Syntax ReadIni$(section$,item$[,filename$])
Description Returns a String containing the specified item from an ini file.
Comments The ReadIni$ function takes the following parameters:
Parameter Description
section$ String specifying the section that contains the desired variable,
such as "windows". Section names are specified without the
enclosing brackets.
item$ String specifying the item whose value is to be retrieved.
filename$ String containing the name of the ini file to read.
The maximum length of a string returned by this function is 4096 characters.
See Also WriteIni (statement); ReadIniSection (statement).
Platform(s) Windows, Win32, OS/2.
Platform Notes Windows, Win32: Under Windows and Win32, if the name of the ini file is not
specified, then [Link] is assumed.
If the filename$ parameter does not include a path, then this statement looks for ini files
in the Windows directory.
ReadIniSection (statement)
Syntax ReadIniSection section$,ArrayOfItems()[,filename$]
Description Fills an array with the item names from a given section of the specified ini file.
Comments The ReadIniSection statement takes the following parameters:
Parameter Description
section$ String specifying the section that contains the desired variables,
such as "windows". Section names are specified without the
enclosing brackets.
ArrayOfItems() Specifies either a zero- or a one-dimensioned array of strings or
variants. The array can be either dynamic or fixed.
If ArrayOfItems() is dynamic, then it will be redimensioned to
exactly hold the new number of elements. If there are no
elements, then the array will be redimensioned to contain no
dimensions. You can use the LBound, UBound, and
ArrayDims functions to determine the number and size of the
new array's dimensions.
Parameter Description
If the array is fixed, each array element is first erased, then the
new elements are placed into the array. If there are fewer
elements than will fit in the array, then the remaining elements
are initialized to zero-length strings (for String arrays) or
Empty (for Variant arrays). A runtime error results if the array
is too small to hold the new elements.
filename$ String containing the name of an ini file.
On return, the ArrayOfItems() parameter will contain one array element for each
variable in the specified ini section. The maximum combined length of all the entry
names returned by this function is limited to 32K.
Example Sub Main()
Dim items() As String
ReadIniSection "windows",items$
r% = SelectBox("INI Items",,items$)
End Sub
Redim (statement)
Syntax Redim [Preserve] variablename ([subscriptRange]) [As type],...
Description Redimensions an array, specifying a new upper and lower bound for each dimension of
the array.
Comments The variablename parameter specifies the name of an existing array (previously
declared using the Dim statement) or the name of a new array variable. If the array
variable already exists, then it must previously have been declared with the Dim
statement with no dimensions, as shown in the following example:
Dim a$() 'Dynamic array of strings (no dimensions yet)
Dynamic arrays can be redimensioned any number of times.
The subscriptRange parameter specifies the new upper and lower bounds for each
dimension of the array using the following syntax:
[lower To] upper [,[lower To] upper]...
See Also Dim (statement); Public (statement); Private (statement); ArrayDims (function);
LBound (function); UBound (function).
Platform(s) All.
Rem (statement)
Syntax Rem text
End Sub
See Also ' (keyword); Comments (topic).
Platform(s) All.
Reset (statement)
Syntax Reset
Description Closes all open files, writing out all I/O buffers.
Example 'This example opens a file for output, closes it with the Reset
'statement, then deletes it with the Kill statement.
Sub Main()
Open "[Link]" for Output Access Write as # 1
Reset
Kill "[Link]"
If FileExists("[Link]") Then
MsgBox "The file was not deleted."
Else
MsgBox "The file was deleted."
End If
End Sub
Resume (statement)
Syntax Resume {[0] | Next | label}
Return (statement)
Syntax Return
Description Transfers execution control to the statement following the most recent GoSub.
Comments A runtime error results if a Return statement is encountered without a corresponding
GoSub statement.
Example 'This example calls a subroutine and then returns execution to
'the Main routine by the Return statement.
Sub Main()
GoSub SubTrue
MsgBox "The Main routine continues here."
Exit Sub
SubTrue:
MsgBox "This message is generated in the subroutine."
Return
Exit Sub
End Sub
Description Returns the rightmost length characters (for Right and Right$) or bytes (for RightB
and RightB$) from a specified string.
Comments The Right$ and RightB$ functions return a String, whereas the Right and RightB
functions return a String variant.
These functions take the following named parameters:
Named Parameter Description
string String from which characters are returned. A runtime error is
generated if string is Null.
length Integer specifying the number of characters or bytes to return.
If length is greater than or equal to the length of the string, then
the entire string is returned. If length is 0, then a zero-length
string is returned.
The RightB and RightB$ functions are used to return byte data from strings containing
byte data.
Example 'This example shows the Right$ function used in a routine to
'change uppercase names to lowercase with an uppercase first
'letter.
Sub Main()
lname$ = "WILLIAMS"
x = Len(lname$)
rest$ = Right$(lname$,x - 1)
fl$ = Left$(lname$,1)
lname$ = fl$ & LCase$(rest$)
MsgBox "The converted name is: " & lname$
End Sub
RmDir (statement)
Syntax RmDir path
See Also ChDir (statement); ChDrive (statement); CurDir, CurDir$ (functions); Dir, Dir$
(functions); MkDir (statement).
Platform(s) All.
Platform Notes Windows: Under Windows, this command behaves the same as the DOS "rd"
command.
Rnd (function)
Syntax Rnd[(number)]
Comments If number is omitted, the next random number is returned. Otherwise, the number
parameter has the following meaning:
If Then
number < 0 Always returns the same number.
number = 0 Returns the last number generated.
number > 0 Returns the next random number.
Example 'This routine generates a list of random numbers and displays
'them.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
For x = -1 To 8
y! = Rnd(1) * 100
message = message & x & " : " & y! & crlf
Next x
MsgBox message & "Last form: " & Rnd
End Sub
RSet (statement)
Syntax RSet destvariable = source
Description Copies the source string source into the destination string destvariable.
Comments If source is shorter in length than destvariable, then the string is right-aligned within
destvariable and the remaining characters are padded with spaces. If source is longer in
length than destvariable, then source is truncated, copying only the leftmost number of
characters that will fit in destvariable. A runtime error is generated if source is Null.
The destvariable parameter specifies a String or Variant variable. If destvariable is a
Variant containing Empty, then no characters are copied. If destvariable is not
convertible to a String, then a runtime error occurs. A runtime error results if
destvariable is Null.
Example 'This example replaces a 40-character string of asterisks (*)
'with an RSet and LSet string and then displays the result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
Dim message,tmpstr$
tmpstr$ = String$(40, "*")
message = "Here are two strings that have been right-" & crlf
SaveFileName$ (function)
Syntax SaveFileName$[([title$ [,[extensions$] [helpfile,context]]])]
Description Displays a dialog box that prompts the user to select from a list of files and returns a
String containing the full path of the selected file.
Comments The SaveFileName$ function accepts the following parameters:
Parameter Description
title$ String containing the title that appears on the dialog box's
caption. If this string is omitted, then "Save As" is used.
extensions$ String containing the available file types. Its format depends on
the platform on which BasicScript is running. If this string is
omitted, then all files are used.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also be
specified.
context Number specifying the ID of the topic within helpfile for this
dialog's help. If this parameter is specified, then helpfile must
also be specified.
The SaveFileName$ function returns a full pathname of the file that the user selects. A
zero-length string is returned if the user selects Cancel. If the file already exists, then the
user is prompted to overwrite it.
If both the helpfile and context parameters are specified, then a Help button is added in
addition to the OK and Cancel buttons. Context-sensitive help can be invoked by
selecting this button or using the help key (F1 key on most platforms). Invoking help
does not remove the dialog.
Example 'This example creates a save dialog box, giving the user the
'ability to save to several different file types.
Sub Main()
e$ = "All Files:*.BMP,*.WMF;Bitmaps:*.BMP;Metafiles:*.WMF"
f$ = SaveFileName$("Save Picture",e$)
If Not f$ = "" Then
MsgBox "User choose to save file as: " + f$
Else
MsgBox "User canceled."
End If
End Sub
SaveSetting (statement)
Syntax SaveSetting appname, section, key, setting
Description Saves the value of the specified key in the system registry. The following table describes
the named parameters to the SaveSetting statement:
Named Parameter Description
appname String expression indicating the name of the application
whose setting will be modified.
section String expression indicating the name of the section whose
setting will be modified.
key String expression indicating the name of the setting to be
modified.
setting The value assigned to key.
Example ’The following example adds two entries to the Windows registry
’if run under Win32 or to [Link] on other platforms,
[Link] (property)
Syntax [Link]
Description Returns an Integer used to convert horizontal pixels to and from dialog units.
Comments The number returned depends on the name and size of the font used to display dialog
boxes.
To convert from pixels to dialog units in the horizontal direction:
((XPixels * 4) + ([Link] - 1)) /
[Link]
To convert from dialog units to pixels in the horizontal direction:
(XDlgUnits * [Link]) / 4
Example 'This example converts the screen width from pixels to dialog
'units.
Sub Main()
XPixels = [Link]
conv% = [Link]
XDlgUnits = (XPixels * 4) + (conv% -1) / conv%
MsgBox "The screen width is " & XDlgUnits & " dialog units."
End Sub
See Also [Link] (property).
Platform(s) Windows, Win32.
[Link] (property)
Syntax [Link]
Description Returns an Integer used to convert vertical pixels to and from dialog units.
Comments The number returned depends on the name and size of the font used to display dialog
boxes.
To convert from pixels to dialog units in the vertical direction:
(YPixels * 8) + ([Link] - 1) /
[Link]
To convert from dialog units to pixels in the vertical direction:
(YDlgUnits * [Link]) / 8
Example 'This example converts the screen width from pixels to dialog
'units.
Sub Main()
YPixels = [Link]
conv% = [Link]
YDlgUnits = (YPixels * 8) + (conv% -1) / conv%
MsgBox "The screen width is " & YDlgUnits & " dialog units."
End Sub
See Also [Link] (property).
Platform(s) Windows, Win32.
[Link] (property)
Syntax [Link]
MsgBox "The Screen height is " & [Link] & " pixels."
End Sub
See Also [Link] (property).
Platform(s) Windows, Win32.
[Link] (property)
Syntax [Link]
Description Returns an Integer representing the number of twips per pixel in the horizontal
direction of the installed display driver.
Comments This property is read-only.
Example 'This example displays the number of twips across the screen
'horizontally.
Sub Main()
XScreenTwips = [Link] * [Link]
MsgBox "Total horizontal screen twips = " & XScreenTwips
End Sub
[Link] (property)
Syntax [Link]
Description Returns an Integer representing the number of twips per pixel in the vertical direction
of the installed display driver.
Comments This property is read-only.
Example 'This example displays the number of twips across the screen
'vertically.
Sub Main()
YScreenTwips = [Link] * [Link]
MsgBox "Total vertical screen twips = " & YScreenTwips
End Sub
See Also [Link] (property).
Platform(s) Windows, Win32.
[Link] (property)
Syntax [Link]
Second (function)
Syntax Second(time)
Description Returns the second of the day encoded in the specified time parameter.
Comments The value returned is an Integer between 0 and 59 inclusive.
The time parameter is any expression that converts to a Date.
Example 'This example takes the current time; extracts the hour, minute,
'and second; and displays them as the current time.
Sub Main()
xt# = TimeValue(Time$())
xh# = Hour(xt#)
xm# = Minute(xt#)
xs# = Second(xt#)
Msgbox "The current time is: " & CStr(xh#) & ":" & CStr(xm#) _
& ":" & CStr(xs#)
End Sub
See Also Day (function); Minute (function); Month (function); Year (function); Hour
(function); Weekday (function); DatePart (function).
Platform(s) All.
Seek (function)
Syntax Seek(filenumber)
Description Returns the position of the file pointer in a file relative to the beginning of the file.
Comments The filenumber parameter is a number that BasicScript uses to refer to the open file—
the number passed to the Open statement.
The value returned depends on the mode in which the file was opened:
File Mode Returns
Seek (statement)
Syntax Seek [#] filenumber,position
Description Sets the position of the file pointer within a given file such that the next read or write
operation will occur at the specified position.
Select...Case (statement)
Syntax Select Case testexpression
[Case expressionlist
[statement_block]]
[Case expressionlist
[statement_block]]
.
.
[Case Else
[statement_block]]
End Select
Description Used to execute a block of BasicScript statements depending on the value of a given
expression.
Comments The Select Case statement has the following parts:
Part Description
End Sub
See Also Choose (function); Switch (function); IIf (function); If...Then...Else (statement).
Platform(s) All.
SelectBox (function)
Syntax SelectBox([title],prompt,ArrayOfItems [,helpfile,context])
Description Displays a dialog box that allows the user to select from a list of choices and returns an
Integer containing the index of the item that was selected.
Comments The SelectBox statement accepts the following parameters:
Parameter Description
title Title of the dialog box. This can be an expression convertible
to a String. A runtime error is generated if title is Null.
If title is missing, then the default title is used.
prompt Text to appear immediately above the list box containing the
items. This can be an expression convertible to a String. A
runtime error is generated if prompt is Null.
ArrayOfItems Single-dimensioned array. Each item from the array will
occupy a single entry in the list box. A runtime error is
generated if ArrayOfItems is not a single-dimensioned array.
ArrayOfItems can specify an array of any fundamental data
type (structures are not allowed). Null and Empty values are
treated as zero-length strings.
helpfile Name of the file containing context-sensitive help for this
dialog. If this parameter is specified, then context must also
be specified.
context Number specifying the ID of the topic within helpfile for this
dialog's help. If this parameter is specified, then helpfile must
also be specified.
The value returned is an Integer representing the index of the item in the list box that
was selected relative to the lower bound of ArrayOfItems. If the user selects Cancel, a
value 1 less than the lower bound of the array is returned.
If both the helpfile and context parameters are specified, then a Help button is added in
addition to the OK and Cancel buttons. Context-sensitive help can be invoked by
selecting this button or using the help key (F1 on most platforms). Invoking help does
not remove the dialog.
Example 'This example gets the current apps running, puts them in to an
'array and then asks the user to select one from a list.
Sub Main()
Dim a$()
AppList a$
result% = SelectBox("Picker","Pick an application:",a$)
If Not result% = -1 then
Msgbox "User selected: " & a$(result%)
Else
Msgbox "User canceled"
End If
End Sub
See Also MsgBox (statement); AskBox, AskBox$ (functions); AskPassword, AskPassword$
(functions); InputBox, InputBox$ (functions); OpenFileName$ (function);
SaveFileName$ (function); AnswerBox (function).
Platform(s) Windows, Win32, Macintosh, OS/2, UNIX.
SelectButton (statement)
Syntax SelectButton name$ | id
Description Simulates a mouse click on the a push button given the push button's name (the name$
parameter) or ID (the id parameter).
Comments The SelectButton statement accepts the following parameters:
Parameter Description
SelectComboBoxItem (statement)
Syntax SelectComboBoxItem {name$ | id},{ItemName$ | ItemNumber}
[,isDoubleClick]
Description Selects an item from a combo box given the name or ID of the combo box and the name
or line number of the item.
Comments The SelectComboBoxItem statement accepts the following parameters:
Parameter Description
name$ String indicating the name of the combo box containing the
item to be selected.
The name of a combo box is determined by scanning the
window list looking for a text control with the given name that
is immediately followed by a combo box. A runtime error is
generated if a combo box with that name cannot be found
within the active window.
id Integer specifying the ID of the combo box containing the
item to be selected.
ItemName$ String specifying which item is to be selected. The string is
compared without regard to case. If ItemName$ is a
zero-length string, then all currently selected items are
deselected. A runtime error results if ItemName$ cannot be
found in the combo box.
ItemNumber Integer containing the index of the item to be selected. A
runtime error is generated if ItemNumber is not within the
correct range.
isDoubleClick Boolean value indicating whether a double click of that item is
to be simulated.
Note: The SelectComboBoxItem statement is used to set the item of a combo box in
another application's dialog box. Use the DlgText statement to change the content of
the text box part of a list box in a dynamic dialog box.
End Sub
See Also ComboBoxEnabled (function); ComboBoxExists (function); GetComboBoxItem$
(function); GetComboBoxItemCount (function).
Platform(s) Windows.
SelectListBoxItem (statement)
Syntax SelectListBoxItem {name$ | id},{ItemName$ | ItemNumber}
[,isDoubleClick]
Description Selects an item from a list box given the name or ID of the list box and the name or line
number of the item.
Comments The SelectListBoxItem statement accepts the following parameters:
Parameter Description
name$ String indicating the name of the list box containing the item to
be selected.
The name of a list box is determined by scanning the window
list looking for a text control with the given name that is
immediately followed by a list box. A runtime error is
generated if a list box with that name cannot be found within
the active window.
id Integer specifying the ID of the list box containing the item to
be selected.
ItemName$ String specifying which item is to be selected. The string is
compared without regard to case. If ItemName$ is a zero-length
string, then all currently selected items are deselected. A
runtime error results if ItemName$ cannot be found in the list
box.
ItemNumber Integer containing the index of the item to be selected. A
runtime error is generated if ItemNumber is not within the
correct range.
isDoubleClick Boolean value indicating whether a double click of that item is
to be simulated.
The list box must exist within the current window or dialog box; otherwise, a runtime
error will be generated.
For multiselect list boxes, SelectListBoxItem will select additional items (i.e., it will
not remove the selection from the currently selected items).
Example 'This example simulates a double click on the first item in list
'box 1.
Sub Main()
SelectListBoxItem "ListBox1",1,TRUE
End Sub
See Also GetListBoxItem$ (function); GetListBoxItemCount (function); ListBoxEnabled
(function); ListBoxExists (function).
Platform(s) Windows.
SendKeys (statement)
Syntax SendKeys string [, [wait] [,delay]]
Description Sends the specified keys to the active application, optionally waiting for the keys to be
processed before continuing.
Comments The SendKeys statement accepts the following named parameters:
Named Parameter Description
string String containing the keys to be sent. The format for string is
described below.
wait Boolean value. If True, then BasicScript waits for the keys to
be completely processed before continuing. The default value
is False, which causes BasicScript to continue script execution
while before SendKeys finishes.
delay Integer specifying the number of milliseconds devoted for the
output of the entire string parameter. It must be within the
following range:
0 <= delay <= 32767
For example, if delay is 5000 (5 seconds) and the string
parameter contains ten keys, then a key will be output every
1/2 second. If unspecified (or 0), the keys will play back at full
speed.
The SendKeys statement will wait for a prior SendKeys to complete before executing.
Specifying Keys
To specify any key on the keyboard, simply use that key, such as "a" for lowercase a, or
"A" for uppercase a.
Sequences of keys are specified by appending them together: "abc" or "dir /w".
Some keys have special meaning and are therefore specified in a special way—by
enclosing them within braces. For example, to specify the percent sign, use "{%}". The
following table shows the special keys:
Key Special Meaning Example
+ Shift "+{F1}" Shift+F1
^ Ctrl "^a" Ctrl+A
~ Shortcut for Enter "~" Enter
% Alt "%F" Alt+F
[] No special meaning "{[}" Open bracket
{} Used to enclose special keys "{Up}" Up arrow
() Used to specify grouping "^(ab)" Ctrl+A, Ctrl+B
Keys that are not displayed when you press them are also specified within braces, such
as {Enter} or {Up}. A list of these keys follows:
{BkSp} {BS} {Break} {CapsLock} {Clear}
Keys can be combined with Shift, Ctrl, and Alt using the reserved keys "+", "^", and
"%" respectively:
For Key Combination Use
Shift+Enter "+{Enter}"
Ctrl+C "^c"
Alt+F2 "%{F2}"
To specify a modifier key combined with a sequence of consecutive keys, group the key
sequence within parentheses, as in the following example:
For Key Combination Use
Shift+A, Shift+B "+(abc)"
Ctrl+F1, Ctrl+F2 "^({F1}{F2})"
Use "~" as a shortcut for embedding Enter within a key sequence:
For Key Combination Use
a, b, Enter, d, e "ab~de"
Enter, Enter "~~"
To embed quotation marks, use two quotation marks in a row:
For Key Combination Use
"Hello" ""Hello""
a"b"c "a""b""c"
Key sequences can be repeated using a repeat count within braces:
For Key Combination Use
Ten "a" keys "{a 10}"
Two Enter keys "{Enter 2}"
Example 'This example runs Notepad, writes to Notepad, and saves the new
'file using the SendKeys statement.
Sub Main()
id = Shell("[Link]")
AppActivate "Notepad"
SendKeys "Hello, Notepad.",True 'Write some text.
SendKeys "%fs",True 'Save File as "[Link]"
SendKeys "[Link]{ENTER}",True
AppClose "Notepad"
End Sub
See Also DoKeys (statement); QueKeys (statement); QueKeyDn (statement); QueKeyUp
(statement).
Set (statement)
Syntax 1 Set object_var = object_expression
Syntax 2
In the second syntax, the object variable is being assigned to a new instance of an
existing object type. This syntax is valid only for data objects.
When an object created using the New keyword goes out of scope (i.e., the Sub or
Function in which the variable is declared ends), the object is destroyed.
Syntax 3
The reserved keyword Nothing is used to make an object variable reference no object.
At a later time, the object variable can be compared to Nothing to test whether the
object variable has been instantiated:
Set a = Nothing
:
If a Is Nothing Then Beep
Example 'This example creates two objects and sets their values.
Sub Main()
Dim document As Object
Dim page As Object
Set document = GetObject("c:\[Link]")
SetAttr (statement)
Syntax SetAttr pathname, attributes
Description Changes the attribute pathname to the given attribute. A runtime error results if the file
cannot be found.
Comments The SetAttr statement accepts the following named parameters:
Named Parameter Description
pathname String containing the name of the file.
attributes Integer specifying the new attribute of the file.
The attributes parameter can contain any combination of the following values:
Constant Value Includes
Platform(s) All.
Platform Notes Windows: Under Windows, these attributes are the same as those used by DOS.
UNIX: On UNIX platforms, the hidden file attribute corresponds to files without the
read or write attributes.
SetCheckBox (statement)
Syntax SetCheckBox {name$ | id},state
Description Sets the state of the check box with the given name or ID.
Comments The SetCheckBox statement accepts the following parameters:
Parameter Description
name$ String containing the name of the check box to be set.
id Integer specifying the ID of the check box to be set.
state Integer indicating the new state of the check box. If state is 1,
then the box is checked. If state is 0, then the check is
removed. If state is 2, then the box is dimmed (only applicable
for three-state check boxes).
A runtime error is generated if a check box with the specified name cannot be found in
the active window.
This statement has the side effect of setting the focus to the given check box.
Note: The SetCheckBox statement is used to set the state of a check box in another
application's dialog box. Use the DlgValue statement to modify the state of a check
box within a dynamic dialog box.
SetEditText (statement)
Syntax SetEditText {name$ | id},content$
Description Sets the content of an edit control given its name or ID.
Comments The SetEditText statement accepts the following parameters:
Parameter Description
name$ String containing the name of the text box to be set.
The name of a text box control is determined by scanning the
window list looking for a text control with the given name that
is immediately followed by an edit control. A runtime error is
generated if a text box control with that name cannot be found
within the active window.
id Integer specifying the ID of the text box to be set.
For text boxes that do not have a preceding text control, the id
can be used to absolutely reference the control. The id is
determined by examining the dialog box with a resource editor
or using an application such as Spy.
content$ String containing the new content for the text box.
This statement has the side effect of setting the focus to the given text box.
Note: The SetEditText statement is used to set the content of a text box in another
application's dialog box. Use the DlgText statement to set the text of a text box
within a dynamic dialog box.
Example 'This example sets the content of the filename text box of the
'current window to "[Link]".
Sub Main()
SetEditText "Filename:","[Link]"
End Sub
SetOption (statement)
Syntax SetOption name$ | id
Description Selects the specified option button given its name or ID.
Comments The SetOption statement accepts the following parameters:
Parameter Description
name$ String containing the name of the option button to be selected.
Parameter Description
id Integer containing the ID of the option button to be selected.
A runtime error is generated if the option button cannot be found within the active
window.
Sgn (function)
Syntax Sgn(number)
Description Returns an Integer indicating whether a number is less than, greater than, or equal to 0.
Comments Returns 1 if number is greater than 0.
Returns 0 if number is equal to 0.
Returns –1 if number is less than 0.
The number parameter is a numeric expression of any type. If number is Null, then a
runtime error is generated. Empty is treated as 0.
Example 'This example tests the product of two numbers and displays a
'message based on the sign of the result.
Sub Main()
a% = -100
b% = 100
c% = a% * b%
Select Case Sgn(c%)
Case -1
MsgBox "The product is negative " & Sgn(c%)
Case 0
MsgBox "The product is 0 " & Sgn(c%)
Case 1
MsgBox "The product is positive " & Sgn(c%)
End Select
End Sub
See Also Abs (function).
Platform(s) All.
Shell (function)
Syntax Shell(pathname [,windowstyle])
Sub Main()
id = Shell("[Link]",1)
AppActivate "Clock"
Sleep(2000)
AppClose "Clock"
End Sub
See Also PrintFile (function); SendKeys (statement); AppActivate (statement).
Platform(s) All.
Platform Notes Windows: Under Windows, this function returns the hInstance of the application. Since
this value is only a WORD in size, the upper WORD of the result is always zero.
The Shell function under Windows supports file associations. In other words, you can
specify the name of a file, and the Shell function executes the associated application
with that file as a parameter. (File associations are specified in the [Link] file.)
Win32: Under Win32, this function returns a global process ID that can be used to
identify the new process. Under Win32, the Shell function does not support file
associations (i.e., setting pathname to "[Link]" will not execution Notepad).
When specifying long filenames as parameters, you may have to enclose the parameters
in double quotes. For example, under Windows 95, to run WordPad, passing it a file
called "Sample Document", you would use the following statement:
r = Shell("WordPad ""Sample Document""")
Macintosh: The Macintosh does not support wildcard characters such as * and ?. These
are valid filename characters. Instead of wildcards, the Macintosh uses the MacID
function to specify a collection of files of the same type. The syntax for this function is:
Shell(MacID(text$) [,windowstyle])
The text$ parameter is a four-character string containing an application signature. A
runtime error occurs if the MacID function is used on platforms other than the
Macintosh.
On the Macintosh, the windowstyle parameter only specifies whether the application
receives the focus.
UNIX: Under all versions of UNIX, the windowstyle parameter is ignored. This
function returns the process identifier of the new process.
Under UNIX, BasicScript attempts to execute the command line using one of the
installed shells. BasicScript looks for a shell using the following precedence:
1. BasicScript examines the SHELL environment variable, which is normally set to
the path of the currently executing shell (e.g., /bin/sh, /bin/csh, and so on).
2. BasicScript examines the PATH environment variable for an executable program
called sh (the Bourne shell).
3. In the unlikely event that a shell was not located with the above rules, BasicScript
will search for sh in the following areas:
/bin
/usr/bin
/usr/sbin
Once a suitable shell has been located, it is executed with pathname as a parameter. The
environment of the calling process is made available to the new process and will be use
by the shell in a manner specific to that shell.
Due to the asynchronous nature of the shell process, failure to find and start the program
is not reported to BasicScript.
OS/2: Under OS/2, the Shell function is capable of running both Presentation Manager
applications and command line applications. When running command line applications,
the Shell function always returns 0.
Sin (function)
Syntax Sin(number)
Description A data type used to declare variables capable of holding real numbers with up to seven
digits of precision.
Comments Single variables are used to hold numbers within the following ranges:
Sign Range
Negative -3.402823E38 <= single <= -1.401298E-45
Positive 1.401298E-45 <= single <= 3.402823E38
Storage
Internally, singles are stored as 4-byte (32-bit) IEEE values. Thus, when appearing
within a structure, singles require 4 bytes of storage. When used with binary or random
files, 4 bytes of storage is required.
Each single consists of the following
• A 1-bit sign
• An 8-bit exponent
• A 24-bit mantissa
See Also Currency (data type); Date (data type); Double (data type); Integer (data type); Long
(data type); Object (data type); String (data type); Variant (data type); Boolean (data
type); DefType (statement); CSng (function).
Platform(s) All.
Sleep (statement)
Syntax Sleep milliseconds
Platform(s) All.
Platform Notes Windows: Under Windows, the accuracy of the system clock is modulo 55
milliseconds. The value of milliseconds will, in the worst case, be rounded up to the
nearest multiple of 55. In other words, if milliseconds is 1, it will be rounded to 55 in the
worst case.
Sln (function)
Syntax Sln(cost, salvage, life)
Description Returns the straight-line depreciation of an asset assuming constant benefit from the
asset.
Comments The Sln of an asset is found by taking an estimate of its useful life in years, assigning
values to each year, and adding up all the numbers.
The formula used to find the Sln of an asset is as follows:
(Cost - Salvage Value) / Useful Life
The Sln function requires the following named parameters:
Named Parameter Description
cost Double representing the initial cost of the asset.
salvage Double representing the estimated value of the asset at the end
of its useful life.
life Double representing the length of the asset's useful life.
The unit of time used to express the useful life of the asset is the same as the unit of time
used to express the period for which the depreciation is returned.
Example 'This example calculates the straight-line depreciation of an
'asset that cost $10,000.00 and has a salvage value of $500.00
'as scrap after ten years of service life.
Sub Main()
dep# = Sln(10000.00,500.00,10)
MsgBox "The annual depreciation is: " &
Format(dep#,"Currency")
End Sub
Spc (function)
Syntax Spc(numspaces)
Description Prints out the specified number of spaces. This function can only be used with the Print
and Print# statements.
Comments The numspaces parameter is an Integer specifying the number of spaces to be printed.
It can be any value between 0 and 32767.
If a line width has been specified (using the Width statement), then the number of
spaces is adjusted as follows:
numspaces = numspaces Mod width
If the resultant number of spaces is greater than width – print_position, then the number
of spaces is recalculated as follows:
numspaces = numspaces – (width – print_position)
These calculations have the effect of never allowing the spaces to overflow the line
length. Furthermore, with a large value for column and a small line width, the file
pointer will never advance more than one line.
Example 'This example displays 20 spaces between the arrows.
Sub Main()
[Link]
Print "I am"; Spc(20); "20 spaces apart!"
Sleep (10000)'Wait 10 seconds.
[Link]
End Sub
See Also Tab (function); Print (statement); Print# (statement).
Platform(s) All.
SQLBind (function)
Syntax SQLBind(connectionnum, array [,column])
Description Specifies which fields are returned when results are requested using the SQLRetrieve
or SQLRetrieveToFile function.
Comments The following table describes the named parameters to the SQLBind function:
Named Parameter Description
connectionnum Long parameter specifying a valid connection.
array Any array of variants. Each call to SQLBind adds a new
column number (an Integer) in the appropriate slot in the array.
Thus, as you bind additional columns, the array parameter
grows, accumulating a sorted list (in ascending order) of bound
columns.
If array is fixed, then it must be a one-dimensional variant array
with sufficient space to hold all the bound column numbers. A
runtime error is generated if array is too small.
If array is dynamic, then it will be resized to exactly hold all the
bound column numbers.
column Optional Long parameter that specifies the column to which to
bind data. If this parameter is omitted, all bindings for the
connection are dropped.
This function returns the number of bound columns on the connection. If no columns
are bound, then 0 is returned. If there are no pending queries, then calling SQLBind
will cause an error (queries are initiated using the SQLExecQuery function).
If supported by the driver, row numbers can be returned by binding column 0.
BasicScript generates a trappable runtime error if SQLBind fails. Additional error
information can then be retrieved using the SQLError function.
Example 'This example binds columns to data.
Sub Main()
Dim columns() As Variant
id& = SQLOpen("dsn=SAMPLE",,3)
t& = SQLExecQuery(id&,"Select * From c:\[Link]")
i% = SQLBind(id&,columns,3)
i% = SQLBind(id&,columns,1)
i% = SQLBind(id&,columns,2)
i% = SQLBind(id&,columns,6)
For x = 0 To (i% - 1)
MsgBox columns(x)
Next x
id& = SQLClose(id&)
End Sub
See Also SQLRetrieve (function); SQLRetrieveToFile (function).
Platform(s) Windows, Win32.
SQLClose (function)
Syntax SQLClose(connectionnum)
SQLError (function)
Syntax SQLError(resultarray, connectionnum )
Description Retrieves driver-specific error information for the most recent SQL functions that failed.
Comments This function is called after any other SQL function fails. Error information is returned
in a two-dimensional array (resultarray). The following table describes the named
parameters to the SQLError function:
Named Parameter Description
resultarray Two-dimensional Variant array, which can be dynamic or fixed.
If the array is fixed, it must be (x,3), where x is the number of
errors you want returned. If x is too small to hold all the errors,
then the extra error information is discarded. If x is greater than
the number of errors available, all errors are returned, and the
empty array elements are set to Empty.
If the array is dynamic, it will be resized to hold the exact
number of errors.
connectionnum Optional Long parameter specifying a connection ID. If this
parameter is omitted, error information is returned for the most
recent SQL function call.
Each array entry in the resultarray parameter describes one error. The three elements in
each array entry contain the following information:
Element Value
(entry,0) The ODBC error state, indicated by a Long containing the error
class and subclass.
(entry,1) The ODBC native error code, indicated by a Long.
(entry,2) The text error message returned by the driver. This field is String
type.
For example, to retrieve the ODBC text error message of the first returned error, the
array is referenced as:
resultarray(0,2)
The SQLError function returns the number of errors found.
BasicScript generates a runtime error if SQLError fails. (You cannot use the
SQLError function to gather additional error information in this case.)
Example 'This example forces a connection error and traps it for use
'with the SQLError function.
Sub Main()
Dim a() As Variant
On Error Goto Trap
id& = SQLOpen("",,4)
id& = SQLClose(id&)
Exit Sub
Trap:
rc% = SQLError(a)
If (rc%) Then
For x = 0 To (rc% - 1)
MsgBox "The SQLState returned was: " & a(x,0)
MsgBox "The native error code returned was: " & a(x,1)
MsgBox a(x,2)
Next x
End If
End Sub
Platform(s) Windows, Win32.
SQLExecQuery (function)
Syntax SQLExecQuery(connectionnum, querytext)
SQLGetSchema (function)
Syntax SQLGetSchema(connectionnum, typenum, [, [resultarray] [, qualifiertext]])
Description Returns information about the data source associated with the specified connection.
Comments The following table describes the named parameters to the SQLGetSchema function:
Named Parameter Description
connectionnum Long parameter identifying a valid connected data source. This
parameter is returned by the SQLOpen function.
SQLOpen (function)
Syntax SQLOpen(connectionstr [, [outputref] [, driverprompt]])
Description Establishes a connection to the specified data source, returning a Long representing the
unique connection ID.
Comments This function connects to a data source using a login string (connectionstr) and
optionally sets the completed login string (outputref) that was used by the driver. The
following table describes the named parameters to the SQLOpen function:
Named Parameter Description
connectionstr String expression containing information required by the driver
to connect to the requested data source. The syntax must strictly
follow the driver's SQL syntax.
outputref Optional String variable that will receive a completed
connection string returned by the driver. If this parameter is
missing, then no connection string will be returned.
driverprompt Integer expression specifying any of the following values:
Value Meaning
1 The driver's login dialog box is always
displayed.
2 The driver's dialog box is only displayed
if the connection string does not contain
enough information to make the
connection. This is the default behavior.
3 The driver's dialog box is only displayed
if the connection string does not contain
enough information to make the
connection. Dialog box options that were
passed as valid parameters are dimmed
and unavailable.
4 The driver's login dialog box is never
displayed.
The SQLOpen function will never return an invalid connection ID. The following
example establishes a connection using the driver's login dialog box:
id& = SQLOpen("",,1)
BasicScript returns 0 and generates a trappable runtime error if SQLOpen fails.
Additional error information can then be retrieved using the SQLError function.
Before you can use any SQL statements, you must set up a data source and relate an
existing database to it. This is accomplished using the [Link] program.
Example 'This example connects the data source called "sample,"
'returning the completed connction string, and then displays it.
Sub Main()
Dim s As String
id& = SQLOpen("dsn=SAMPLE",s$,3)
MsgBox "The completed connection string is: " & s$
id& = SQLClose(id&)
End Sub
SQLRequest (function)
Syntax SQLRequest(connectionstr, querytext, resultarray [, [outputref] [,
[driverprompt] [, colnameslogical]]])
Description Opens a connection, runs a query, and returns the results as an array.
Comments The SQLRequest function takes the following named parameters:
Named Parameter Description
SQLRetrieve (function)
Syntax SQLRetrieve(connectionnum , resultarray[, [maxcolumns] [, [ maxrows] [,
[colnameslogical] [, fetchfirstlogical]]]])
Description Retrieves the results of a query.
Comments This function is called after a connection to a data source is established, a query is
executed, and the desired columns are bound. The following table describes the named
parameters to the SQLRetrieve function:
Named Parameter Description
connectionnum Long identifying a valid connected data source with pending
query results.
resultarray Two-dimensional array of variants to receive the results. The
array has x rows by y columns. The number of columns is
determined by the number of bindings on the connection.
maxcolumns Optional Integer expression specifying the maximum number
of columns to be returned. If maxcolumns is greater than the
number of columns bound, the additional columns are set to
empty. If maxcolumns is less than the number of bound results,
the rightmost result columns are discarded until the result fits.
maxrows Optional Integer specifying the maximum number of rows to
be returned. If maxrows is greater than the number of rows
available, all results are returned, and additional rows are set to
empty. If maxrows is less than the number of rows available,
the array is filled, and additional results are placed in memory
for subsequent calls to SQLRetrieve.
colnameslogical Optional Boolean specifying whether column names should
be returned as the first row of results. The default is False.
fetchfirstlogical Optional Boolean expression specifying whether results are
retrieved from the beginning of the result set. The default is
False.
Before you can retrieve the results from a query, you must (1) initiate a query by calling
the SQLExecQuery function and (2) specify the fields to retrieve by calling the
SQLBind function.
This function returns a Long specifying the number of rows available in the array.
BasicScript generates a runtime error if SQLRetrieve fails. Additional error
information is placed in memory.
Example 'This example executes a query on the connected data source,
'binds columns, and retrieves them.
Sub Main()
Dim a() As Variant
Dim b() As Variant
Dim c() As Variant
On Error Goto Trap
id& = SQLOpen("DSN=SAMPLE",,3)
qry& = SQLExecQuery(id&,"Select * From c:\[Link]"")
i% = SQLBind(id&,b,3)
i% = SQLBind(id&,b,1)
i% = SQLBind(id&,b,2)
i% = SQLBind(id&,b,6)
l& = SQLRetrieve(id&,c)
For x = 0 To Ubound(c)
For y = 0 To l& - 1
MsgBox c(x,y)
Next y
Next x
id& = SQLClose(id&)
Exit Sub
Trap:
rc% = SQLError(a)
If (rc%) Then
For x = 0 To (rc% - 1)
MsgBox "The SQLState returned was: " & a(x,0)
MsgBox "The native error code returned was: " & a(x,1)
MsgBox a(x,2)
Next x
End If
End Sub
SQLRetrieveToFile (function)
Syntax SQLRetrieveToFile(connectionnum, destination [, [colnameslogical] [,
columndelimiter]])
Description Retrieves the results of a query and writes them to the specified file.
Comments The following table describes the named parameters to the SQLRetrieveToFile
function:
Named Parameter Description
connectionnum Long specifying a valid connection ID.
destination String specifying the file where the results are written.
colnameslogical Optional Boolean specifying whether the first row of results
returned are the bound column names. By default, the column
names are not returned.
columndelimiter Optional String specifying the column separator. A tab
(Chr$(9)) is used as the default.
Before you can retrieve the results from a query, you must (1) initiate a query by calling
the SQLExecQuery function and (2) specify the fields to retrieve by calling the
SQLBind function.
This function returns the number of rows written to the file. A runtime error is generated
if there are no pending results or if BasicScript is unable to open the specified file.
BasicScript generates a runtime error if SQLRetrieveToFile fails. Additional error
information may be placed in memory for later use with the SQLError function.
Example 'This example opens a connection, runs a query, binds columns,
'and writes the results to a file.
Sub Main()
Dim a() As Variant
Dim b() As Variant
On Error Goto Trap
id& = SQLOpen("DSN=SAMPLE;UID=RICH",,4)
t& = SQLExecQuery(id&, "Select * From c:\[Link]"")
i% = SQLBind(id&,b,3)
i% = SQLBind(id&,b,1)
i% = SQLBind(id&,b,2)
i% = SQLBind(id&,b,6)
l& = SQLRetrieveToFile(id&,"c:\[Link]",True,",")
id& = SQLClose(id&)
Exit Sub
Trap:
rc% = SQLError(a)
If (rc%) Then
For x = 0 To (rc-1)
MsgBox "The SQLState returned was: " & a(x,0)
MsgBox "The native error code returned was: " & a(x,1)
MsgBox a(x,2)
Next x
End If
End Sub
Sqr (function)
Syntax Sqr(number)
Example 'This example calculates the square root of the numbers from 1
'to 10 and displays them.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
For x = 1 To 10
sx# = Sqr(x)
message = message & Format(x,"Fixed") & " - " _
& Format(sx#,"Fixed") & crlf
Next x
MsgBox message
End Sub
Platform(s) All.
Stop (statement)
Syntax Stop
Description Suspends execution of the current script, returning control to a debugger if one is
present. If a debugger is not present, this command will have the same effect as End.
Example 'The Stop statement can be used for debugging. In this example,
'it is used to stop execution when Z is randomly set to 0.
Sub Main()
For x = 1 To 10
z = Random(0,10)
If z = 0 Then Stop
y = x / z
Next x
End Sub
See Also Exit For (statement); Exit Do (statement); Exit Function (statement); Exit Sub
(statement); End (statement).
Platform(s) All.
Singles are printed using only 7 significant digits. Doubles are printed using 15–16
significant digits.
These functions only output the period as the decimal separator and do not output
thousands separators. Use the CStr, Format, or Format$ function for this purpose.
Example 'In this example, the Str$ function is used to display the
'value of a numeric variable.
Sub Main()
x# = 100.22
MsgBox "The string value is: " + Str(x#)
End Sub
See Also Format, Format$ (functions); CStr (function).
Platform(s) All.
StrComp (function)
Syntax StrComp(string1,string2 [,compare])
Description Returns an Integer indicating the result of comparing the two string arguments.
Comments One of the following values is returned:
0 string1 = string2
1 string1 > string2
–1 string1 < string2
Null string1 or string2 is Null
Parameter Description
If compare is not specified, then the current Option Compare
setting is used. If no Option Compare statement has been
encountered, then Binary is used (i.e., string comparison is
case-sensitive).
Example 'This example compares two strings and displays the results. It
'illustrates that the function compares two strings to the
'length of the shorter string in determining equivalency.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = "This string is UPPERCASE and lowercase"
b$ = "This string is uppercase and lowercase"
c$ = "This string"
d$ = "This string is uppercase and lowercase characters"
abc = StrComp(a$,b$,0)
message = message & "a and c (sensitive) : " & _
Format(abc,"True/False") & crlf
abi = StrComp(a$,b$,1)
message = message & "a and b (insensitive): " & _
Format(abi,"True/False") & crlf
aci = StrComp(a$,c$,1)
message = message & "a and c (insensitive): " & _
Format(aci,"True/False") & crlf
bdi = StrComp(b$,d$,1)
message = message & "b and d (sensitive) : " & _
Format(bdi,"True/False") & crlf
MsgBox message
End Sub
See Also Comparison Operators (topic); Like (operator); Option Compare (statement).
Platform(s) All.
StrConv (function)
Syntax StrConv(string, conversion)
A runtime error is generated when a conversion is requested that is not supported on the
current platform. For example, the ebWide and ebNarrow constants can only be used
on an MBCS platform. (You can determine platform capabilities using the
[Link] method.)
The following groupings of constants are mutually exclusive and therefore cannot be
specified at the same time:
ebUpperCase, ebLowerCase, ebProperCase
ebWide, ebNarrow
ebUnicode, ebFromUnicode
Many of the constants can be combined. For example, ebLowerCase Or ebNarrow.
When converting to proper case (i.e., the ebProperCase constant), the following are
seen as word delimiters: tab, linefeed, carriage-return, formfeed, vertical tab, space,
null.
Example Sub Main()
a = InputBox("Type any string:")
MsgBox "Upper case: " & StrConv(a,ebUpperCase)
MsgBox "Lower case: " & StrConv(a,ebLowerCase)
MsgBox "Proper case: " & StrConv(a,ebProperCase)
If [Link](10) And [Link] = ebWin16 Then
'This is an MBCS locale
MsgBox "Narrow: " & StrConv(a,ebNarrow)
MsgBox "Wide: " & StrConv(a,ebWide)
MsgBox "Katakana: " & StrConv(a,ebKatakana)
MsgBox "Hiragana: " & StrConv(a,ebHiragana)
End If
End Sub
See Also UCase, UCase$ (functions); LCase, LCase$ (functions); [Link] (method).
Platform(s) All.
Description Returns a string of length number consisting of a repetition of the specified filler
character.
Comments String$ returns a String, whereas String returns a String variant.
Part Description
the value of that variable in the caller. If the parameter is declared using the ByVal
keyword, then the value of that variable cannot be changed in the called subroutine. If
neither the ByRef nor the ByVal keyword is specified, then the parameter is passed by
reference.
You can override passing a parameter by reference by enclosing that parameter within
parentheses. For instance, the following example passes the variable j by reference,
regardless of how the third parameter is declared in the arglist of UserSub:
UserSub 10,12,(j)
Optional Parameters
BasicScript allows you to skip parameters when calling subroutines, as shown in the
following example:
Sub Test(a%,b%,c%)
End Sub
Sub Main
Test 1,,4 'Parameter 2 was skipped.
End Sub
You can skip any parameter with the following restrictions:
1. The call cannot end with a comma. For instance, using the above example, the
following is not valid:
Test 1,,
2. The call must contain the minimum number of parameters as required by the called
subroutine. For instance, using the above example, the following are invalid:
Test ,1 'Only passes two out of three required
'parameters.
Test 1,2 'Only passes two out of three required
'parameters.
When you skip a parameter in this manner, BasicScript creates a temporary variable and
passes this variable instead. The value of this temporary variable depends on the data
type of the corresponding parameter in the argument list of the called subroutine, as
described in the following table:
Value Data Type
0 Integer, Long, Single, Double, Currency
Zero-length string String
Nothing Object (or any data object)
Error Variant
December 30, 1899 Date
False Boolean
Within the called subroutine, you will be unable to determine whether a parameter was
skipped unless the parameter was declared as a variant in the argument list of the
subroutine. In this case, you can use the IsMissing function to determine whether the
parameter was skipped:
Sub Test(a,b,c)
If IsMissing(a) Or IsMissing(b) Then Exit Sub
End Sub
Switch (function)
Syntax Switch(condition1,expression1 [,condition2,expression2 ...
[,condition7,expression7]])
Description Returns the expression corresponding to the first True condition.
Comments The Switch function evaluates each condition and expression, returning the expression
that corresponds to the first condition (starting from the left) that evaluates to True. Up
to seven condition/expression pairs can be specified.
A runtime error is generated it there is an odd number of parameters (i.e., there is a
condition without a corresponding expression).
The Switch function returns Null if no condition evaluates to True.
Example 'This code fragment displays the current operating platform. If
'the platform is unknown, then the word "Unknown" is displayed.
Sub Main()
Dim a As Variant
a = Switch([Link] = 0,"Windows 3.1", _
[Link] = 2,"Win32",[Link] = 11,"OS/2")
MsgBox "The current platform is: " & _
IIf(IsNull(a),"Unknown",a)
End Sub
SYD (function)
Syntax SYD(cost, salvage, life, period)
Description Returns the sum of years' digits depreciation of an asset over a specific period of time.
Comments The SYD of an asset is found by taking an estimate of its useful life in years, assigning
values to each year, and adding up all the numbers.
The formula used to find the SYD of an asset is as follows:
(Cost – Salvage_Value) * Remaining_Useful_Life / SYD
The SYD function requires the following named parameters:
Named Parameter Description
cost Double representing the initial cost of the asset.
salvage Double representing the estimated value of the asset at the end
of its useful life.
life Double representing the length of the asset's useful life.
period Double representing the period for which the depreciation is to
be calculated. It cannot exceed the life of the asset.
To receive accurate results, the parameters life and period must be expressed in the same
units. If life is expressed in terms of months, for example, then period must also be
expressed in terms of months.
Example 'In this example, an asset that cost $1,000.00 is depreciated
'over ten years. The salvage value is $100.00, and the sum of
'the years' digits depreciation is shown for each year.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
For x = 1 To 10
dep# = SYD(1000,100,10,x)
message = message & "Year: " & x & " Dep: " _
& Format(dep#,"Currency") & crlf
Next x
MsgBox message
End Sub
[Link] (method)
Syntax [Link]
[Link] (property)
Syntax [Link]
[Link] (property)
Syntax [Link]
Sub Main()
FreeRes% = [Link]
MsgBox FreeRes% & "% of memory resources available."
End Sub
[Link] (method)
Syntax [Link] isOn
[Link] (method)
Syntax [Link]
[Link] (property)
Syntax [Link]
Description Returns a Long representing the number of bytes of available free memory in Windows.
Example 'This example displays the total system memory.
Sub Main()
TotMem& = [Link]
TotKBytes$ = Format(TotMem& / 1000,"##,###")
MsgBox TotKbytes$ & " Kbytes of total system memory exist"
End Sub
[Link]$ (property)
Syntax [Link]$
[Link]$ (property)
Syntax [Link]$
Description Returns the version of the operating environment, such as "3.0" or "3.1."
Example 'This example sets the UseWin31 variable to True if the Windows
Tab (function)
Syntax Tab (column)
Description Prints the number of spaces necessary to reach a given column position.
Comments This function can only be used with the Print and Print# statements.
The column parameter is an Integer specifying the desired column position to which to
advance. It can be any value between 0 and 32767 inclusive.
Rule 1: If the current print position is less than or equal to column, then the number of
spaces is calculated as:
column – print_position
Rule 2: If the current print position is greater than column, then column – 1 spaces are
printed on the next line.
If a line width is specified (using the Width statement), then the column position is
adjusted as follows before applying the above two rules:
column = column Mod width
The Tab function is useful for making sure that output begins at a given column
position, regardless of the length of the data already printed on that line.
Example 'This example prints three column headers and three numbers
'aligned below the column headers.
Sub Main()
[Link]
Print "Column1";Tab(10);"Column2";Tab(20);"Column3"
Print Tab(3);"1";Tab(14);"2";Tab(24);"3"
Sleep(10000) 'Wait 10 seconds.
[Link]
End Sub
Tan (function)
Syntax Tan(number)
c# = Tan(Pi / 4)
MsgBox "The tangent of 45 degrees is: " & c#
End Sub
Text (statement)
Syntax Text x,y,width,height,title$ [,[.Identifier] [,[FontName$] [,[size]
[,style]]]]
Description Defines a text control within a dialog box template. The text control only displays text;
the user cannot set the focus to a text control or otherwise interact with it.
Comments The text within a text control word-wraps. Text controls can be used to display up to
32K of text.
The Text statement accepts the following parameters:
Parameter Description
x, y Integer positions of the control (in dialog units) relative to the
upper left corner of the dialog box.
width, height Integer dimensions of the control in dialog units.
title$ String containing the text that appears within the text control.
This text may contain an ampersand character to denote an
accelerator letter, such as "&Save" for Save. Pressing this
accelerator letter sets the focus to the control following the Text
statement in the dialog box template.
.Identifier Name by which this control can be referenced by statements in a
dialog function (such as DlgFocus and DlgEnable). If this
parameter is omitted, then the first two words from title$ are
used.
FontName$ Name of the font used for display of the text within the text
control. If this parameter is omitted, then the default font for the
dialog is used.
size Size of the font used for display of the text within the text
control. If this parameter is omitted, then the default size for the
default font of the dialog is used.
Parameter Description
style Style of the font used for display of the text within the text
control. This can be any of the following values:
ebRegular Normal font (i.e., neither bold nor italic)
ebBold Bold font
ebItalic Italic font
ebBoldItalic Bold-italic font
If this parameter is omitted, then ebRegular is used.
Example Begin Dialog UserDialog3 81,64,128,60,"Untitled"
CancelButton 80,32,40,14
OKButton 80,8,40,14
Text 4,8,68,44,"This text is displayed in the dialog box."
End Dialog
TextBox (statement)
Syntax TextBox x,y,width,height,.Identifier [,[isMultiline] [,[FontName$] [,[size]
[,style]]]]
Description Defines a single or multiline text-entry field within a dialog box template.
Value Meaning
oldtime$ = Time$
message = "Time was: " & oldtime$ & crlf
Time$ = "10:30:54"
message = message & "Time set to: " & Time$ & crlf
Time$ = oldtime$
message = message & "Time restored to: " & Time$
MsgBox message
End Sub
See Also Time, Time$ (statements); Date, Date$ (functions); Date, Date$ (statements); Now
(function).
Platform(s) All.
Description Sets the system time to the time contained in the specified string.
Comments The Time$ statement requres a string variable in one of the following formats:
HH
HH:MM
HH:MM:SS
where HH is between 0 and 23, MM is between 0 and 59, and SS is between 0 and 59.
The Time statement converts any valid expression to a time, including string and
numeric values. Unlike the Time$ statement, Time recognizes many different time
formats, including 12-hour times.
Example 'This example returns the system time and displays it in a
'dialog box.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
oldtime$ = Time$
message = "Time was: " & oldtime$ & crlf
Time$ = "10:30:54"
message = message & "Time set to: " & Time$ & crlf
Time$ = oldtime$
message = message & "Time restored to: " & Time$
MsgBox message
End Sub
See Also Time, Time$ (functions); Date, Date$ (functions); Date, Date$ (statements).
Platform(s) All.
Platform Notes UNIX, Win32, OS/2: On all UNIX platforms, Win32, and OS/2, you may not have
permission to change the time, causing runtime error 70 to be generated.
Timer (function)
Syntax Timer
Description Returns a Single representing the number of seconds that have elapsed since midnight.
Example 'This example displays the elapsed time between execution start
'and the time you clicked the OK button on the first message.
Sub Main()
start& = Timer
MsgBox "Click the OK button, please."
total& = Timer - start&
MsgBox "The elapsed time was: " & total& & " seconds."
End Sub
TimeSerial (function)
Syntax TimeSerial(hour, minute, second)
Description Returns a Date variant representing the given time with a date of zero.
Comments The TimeSerial function requires the following named parameters:
Named Parameter Description
hour Integer between 0 and 23.
minute Integer between 0 and 59.
second Integer between 0 and 59.
Example Sub Main()
start# = TimeSerial(10,22,30)
finish# = TimeSerial(10,35,27)
dif# = Abs(start# - finish#)
MsgBox "The time difference is: " & Format(dif#, "hh:mm:ss")
End Sub
See Also DateValue (function); TimeValue (function); DateSerial (function).
Platform(s) All.
TimeValue (function)
Syntax TimeValue(time)
Description Returns a Date variant representing the time contained in the specified string argument.
Comments This function interprets the passed time parameter looking for a valid time specification.
The time parameter can contain valid time items separated by time separators such as
colon (:) or period (.).
Time strings can contain an optional date specification, but this is not used in the
formation of the returned value.
If a particular time item is missing, then it is set to 0. For example, the string "10 pm"
would be interpreted as "22:00:00."
Example 'This example calculates the current time and displays it in a
'dialog box.
Sub Main()
t1$ = "10:15"
t2# = TimeValue(t1$)
MsgBox "The TimeValue of " & t1$ & " is: " & t2#
End Sub
See Also DateValue (function); TimeSerial (function); DateSerial (function).
Platform(s) All.
Platform Notes Windows: Under Windows, time specifications vary, depending on the international
settings contained in the [intl] section of the [Link] file.
Examples 'This first example uses the Trim$ function to extract the
'nonblank part of a string and display it.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
text$ = " This is text "
tr$ = Trim$(text$)
MsgBox "Original =>" & text$ & "<=" & crlf & _
"Trimmed =>" & tr$ & "<="
End Sub
'This second example displays a right-justified string and its
'LTrim result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = " <= This is a right-justified string"
b$ = LTrim$(a$)
MsgBox a$ & crlf & b$
End Sub
'This third example displays a left-justified string and its
'RTrim result.
Const crlf = Chr$(13) + Chr$(10)
Sub Main()
a$ = "This is a left-justified string. "
b$ = RTrim$(a$)
MsgBox a$ & "<=" & crlf & b$ & "<="
End Sub
Platform(s) All.
Type (statement)
Syntax Type username
variable As type
variable As type
variable As type
:
End Type
Description The Type statement creates a structure definition that can then be used with the Dim
statement to declare variables of that type. The username field specifies the name of the
structure that is used later with the Dim statement.
Comments Within a structure definition appear field descriptions in the format:
variable As type
where variable is the name of a field of the structure, and type is the data type for that
variable. Any fundamental data type or previously declared user-defined data type can
be used within the structure definition (structures within structures are allowed). Only
fixed arrays can appear within structure definitions.
The Type statement can only appear outside of subroutine and function declarations.
When declaring strings within fixed-size types, it is useful to declare the strings as
fixed-length. Fixed-length strings are stored within the structure itself rather than in the
string space. For example, the following structure will always require 62 bytes of
storage:
Type Person
FirstName As String * 20
LastName As String * 40
Age As Integer
End Type
Note: Fixed-length strings within structures are size-adjusted upward to an even byte
boundary. Thus, a fixed-length string of length 5 will occupy 6 bytes of storage
within the structure.
Example 'This example displays the use of the Type statement to create
'a structure representing the parts of a circle and assign
'values to them.
Type Circ
message As String
rad As Integer
dia As Integer
are As Double
cir As Double
End Type
Sub Main()
Dim circle As Circ
[Link] = 5
[Link] = [Link] * 2
[Link] = ([Link] ^ 2) * Pi
[Link] = [Link] * Pi
[Link] = "The area of the circle is: " & [Link]
MsgBox [Link]
End Sub
TypeName (function)
Syntax TypeName(varname)
"String" A String.
objecttype A data object variable. In this case, objecttype is the name of
the specific object type.
"Integer" An integer.
"Long" A long.
"Single" A single.
"Double" A double.
"Currency" A currency value.
"Date" A date value.
"Boolean" A boolean value.
"Error" An error value.
"Empty" An uninitialized variable.
"Null" A variant containing no valid data.
"Object" An OLE automation object.
"Unknown" An unknown type of OLE automation object.
"Nothing" An uninitialized object variable.
class A specific type of OLE automation object. In this case, class
is the name of the object as known to OLE.
If varname is an array, then the returned string can be any of the above strings follows
by a empty parenthesis. For example, "Integer()" would be returned for an array of
integers.
If varname is an expression, then the expression is evaluated and a String representing
the resultant data type is returned.
If varname is an OLE collection, then TypeName returns the name of that object
collection.
Example 'The following example defines a subroutine that only accepts
'Integer variables. If not passed an Integer, it will inform
'the user that there was an error, displaying the actual type
'of variable that was passed.
TypeOf (function)
Syntax TypeOf objectvariable Is objecttype
UBound (function)
Syntax UBound(ArrayVariable() [,dimension])
Description Returns an Integer containing the upper bound of the specified dimension of the
specified array variable.
Comments The dimension parameter is an integer that specifies the desired dimension. If not
specified, then the upper bound of the first dimension is returned.
The UBound function can be used to find the upper bound of a dimension of an array
returned by an OLE Automation method or property:
UBound([Link] [,dimension])
UBound([Link] [,dimension])
Examples 'This example dimensions two arrays and displays their upper
'bounds.
Sub Main()
Dim a(5 To 12)
Dim b(2 To 100, 9 To 20)
uba = UBound(a)
ubb = UBound(b,2)
MsgBox "The upper bound of a is: " & uba & " The upper bound of
b is: " & ubb
'This example uses Lbound and Ubound to dimension a dynamic
'array to hold a copy of an array redimmed by the FileList
'statement.
Dim fl$()
FileList fl$,"*"
count = Ubound(fl$)
If ArrayDims(a) Then
Redim nl$(Lbound(fl$) To Ubound(fl$))
For x = 1 To count
nl$(x) = fl$(x)
Next x
MsgBox "The last element of the new array is: " & nl$(count)
End If
End Sub
Unlock (statement)
See Lock, Unlock (statements).
Declaring Structures
The Type statement is used to create a structure definition. Type declarations must
appear outside the body of all subroutines and functions within a script and are therefore
global to an entire script.
Once defined, a UDT can be used to declare variables of that type using the Dim,
Public, or Private statement. The following example defines a rectangle structure:
Type Rect
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
:
Sub Main()
Dim r As Rect
:
[Link] = 10
End Sub
Any fundamental data type can be used as a structure member, including other
user-defined types. Only fixed arrays can be used within structures.
Copying Structures
UDTs of the same type can be assigned to each other, copying the contents. No other
standard operators can be applied to UDTs.
Dim r1 As Rect
Dim r2 As Rect
:
r1 = r2
When copying structures of the same type, all strings in the source UDT are duplicated
and references are placed into the target UDT.
The LSet statement can be used to copy a UDT variable of one type to another:
LSet variable1 = variable2
LSet cannot be used with UDTs containing variable-length strings. The smaller of the
two structures determines how many bytes get copied.
Passing Structures
UDTs can be passed both to user-defined routines and to external routines, and they can
be assigned. UDTs are always passed by reference.
Since structures are always passed by reference, the ByVal keyword cannot be used
when defining structure arguments passed to external routines (using Declare). The
ByVal keyword can only be used with fundamental data types such as Integer and
String.
Passing structures to external routines actually passes a far pointer to the data structure.
Size of Structures
The Len function can be used to determine the number of bytes occupied by a UDT:
Len(udt_variable_name)
Since strings are stored in BasicScript's data space, only a reference (currently, 2 bytes)
is stored within a structure. Thus, the Len function may seem to return incorrect
information for structures containing strings.
Val (function)
Syntax Val(string)
Description A data type used to declare variables that can hold one of many different types of data.
Comments During a variant's existence, the type of data contained within it can change. Variants
can contain any of the following types of data:
Type of Data BasicScript Data Types
Numeric Integer, Long, Single, Double, Boolean, Date, Currency.
Logical Boolean.
Dates and times Date.
String String.
Object Object.
No valid data A variant with no valid data is considered Null.
Uninitialized An uninitialized variant is considered Empty.
There is no type-declaration character for variants.
The number of significant digits representable by a variant depends on the type of data
contained within the variant.
Variant is the default data type for BasicScript. If a variable is not explicitly declared
with Dim, Public, or Private, and there is no type-declaration character (i.e., #, @, !, %,
or &), then the variable is assumed to be Variant.
Assigning to Variants
Before a Variant has been assigned a value, it is considered empty. Thus, immediately
after declaration, the VarType function will return ebEmpty. An uninitialized variant is
0 when used in numeric expressions and is a zero-length string when used within string
expressions.
A Variant is Empty only after declaration and before assigning it a value. The only
way for a Variant to become Empty after having received a value is for that variant to
be assigned to another Variant containing Empty, for it to be assigned explicitly to the
constant Empty, or for it to be erased using the Erase statement.
When a variant is assigned a value, it is also assigned that value's type. Thus, in all
subsequent operations involving that variant, the variant will behave like the type of data
it contains.
Operations on Variants
Normally, a Variant behaves just like the data it contains. One exception to this rule is
that, in arithmetic operations, variants are automatically promoted when an overflow
occurs. Consider the following statements:
Adding Variants
The + operator is defined as performing two functions: when passed strings, it
concatenates them; when passed numbers, it adds the numbers.
With variants, the rules are complicated because the types of the variants are not known
until execution time. If you use +, you may unintentionally perform the wrong
operation.
It is recommended that you use the & operator if you intend to concatenate two String
variants. This guarantees that string concatenation will be performed and not addition.
Variant Storage
Variants require 16 bytes of storage internally:
• A 2-byte type
• A 2-byte extended type for data objects
• 4 bytes of padding for alignment
• An 8-byte value
Unlike other data types, writing variants to Binary or Random files does not write 16
bytes. With variants, a 2-byte type is written, followed by the data (2 bytes for Integer
and so on).
Disadvantages of Variants
The following list describes some disadvantages of variants:
1. Using variants is slower than using the other fundamental data types (i.e., Integer,
Long, Single, Double, Date, Object, String, Currency, and Boolean). Each
operation involving a Variant requires examination of the variant's type.
2. Variants require more storage than other data types (16 bytes as opposed to 8 bytes
for a Double, 2 bytes for an Integer, and so on).
3. Unpredictable behavior. You may write code to expect an Integer variant. At
runtime, the variant may be automatically promoted to a Long variant, causing
your code to break.
See Also Currency (data type); Date (data type); Double (data type); Integer (data type); Long
(data type); Object (data type); Single (data type); String (data type); Boolean (data
type); DefType (statement); CVar (function); VarType (function).
Platform(s) All.
VarType (function)
Syntax VarType(varname)
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax [Link]
[Link] (method)
Syntax [Link] [title [,XPos,YPos [,width,height]]]
Description Opens a new viewport window or switches the focus to the existing viewport window.
Comments The [Link] method accepts the following named :
Named Parameter Description
Sleep 2000
[Link]
End Sub
VLine (statement)
Syntax VLine [lines]
Description Scrolls the window with the focus up or down by the specified number of lines.
Comments The lines parameter is an Integer specifying the number of lines to scroll. If this
parameter is omitted, then the window is scrolled down by one line.
Example 'This example prints a series of lines to the viewport, then
'scrolls back up the lines to the top using VLine.
Sub Main()
[Link] "BasicScript Viewport",100,100,500,200
For i = 1 to 50
Print "This will be displayed on line#: " & i
Next i
MsgBox "We will now go back 40 lines..."
VLine -40
MsgBox "...and here we are!"
[Link]
End Sub
See Also VPage (statement); VScroll (statement).
Platform(s) Windows, Win32.
VPage (statement)
Syntax VPage [pages]
Description Scrolls the window with the focus up or down by the specified number of pages.
Comments The pages parameter is an Integer specifying the number of lines to scroll. If this
parameter is omitted, then the window is scrolled down by one page.
Example 'This example scrolls the viewport window up five pages.
Sub Main()
[Link] "BasicScript Viewport",100,100,500,200
For i = 1 to 500
Print "This will be displayed on line#: " & i
Next i
MsgBox "We will now go back 5 pages..."
VLine -5
MsgBox "...and here we are!"
[Link]
End Sub
VScroll (statement)
Syntax VScroll percentage
Description Sets the thumb mark on the vertical scroll bar attached to the current window.
Comments The position is given as a percentage of the total range associated with that scroll bar.
For example, if the percentage parameter is 50, then the thumb mark is positioned in the
middle of the scroll bar.
Example 'This example prints a bunch of lines to the viewport, then
'scrolls back to the top using VScroll.
Sub Main()
[Link] "BasicScript Viewport",100,100,500,200
For i = 1 to 50
Print "This will be displayed on line#: " & i
Next i
MsgBox "We will now go to the 0% thumb mark poisiton (the
top)..."
VScroll 0
MsgBox "...and here we are!"
[Link]
End Sub
See Also VLine (statement); VPage (statement).
Platform(s) Windows, Win32.
Weekday (function)
Syntax Weekday(date [,firstdayofweek])
Description Returns an Integer value representing the day of the week given by date. Sunday is 1,
Monday is 2, and so on.
The Weekday function takes the following named parameters:
Named Parameter Description
date Any expression representing a valid date.
firstdayofweek Indicates the first day of the week. If omitted, then sunday is
assumed (i.e., the constant ebSunday described below).
The firstdayofweek parameter, if specified, can be any of the following constants:
Constant Value Description
See Also Day (function); Minute (function); Second (function); Month (function); Year
(function); Hour (function); DatePart (function).
Platform(s) All.
While...Wend (statement)
Syntax While condition
[statements]
Wend
Description Repeats a statement or group of statements while a condition is True.
Comments The condition is initially and then checked at the top of each iteration through the loop.
Example 'This example executes a While loop until the random number
'generator returns a value of 1.
Sub Main()
x% = 0
count% = 0
While x% <> 1 And count% < 500
x% = Rnd(1)
If count% > 1000 Then
Exit Sub
Else
count% = count% + 1
End If
Wend
MsgBox "The loop executed " & count% & " times."
End Sub
Width# (statement)
Syntax Width# filenumber, width
Description Specifies the line width for sequential files opened in either Output or Append mode.
Comments The Width# statement requires the following named parameters:
Named Parameter Description
filenumber Integer used by BasicScript to refer to the open file—the
number passed to the Open statement.
width Integer between 0 to 255 inclusive specifying the new width. If
width is 0, then no maximum line length is used.
When a file is initially opened, there is no limit to line length. This command forces all
subsequent output to the specified file to use the specified value as the maximum line
length.
The Width statement affects output in the following manner: if the column position is
greater than 1 and the length of the text to be written to the file causes the column
position to exceed the current line width, then the data is written on the next line.
The Width statement also affects output of the Print command when used with the Tab
and Spc functions.
Example 'This statement sets the maximum line width for file number 1
'to 80 columns.
Sub Main()
Width #1,80
End Sub
See Also Print (statement); Print# (statement); Tab (function); Spc (function).
Platform(s) All.
WinActivate (statement)
Syntax WinActivate [window_name$ | window_object] [,timeout]
Description Activates the window with the given name or object value.
WinClose (statement)
Syntax WinClose [window_name$ | window_object]
WinFind (function)
Syntax WinFind(name$) As HWND
Description Returns an object variable referencing the window having the given name.
Comments The name$ parameter is specified using the same format as that used by the
WinActivate statement.
Example 'This example closes Microsoft Word if its object reference is
'found.
Sub Main()
Dim WordHandle As HWND
Set WordHandle = WinFind("Word")
If (WordHandle Is Not Nothing) Then WinClose WordHandle
End Sub
See Also WinActivate (statement).
Platform(s) Windows, Win32.
WinList (statement)
Syntax WinList ArrayOfWindows()
Description Fills the passed array with references to all the top-level windows.
Comments The passed array must be declared as an array of HWND objects.
The ArrayOfWindows parameter must specify either a zero- or one-dimensioned
dynamic array or a single-dimensioned fixed array. If the array is dynamic, then it will
be redimensioned to exactly hold the new number of elements. For fixed arrays, each
array element is first erased, then the new elements are placed into the array. If there are
fewer elements than will fit in the array, then the remaining elements are unused. A
runtime error results if the array is too small to hold the new elements.
After calling this function, use the LBound and UBound functions to determine the
new size of the array.
Example 'This example minimizes all top-level windows.
Sub Main()
Dim a() As HWND
WinList a
For i = 1 To UBound(a)
WinMinimize a(i)
Next i
End Sub
WinMaximize (statement)
Syntax WinMaximize [window_name$ | window_object]
WinMinimize (statement)
Syntax WinMinimize [window_name$ | window_object]
WinMove (statement)
Syntax WinMove x,y [window_name$ | window_object]
WinRestore (statement)
Syntax WinRestore [window_name$ | window_object]
Comments Restoring a minimized window restores that window to it screen position before it was
minimized. Restoring a maximized window resizes the window to its size previous to
maximizing.
The WinRestore statement requires the following parameters:
Parameter Description
window_name$ String containing the name that appears on the desired
application's title bar. Optionally, a partial name can be used,
such as "Word" for "Microsoft Word."
A hierarchy of windows can be specified by separating each
window name with a vertical bar (|), as in the following example:
WinActivate "Notepad|Find"
In this example, the top-level windows are searched for a
window whose title contains the word "Notepad". If found, the
windows owned by the top level window are searched for one
whose title contains the string "Find"
window_object HWND object specifying the exact window to activate. This can
be used in place of the window_name$ parameter to indicate a
specific window to activate.
If window_name$ and window_object are omitted, then the window with the focus is
restored.
This command differs from the AppRestore command in that this command operates
on the current window rather than the current top-level window.
Example 'This example minimizes all top-level windows except for Program
'Manager.
Sub Main()
Dim a() As HWND
WinList a
For i = 0 To UBound(a)
WinMinimize a(i)
Next I
WinRestore "Program Manager"
End Sub
WinSize (statement)
Syntax WinSize width,height [,window_name$ | window_object]
Description Resizes the given window to the specified width and height.
Comments The WinSize statement requires the following parameters:
Parameter Description
width,height Integer coordinates given in twips that specify the new size of
the window.
window_name$ String containing the name that appears on the desired
application's title bar. Optionally, a partial name can be used,
such as "Word" for "Microsoft Word."
A hierarchy of windows can be specified by separating each
window name with a vertical bar (|), as in the following
example:
WinActivate "Notepad|Find"
In this example, the top-level windows are searched for a
window whose title contains the word "Notepad". If found, the
windows owned by the top level window are searched for one
whose title contains the string "Find".
window_object HWND object specifying the exact window to activate. This
can be used in place of the window_name$ parameter to
indicate a specific window to activate.
If window_name$ and window_object are omitted, then the window with the focus is
resized.
This command differs from the AppSize command in that this command operates on
the current window rather than the current top-level window.
Example 'This example runs and resizes Notepad.
Sub Main()
Dim NotepadApp As HWND
id = Shell("[Link]")
set NotepadApp = WinFind("Notepad")
WinSize 4400,8500,NotepadApp
End Sub
Word$ (function)
Syntax Word$(text$,first[,last])
Description Returns a String containing a single word or sequence of words between first and last.
Comments The Word$ function requires the following parameters:
Parameter Description
text$ String from which the sequence of words will be extracted.
first Integer specifying the index of the first word in the sequence to
return. If last is not specified, then only that word is returned.
last Integer specifying the index of the last word in the sequence to
return. If last is specified, then all words between first and last
will be returned, including all spaces, tabs, and end-of-lines that
occur between those words.
Words are separated by any nonalphanumeric characters such as spaces, tabs,
end-of-lines, and punctuation. On multi-byte and wide character platforms, double-byte
spaces are treated as separators as well. Embedded null characters are treated as regular
characters.
If first is greater than the number of words in text$, then a zero-length string is returned.
If last is greater than the number of words in text$, then all words from first to the end of
the text are returned.
Example 'This example finds the name "Stuart" in a string and then
'extracts two words from the string.
Sub Main()
s$ = "My last name is Williams; Stuart is my surname."
c$ = Word$(s$,5,6)
MsgBox "The extracted name is: " & c$
End Sub
See Also Item$ (function); ItemCount (function); Line$ (function); LineCount (function);
WordCount (function).
Platform(s) All.
WordCount (function)
Syntax WordCount(text$)
Description Returns an Integer representing the number of words in the specified text.
Comments Words are separated by spaces, tabs, and end-of-lines. Embedded null characters are
treated as regular characters.
Example 'This example counts the number of words in a particular string.
Sub Main()
s$ = "My last name is Williams; Stuart is my surname."
i% = WordCount(s$)
MsgBox "'" & s$ & "' has " & i% & " words."
End Sub
See Also Item$ (function); ItemCount (function); Line$ (function); LineCount (function);
Word$ (function).
Platform(s) All.
Write# (statement)
Syntax Write [#]filenumber [,expressionlist]
Example 'This example opens a file for sequential write, then writes ten
'records into the file with the values 10...50. Then the file is
'closed and reopened for read, and the records are read with the
'Input statement. The results are displayed in a dialog box.
Sub Main()
Open "[Link]" For Output Access Write As #1
For x = 1 To 10
r% = x * 10
Write #1,x,r%
Next x
Close
Open "[Link]" For Input Access Read As #1
For x = 1 To 10
Input #1,a%,b%
message = message & "Record " & a% & ": " & b% & [Link]$
Next x
MsgBox message
Close
End Sub
WriteIni (statement)
Syntax WriteIni section$,ItemName$,value$[,filename$]
section$ String specifying the section that contains the desired variables,
such as "Windows." Section names are specified without the
enclosing brackets.
ItemName$ String specifying which item from within the given section you
want to change. If ItemName$ is a zero-length string (""), then
the entire section specified by section$ is deleted.
value$ String specifying the new value for the given item. If value$ is a
zero-length string (""), then the item specified by ItemName$ is
deleted from the ini file.
filename$ String specifying the name of the ini file.
Example 'This example sets the txt extension to be associated with
'Notepad.
Sub Main()
WriteIni "Extensions","txt", _
"c:\windows\[Link] ^.txt","[Link]"
End Sub
Xor (operator)
Syntax result = expression1 Xor expression2
Description Performs a logical or binary exclusion on two expressions.
Comments If both expressions are either Boolean, Boolean variants, or Null variants, then a logical
exclusion is performed as follows:
If expression1 is and expression2 is then the result is
True True False
True False True
False True True
False False False
If either expression is Null, then Null is returned.
Binary Exclusion
If the two expressions are Integer, then a binary exclusion is performed, returning an
Integer result. All other numeric types (including Empty variants) are converted to
Long, and a binary exclusion is then performed, returning a Long result.
Binary exclusion forms a new value based on a bit-by-bit comparison of the binary
representations of the two expressions according to the following table:
If bit in expression1 is and bit in expression2 is the result is
1 1 0
0 1 1
1 0 1
0 0 0
Example 'This example builds a logic table for the XOR function and
'displays it.
Sub Main()
For x = -1 To 0
For y = -1 To 0
z = x Xor y
message = message & Format(x,"True/False") & " Xor "
message = message & Format(y,"True/False") & " = "
message = message & Format(z,"True/False") & [Link]$
Next y
Next x
MsgBox message
End Sub
See Also Operator Precedence (topic); Or (operator); Eqv (operator); Imp (operator); And
(operator).
Platform(s) All.
Year (function)
Syntax Year(date)
Description Returns the year of the date encoded in the specified date parameter. The value returned
is between 100 and 9999 inclusive.
The date parameter is any expression representing a valid date.
Example 'This example returns the current year in a dialog box.
Sub Main()
tdate$ = Date$
tyear! = Year(DateValue(tdate$))
MsgBox "The current year is: " & tyear$
End Sub
See Also Day (function); Minute (function); Second (function); Month (function); Hour
(function); Weekday (function); DatePart (function).
Platform(s) All.
The following table lists all BasicScript language elements and specifies the platforms
on which these language elements are supported.
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
#Const ■ ■ ■ ■ ■ ■ ■
#If...Then...#Else ■ ■ ■ ■ ■ ■ ■
& ■ ■ ■ ■ ■ ■ ■
' ■ ■ ■ ■ ■ ■ ■
() ■ ■ ■ ■ ■ ■ ■
* ■ ■ ■ ■ ■ ■ ■
+ ■ ■ ■ ■ ■ ■ ■
- ■ ■ ■ ■ ■ ■ ■
/ ■ ■ ■ ■ ■ ■ ■
< ■ ■ ■ ■ ■ ■ ■
<= ■ ■ ■ ■ ■ ■ ■
<> ■ ■ ■ ■ ■ ■ ■
= (assignment) ■ ■ ■ ■ ■ ■ ■
= (operator) ■ ■ ■ ■ ■ ■ ■
> ■ ■ ■ ■ ■ ■ ■
>= ■ ■ ■ ■ ■ ■ ■
\ ■ ■ ■ ■ ■ ■ ■
^ ■ ■ ■ ■ ■ ■ ■
_ ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
Abs ■ ■ ■ ■ ■ ■ ■
ActivateControl ■ ❒ ❒ ❒ ❒ ❒ ❒
And ■ ■ ■ ■ ■ ■ ■
Any ■ ■ ■ ■ ■ ■ ■
AnswerBox ■ ■ ■ ■ ❒ ■ ❒
AppActivate ■ ■ ❒ ■ ❒ ■ ❒
AppClose ■ ■ ❒ ■ ❒ ❒ ❒
AppFileName$ ■ ❒ ❒ ■ ❒ ❒ ❒
AppFind, AppFind$ ■ ■ ❒ ■ ❒ ❒ ❒
AppGetActive$ ■ ■ ❒ ■ ❒ ❒ ❒
AppGetPosition ■ ■ ❒ ■ ❒ ❒ ❒
AppGetState ■ ■ ❒ ■ ❒ ❒ ❒
AppHide ■ ■ ❒ ■ ❒ ❒ ❒
AppList ■ ■ ❒ ■ ❒ ❒ ❒
AppMaximize ■ ■ ❒ ■ ❒ ❒ ❒
AppMinimize ■ ■ ❒ ■ ❒ ❒ ❒
AppMove ■ ■ ❒ ■ ❒ ❒ ❒
AppRestore ■ ■ ❒ ■ ❒ ❒ ❒
AppSetState ■ ■ ❒ ■ ❒ ❒ ❒
AppShow ■ ■ ❒ ■ ❒ ❒ ❒
AppSize ■ ■ ❒ ■ ❒ ❒ ❒
AppType ■ ■ ❒ ❒ ❒ ❒ ❒
ArrayDims ■ ■ ■ ■ ■ ■ ■
ArraySort ■ ■ ■ ■ ■ ■ ■
Asc, AscB, AscW ■ ■ ■ ■ ■ ■ ■
AskBox, AskBox$ ■ ■ ■ ■ ❒ ■ ❒
AskPassword, AskPassword$ ■ ■ ■ ■ ❒ ■ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
Atn ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ■ ■ ■ ■ ■
Beep ■ ■ ■ ■ ■ ■ ■
Begin Dialog ■ ■ ■ ■ ❒ ■ ❒
Boolean ■ ■ ■ ■ ■ ■ ■
ButtonEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
ButtonExists ■ ❒ ❒ ❒ ❒ ❒ ❒
Call ■ ■ ■ ■ ■ ■ ■
CancelButton ■ ■ ■ ■ ❒ ■ ❒
CBool ■ ■ ■ ■ ■ ■ ■
CCur ■ ■ ■ ■ ■ ■ ■
CDate, CVDate ■ ■ ■ ■ ■ ■ ■
CDbl ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
ChDir ■ ■ ■ ■ ■ ■ ■
ChDrive ■ ■ ❒ ■ ■ ❒ ❒
CheckBox ■ ■ ■ ■ ❒ ■ ❒
CheckBoxEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
CheckBoxExists ■ ❒ ❒ ❒ ❒ ❒ ❒
Choose ■ ■ ■ ■ ■ ■ ■
Chr, Chr$, ChrB, ChrB$, ChrW, ChrW$ ■ ■ ■ ■ ■ ■ ■
CInt ■ ■ ■ ■ ■ ■ ■
Clipboard$ (function) ■ ■ ❒ ■ ❒ ■ ❒
Clipboard$ (statement) ■ ■ ❒ ■ ❒ ■ ❒
[Link] ■ ■ ❒ ■ ❒ ■ ❒
[Link] ■ ■ ❒ ■ ❒ ■ ❒
[Link] ■ ■ ❒ ■ ❒ ■ ❒
[Link] ■ ■ ❒ ■ ❒ ■ ❒
CLng ■ ■ ■ ■ ■ ■ ■
Close ■ ■ ■ ■ ■ ■ ■
ComboBox ■ ■ ■ ■ ❒ ■ ❒
ComboBoxEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
ComboBoxExists ■ ❒ ❒ ❒ ❒ ❒ ❒
Command, Command$ ■ ■ ■ ■ ■ ■ ■
Const ■ ■ ■ ■ ■ ■ ■
Cos ■ ■ ■ ■ ■ ■ ■
CreateObject ■ ■ ❒ ❒ ❒ ■ ❒
CSng ■ ■ ■ ■ ■ ■ ■
CStr ■ ■ ■ ■ ■ ■ ■
CurDir, CurDir$ ■ ■ ■ ■ ■ ■ ■
Currency ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
CVar ■ ■ ■ ■ ■ ■ ■
CVErr ■ ■ ■ ■ ■ ■ ■
Date (data type) ■ ■ ■ ■ ■ ■ ■
Date, Date$ (functions) ■ ■ ■ ■ ■ ■ ■
Date, Date$ (statements) ■ ■ ■ ■ ■ ■ ■
DateAdd ■ ■ ■ ■ ■ ■ ■
DateDiff ■ ■ ■ ■ ■ ■ ■
DatePart ■ ■ ■ ■ ■ ■ ■
DateSerial ■ ■ ■ ■ ■ ■ ■
DateValue ■ ■ ■ ■ ■ ■ ■
Day ■ ■ ■ ■ ■ ■ ■
DDB ■ ■ ■ ■ ■ ■ ■
DDEExecute ■ ■ ❒ ■ ❒ ❒ ❒
DDEInitiate ■ ■ ❒ ■ ❒ ❒ ❒
DDEPoke ■ ■ ❒ ■ ❒ ❒ ❒
DDERequest, DDERequest$ ■ ■ ❒ ■ ❒ ❒ ❒
DDESend ■ ■ ❒ ■ ❒ ❒ ❒
DDETerminate ■ ■ ❒ ■ ❒ ❒ ❒
DDETerminateAll ■ ■ ❒ ■ ❒ ❒ ❒
DDETimeOut ■ ■ ❒ ■ ❒ ❒ ❒
Declare ■ ■ ■ ■ ■ ■ ■
DefBool ■ ■ ■ ■ ■ ■ ■
DefCur ■ ■ ■ ■ ■ ■ ■
DefDate ■ ■ ■ ■ ■ ■ ■
DefDbl ■ ■ ■ ■ ■ ■ ■
DefInt ■ ■ ■ ■ ■ ■ ■
DefLng ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
DefObj ■ ■ ■ ■ ■ ■ ■
DefSng ■ ■ ■ ■ ■ ■ ■
DefStr ■ ■ ■ ■ ■ ■ ■
DefVar ■ ■ ■ ■ ■ ■ ■
DeleteSetting ■ ■ ❒ ■ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
Dialog (function) ■ ■ ■ ■ ❒ ■ ❒
Dialog (statement) ■ ■ ■ ■ ❒ ■ ❒
Dim ■ ■ ■ ■ ■ ■ ■
Dir, Dir$ ■ ■ ■ ■ ■ ■ ■
DiskDrives ■ ■ ❒ ❒ ■ ❒ ❒
DiskFree ■ ■ ❒ ❒ ■ ❒ ❒
DlgCaption ■ ■ ■ ■ ■ ■ ❒
DlgControlId ■ ■ ■ ■ ❒ ■ ❒
DlgEnable (function) ■ ■ ■ ■ ❒ ■ ❒
DlgEnable (statement) ■ ■ ■ ■ ❒ ■ ❒
DlgFocus (function) ■ ■ ■ ■ ❒ ■ ❒
DlgFocus (statement) ■ ■ ■ ■ ❒ ■ ❒
DlgListBoxArray (function) ■ ■ ■ ■ ❒ ■ ❒
DlgListBoxArray (statement) ■ ■ ■ ■ ❒ ■ ❒
DlgProc ■ ■ ■ ■ ❒ ■ ❒
DlgSetPicture ■ ■ ■ ■ ❒ ■ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
DlgText (statement) ■ ■ ■ ■ ❒ ■ ❒
DlgText$ (function) ■ ■ ■ ■ ❒ ■ ❒
DlgValue (function) ■ ■ ■ ■ ❒ ■ ❒
DlgValue (statement) ■ ■ ■ ■ ❒ ■ ❒
DlgVisible (function) ■ ■ ■ ■ ❒ ■ ❒
DlgVisible (statement) ■ ■ ■ ■ ❒ ■ ❒
Do...Loop ■ ■ ■ ■ ■ ■ ■
DoEvents (function) ■ ■ ■ ■ ■ ■ ■
DoEvents (statement) ■ ■ ■ ■ ■ ■ ■
DoKeys ■ ❒ ❒ ❒ ❒ ❒ ❒
Double ■ ■ ■ ■ ■ ■ ■
DropListBox ■ ■ ■ ■ ❒ ■ ❒
EditEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
EditExists ■ ❒ ❒ ❒ ❒ ❒ ❒
End ■ ■ ■ ■ ■ ■ ■
Environ, Environ$ ■ ■ ■ ■ ■ ■ ■
Eof ■ ■ ■ ■ ■ ■ ■
Eqv ■ ■ ■ ■ ■ ■ ■
Erase ■ ■ ■ ■ ■ ■ ■
Erl ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ❒ ■ ❒ ■ ❒ ❒ ❒
[Link] ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
[Link] ■ ■ ■ ■ ■ ■ ■
Error ■ ■ ■ ■ ■ ■ ■
Error, Error$ ■ ■ ■ ■ ■ ■ ■
Exit Do ■ ■ ■ ■ ■ ■ ■
Exit For ■ ■ ■ ■ ■ ■ ■
Exit Function ■ ■ ■ ■ ■ ■ ■
Exit Sub ■ ■ ■ ■ ■ ■ ■
Exp ■ ■ ■ ■ ■ ■ ■
FileAttr ■ ■ ■ ■ ■ ■ ■
FileCopy ■ ■ ■ ■ ■ ■ ■
FileDateTime ■ ■ ■ ■ ■ ■ ■
FileDirs ■ ■ ■ ■ ■ ■ ■
FileExists ■ ■ ■ ■ ■ ■ ■
FileLen ■ ■ ■ ■ ■ ■ ■
FileList ■ ■ ■ ■ ■ ■ ■
FileParse$ ■ ■ ■ ■ ■ ■ ■
FileType ■ ❒ ❒ ❒ ❒ ❒ ❒
Fix ■ ■ ■ ■ ■ ■ ■
For...Each ■ ■ ■ ■ ■ ■ ■
For...Next ■ ■ ■ ■ ■ ■ ■
Format, Format$ ■ ■ ■ ■ ■ ■ ■
FreeFile ■ ■ ■ ■ ■ ■ ■
Function...End Function ■ ■ ■ ■ ■ ■ ■
Fv ■ ■ ■ ■ ■ ■ ■
Get ■ ■ ■ ■ ■ ■ ■
GetAllSettings ■ ■ ❒ ■ ❒ ❒ ❒
GetAttr ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
GetCheckBox ■ ❒ ❒ ❒ ❒ ❒ ❒
GetComboBoxItem$ ■ ❒ ❒ ❒ ❒ ❒ ❒
GetComboBoxItemCount ■ ❒ ❒ ❒ ❒ ❒ ❒
GetEditText$ ■ ❒ ❒ ❒ ❒ ❒ ❒
GetListBoxItem$ ■ ❒ ❒ ❒ ❒ ❒ ❒
GetListBoxItemCount ■ ❒ ❒ ❒ ❒ ❒ ❒
GetObject ■ ■ ❒ ❒ ❒ ■ ❒
GetOption ■ ❒ ❒ ❒ ❒ ❒ ❒
GetSetting ■ ■ ❒ ■ ❒ ❒ ❒
Global ■ ■ ■ ■ ■ ■ ■
GoSub ■ ■ ■ ■ ■ ■ ■
Goto ■ ■ ■ ■ ■ ■ ■
GroupBox ■ ■ ■ ■ ❒ ■ ❒
HelpButton ■ ■ ■ ■ ❒ ■ ❒
Hex, Hex$ ■ ■ ■ ■ ■ ■ ■
HLine ■ ■ ❒ ❒ ❒ ❒ ❒
Hour ■ ■ ■ ■ ■ ■ ■
HPage ■ ■ ❒ ❒ ❒ ❒ ❒
HScroll ■ ■ ❒ ❒ ❒ ❒ ❒
HWND ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
If...Then...Else ■ ■ ■ ■ ■ ■ ■
IIf ■ ■ ■ ■ ■ ■ ■
IMEStatus ■ ■ ■ ■ ❒ ■ ❒
Imp ■ ■ ■ ■ ■ ■ ■
Inline ■ ■ ■ ■ ■ ■ ■
Input# ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
Input, Input$, InputB, InputB$ ■ ■ ■ ■ ■ ■ ■
InputBox, InputBox$ ■ ■ ■ ■ ❒ ■ ❒
InStr, InstrB ■ ■ ■ ■ ■ ■ ■
Int ■ ■ ■ ■ ■ ■ ■
Integer ■ ■ ■ ■ ■ ■ ■
IPmt ■ ■ ■ ■ ■ ■ ■
IRR ■ ■ ■ ■ ■ ■ ■
Is ■ ■ ■ ■ ■ ■ ■
IsDate ■ ■ ■ ■ ■ ■ ■
IsEmpty ■ ■ ■ ■ ■ ■ ■
IsError ■ ■ ■ ■ ■ ■ ■
IsMissing ■ ■ ■ ■ ■ ■ ■
IsNull ■ ■ ■ ■ ■ ■ ■
IsNumeric ■ ■ ■ ■ ■ ■ ■
IsObject ■ ■ ■ ■ ■ ■ ■
Item$ ■ ■ ■ ■ ■ ■ ■
ItemCount ■ ■ ■ ■ ■ ■ ■
Kill ■ ■ ■ ■ ■ ■ ■
LBound ■ ■ ■ ■ ■ ■ ■
LCase, LCase$ ■ ■ ■ ■ ■ ■ ■
Left, Left$, LeftB, LeftB$ ■ ■ ■ ■ ■ ■ ■
Len, LenB ■ ■ ■ ■ ■ ■ ■
Let ■ ■ ■ ■ ■ ■ ■
Like ■ ■ ■ ■ ■ ■ ■
Line Input # ■ ■ ■ ■ ■ ■ ■
Line$ ■ ■ ■ ■ ■ ■ ■
LineCount ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
ListBox ■ ■ ■ ■ ❒ ■ ❒
ListBoxEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
ListBoxExists ■ ❒ ❒ ❒ ❒ ❒ ❒
Loc ■ ■ ■ ■ ■ ■ ■
Lock ■ ■ ■ ■ ■ ■ ■
Lof ■ ■ ■ ■ ■ ■ ■
Log ■ ■ ■ ■ ■ ■ ■
Long ■ ■ ■ ■ ■ ■ ■
LSet ■ ■ ■ ■ ■ ■ ■
LTrim, LTrim$ ■ ■ ■ ■ ■ ■ ■
MacID ❒ ❒ ❒ ❒ ❒ ■ ❒
MacScript ❒ ❒ ❒ ❒ ❒ ■ ❒
Main ■ ■ ■ ■ ■ ■ ■
Mci ■ ❒ ❒ ❒ ❒ ❒ ❒
Menu ■ ❒ ❒ ❒ ❒ ❒ ❒
MenuItemChecked ■ ❒ ❒ ❒ ❒ ❒ ❒
MenuItemEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
MenuItemExists ■ ❒ ❒ ❒ ❒ ❒ ❒
Mid, Mid$, MidB, MidB$ (functions) ■ ■ ■ ■ ■ ■ ■
Mid, Mid$, MidB, MidB$ (statements) ■ ■ ■ ■ ■ ■ ■
Minute ■ ■ ■ ■ ■ ■ ■
MIRR ■ ■ ■ ■ ■ ■ ■
MkDir ■ ■ ■ ■ ■ ■ ■
Mod ■ ■ ■ ■ ■ ■ ■
Month ■ ■ ■ ■ ■ ■ ■
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
MsgBox (function) ■ ■ ■ ■ ❒ ■ ❒
MsgBox (statement) ■ ■ ■ ■ ❒ ■ ❒
Name ■ ■ ■ ■ ■ ■ ■
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
Not ■ ■ ■ ■ ■ ■ ■
Now ■ ■ ■ ■ ■ ■ ■
NPer ■ ■ ■ ■ ■ ■ ■
Npv ■ ■ ■ ■ ■ ■ ■
Object ■ ■ ❒ ❒ ❒ ■ ❒
Oct, Oct$ ■ ■ ■ ■ ■ ■ ■
OKButton ■ ■ ■ ■ ❒ ■ ❒
On Error ■ ■ ■ ■ ■ ■ ■
Open ■ ■ ■ ■ ■ ■ ■
OpenFilename$ ■ ■ ■ ■ ❒ ■ ❒
Option Base ■ ■ ■ ■ ■ ■ ■
Option Compare ■ ■ ■ ■ ■ ■ ■
Option CStrings ■ ■ ■ ■ ■ ■ ■
Option Default ■ ■ ■ ■ ■ ■ ■
Option Explicit ■ ■ ■ ■ ■ ■ ■
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
OptionButton ■ ■ ■ ■ ❒ ■ ❒
OptionEnabled ■ ❒ ❒ ❒ ❒ ❒ ❒
OptionExists ■ ❒ ❒ ❒ ❒ ❒ ❒
OptionGroup ■ ■ ■ ■ ❒ ■ ❒
Or ■ ■ ■ ■ ■ ■ ■
Picture ■ ■ ■ ■ ❒ ■ ❒
PictureButton ■ ■ ■ ■ ❒ ■ ❒
Pmt ■ ■ ■ ■ ■ ■ ■
PopupMenu ■ ■ ❒ ❒ ❒ ❒ ❒
PPmt ■ ■ ■ ■ ■ ■ ■
Print ■ ■ ■ ■ ■ ■ ■
Print # ■ ■ ■ ■ ■ ■ ■
PrinterGetOrientation ■ ❒ ❒ ❒ ❒ ❒ ❒
PrinterSetOrientation ■ ❒ ❒ ❒ ❒ ❒ ❒
PrintFile ■ ❒ ❒ ❒ ❒ ❒ ❒
Private ■ ■ ■ ■ ■ ■ ■
Public ■ ■ ■ ■ ■ ■ ■
PushButton ■ ■ ■ ■ ❒ ■ ❒
Put ■ ■ ■ ■ ■ ■ ■
Pv ■ ■ ■ ■ ■ ■ ■
QueEmpty ■ ❒ ❒ ❒ ❒ ❒ ❒
QueFlush ■ ❒ ❒ ❒ ❒ ❒ ❒
QueKeyDn ■ ❒ ❒ ❒ ❒ ❒ ❒
QueKeys ■ ❒ ❒ ❒ ❒ ❒ ❒
QueKeyUp ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseClick ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseDblClk ■ ❒ ❒ ❒ ❒ ❒ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
QueMouseDblDn ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseDn ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseMove ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseMoveBatch ■ ❒ ❒ ❒ ❒ ❒ ❒
QueMouseUp ■ ❒ ❒ ❒ ❒ ❒ ❒
QueSetRelativeWindow ■ ❒ ❒ ❒ ❒ ❒ ❒
Random ■ ■ ■ ■ ■ ■ ■
Randomize ■ ■ ■ ■ ■ ■ ■
Rate ■ ■ ■ ■ ■ ■ ■
ReadINI$ ■ ■ ❒ ■ ❒ ❒ ❒
ReadINISection ■ ■ ❒ ■ ❒ ❒ ❒
ReDim ■ ■ ■ ■ ■ ■ ■
REM ■ ■ ■ ■ ■ ■ ■
Reset ■ ■ ■ ■ ■ ■ ■
Resume ■ ■ ■ ■ ■ ■ ■
Return ■ ■ ■ ■ ■ ■ ■
Right, Right$, RightB, RightB$ ■ ■ ■ ■ ■ ■ ■
RmDir ■ ■ ■ ■ ■ ■ ■
Rnd ■ ■ ■ ■ ■ ■ ■
RSet ■ ■ ■ ■ ■ ■ ■
RTrim, RTrim$ ■ ■ ■ ■ ■ ■ ■
SaveFileName$ ■ ■ ■ ■ ❒ ■ ❒
SaveSetting ■ ■ ❒ ■ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
Second ■ ■ ■ ■ ■ ■ ■
Seek (function) ■ ■ ■ ■ ■ ■ ■
Seek (statement) ■ ■ ■ ■ ■ ■ ■
Select...Case ■ ■ ■ ■ ■ ■ ■
SelectBox ■ ■ ■ ■ ❒ ■ ❒
SelectButton ■ ❒ ❒ ❒ ❒ ❒ ❒
SelectComboboxItem ■ ❒ ❒ ❒ ❒ ❒ ❒
SelectListboxItem ■ ❒ ❒ ❒ ❒ ❒ ❒
SendKeys ■ ■ ❒ ❒ ❒ ❒ ❒
Set ■ ■ ■ ■ ■ ■ ■
SetAttr ■ ■ ■ ■ ■ ■ ■
SetCheckbox ■ ❒ ❒ ❒ ❒ ❒ ❒
SetEditText ■ ❒ ❒ ❒ ❒ ❒ ❒
SetOption ■ ❒ ❒ ❒ ❒ ❒ ❒
Sgn ■ ■ ■ ■ ■ ■ ■
Shell ■ ■ ■ ■ ■ ■ ■
Sin ■ ■ ■ ■ ■ ■ ■
Single ■ ■ ■ ■ ■ ■ ■
Sleep ■ ■ ■ ■ ■ ■ ■
Sln ■ ■ ■ ■ ■ ■ ■
Space, Space$ ■ ■ ■ ■ ■ ■ ■
Spc ■ ■ ■ ■ ■ ■ ■
SQLBind ■ ■ ❒ ❒ ❒ ❒ ❒
SQLClose ■ ■ ❒ ❒ ❒ ❒ ❒
SQLError ■ ■ ❒ ❒ ❒ ❒ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
SQLExecQuery ■ ■ ❒ ❒ ❒ ❒ ❒
SQLGetSchema ■ ■ ❒ ❒ ❒ ❒ ❒
SQLOpen ■ ■ ❒ ❒ ❒ ❒ ❒
SQLRequest ■ ■ ❒ ❒ ❒ ❒ ❒
SQLRetrieve ■ ■ ❒ ❒ ❒ ❒ ❒
SQLRetrieveToFile ■ ■ ❒ ❒ ❒ ❒ ❒
Sqr ■ ■ ■ ■ ■ ■ ■
Stop ■ ■ ■ ■ ■ ■ ■
Str, Str$ ■ ■ ■ ■ ■ ■ ■
StrComp ■ ■ ■ ■ ■ ■ ■
StrConv ■ ■ ■ ■ ■ ■ ■
String ■ ■ ■ ■ ■ ■ ■
String, String$ ■ ■ ■ ■ ■ ■ ■
Sub...End Sub ■ ■ ■ ■ ■ ■ ■
Switch ■ ■ ■ ■ ■ ■ ■
SYD ■ ■ ■ ■ ■ ■ ■
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link] ■ ■ ❒ ❒ ❒ ❒ ❒
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
[Link]$ ■ ■ ❒ ❒ ❒ ❒ ❒
Tab ■ ■ ■ ■ ■ ■ ■
Tan ■ ■ ■ ■ ■ ■ ■
Text ■ ■ ■ ■ ❒ ■ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
TextBox ■ ■ ■ ■ ❒ ■ ❒
Time, Time$ (functions) ■ ■ ■ ■ ■ ■ ■
Time, Time$ (statements) ■ ■ ■ ■ ■ ■ ■
Timer ■ ■ ■ ■ ■ ■ ■
TimeSerial ■ ■ ■ ■ ■ ■ ■
TimeValue ■ ■ ■ ■ ■ ■ ■
Trim, Trim$ ■ ■ ■ ■ ■ ■ ■
Type ■ ■ ■ ■ ■ ■ ■
TypeName ■ ■ ■ ■ ■ ■ ■
TypeOf ■ ■ ■ ■ ■ ■ ■
UBound ■ ■ ■ ■ ■ ■ ■
UCase, UCase$ ■ ■ ■ ■ ■ ■ ■
UnLock ■ ■ ■ ■ ■ ■ ■
Val ■ ■ ■ ■ ■ ■ ■
Variant ■ ■ ■ ■ ■ ■ ■
VarType ■ ■ ■ ■ ■ ■ ■
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
[Link] ■ ❒ ❒ ❒ ❒ ❒ ❒
VLine ■ ■ ❒ ❒ ❒ ❒ ❒
VPage ■ ■ ❒ ❒ ❒ ❒ ❒
VScroll ■ ■ ❒ ❒ ❒ ❒ ❒
Weekday ■ ■ ■ ■ ■ ■ ■
While...Wend ■ ■ ■ ■ ■ ■ ■
Width# ■ ■ ■ ■ ■ ■ ■
WinActivate ■ ■ ❒ ❒ ❒ ❒ ❒
WinClose ■ ■ ❒ ❒ ❒ ❒ ❒
Macintosh
OpenVMS
NetWare
Win32
UNIX
OS/2
Win
Language Element
WinFind ■ ■ ❒ ❒ ❒ ❒ ❒
WinList ■ ■ ❒ ❒ ❒ ❒ ❒
WinMaximize ■ ■ ❒ ❒ ❒ ❒ ❒
WinMinimize ■ ■ ❒ ❒ ❒ ❒ ❒
WinMove ■ ■ ❒ ❒ ❒ ❒ ❒
WinRestore ■ ■ ❒ ❒ ❒ ❒ ❒
WinSize ■ ■ ❒ ❒ ❒ ❒ ❒
Word$ ■ ■ ■ ■ ■ ■ ■
WordCount ■ ■ ■ ■ ■ ■ ■
Write # ■ ■ ■ ■ ■ ■ ■
WriteIni ■ ■ ❒ ■ ❒ ❒ ❒
Xor ■ ■ ■ ■ ■ ■ ■
Year ■ ■ ■ ■ ■ ■ ■
This section contains lists of all the error messages that BasicScript may display at
runtime. It is divided into two subsections, the first describing errors messages
compatible with “standard” Basic as implemented by Microsoft Visual Basic and the
second describing error messages specific to BasicScript.
A few error messages contain placeholders, which get replaced by the runtime when
forming the completed runtime error message. These placeholders appear in the
following list as the italicized word placeholder.
Error
Number Error Message
93 Invalid pattern string
94 Invalid use of Null
139 Only one user dialog may be up at any time
140 Dialog control identifier does not match any current control
141 The placeholder statement is not available on this dialog control type
143 The dialog control with the focus may not be disabled or hidden
144 Focus may not be set to a hidden or disabled control
150 Dialog control identifier is already defined
163 This statement can only be used when a user dialog is active
260 No timer available
281 No more DDE channels
282 No foreign application responded to a DDE initiate
283 Multiple applications responded to a DDE initiate
285 Foreign application won’t perform DDE method or operation
286 Timeout while waiting for DDE response
287 User pressed Escape key during DDE operation
288 Destination is busy
289 Data not provided in DDE operation
290 Data in wrong format
291 Foreign application quit
292 DDE conversation closed or changed
295 Message queue filled; DDE message lost
298 DDE requires [Link]
380 Invalid property value
423 Property or method not found
424 Object required
429 OLE Automation server can’t create object
430 Class doesn’t support OLE Automation
431 OLE Automation server cannot load file
432 File name or class name not found during OLE Automation operation
438 Object doesn’t support this property or method
440 OLE Automation error
442 Connection to type library or object library for remote process has been
lost. Press OK for dialog to remove reference.
443 Object does not have a default value
445 Object doesn’t support this action
446 Object doesn’t support named arguments
447 Object doesn’t support current locale setting
Error
Number Error Message
448 Named argument not found
449 Argument not optional
450 Wrong number of arguments or invalid property assignment
451 Object not a collection
452 Invalid ordinal
453 Specified DLL function not found
454 Code resource not found
455 Code resource lock error
460 Invalid Clipboard format
481 Invalid picture
520 Can’t empty clipboard
521 Can’t open clipboard
600 Set value not allowed on collections
601 Get value not allowed on collections
603 ODBC - SQLAllocEnv failure
604 ODBC - SQLAllocConnect failure
608 ODBC - SQLFreeConnect error
610 ODBC - SQLAllocStmt failure
3129 Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE',
'SELECT', or 'UPDATE'
3146 ODBC -- call failed.
3148 ODBC -- connection failed.
3276 Invalid database ID
The following table contains a list of all the errors that may be generated by the
BasicScript compiler. With some errors, the compiler changes placeholders within the
error to text from the script being compiled. These placeholders are represented in this
table by the italicized word placeholder.
Error
Number Error Message
1 Variable Required - Can't assign to this expression
2 Letter range must be in ascending order
3 Redefinition of default type
4 Out of storage for variables
5 Type-declaration character doesn't match defined type
6 Expression too complex
7 Cannot assign whole array
8 Assignment variable and expression are different types
9 Type-declaration character not allowed for function with explicit type
10 Array type mismatch in parameter
11 Array type expected for parameter
12 Array type unexpected for parameter
13 Integer expression expected for an array index
14 Integer expression expected
15 String expression expected
16 Identifier is already a user defined type
17 Property value is the incorrect type
18 Left of "." must be an object, structure, or dialog
19 Invalid string operator
20 Can't apply operator to array type
21 Operator type mismatch
22 "placeholder" is not a variable
23 "placeholder" is not an array variable or a function
24 Unknown placeholder "placeholder"
25 Out of memory
26 placeholder: Too many parameters encountered
Error
Number Error Message
27 placeholder: Missing parameter(s)
28 placeholder: Type mismatch in parameter placeholder
29 Missing label "placeholder"
30 Too many nested statements
31 Encountered new-line in string
32 Overflow in decimal value
33 Overflow in hex value
34 Overflow in octal value
35 Expression is not constant
36 Not inside a Do statement
37 Type-declaration character not allowed for parameter with explicit type
39 Can't pass an array by value
40 "placeholder" is already declared as a parameter
41 Variable name used as label name
42 Duplicate label
43 Not inside a function
44 Not inside a sub
46 Can't assign to function
47 Identifier is already a variable
48 Unknown type
49 Variable is not an array type
50 Can't redimension an array to a different type
51 Identifier is not a string array variable
52 0 expected
54 placeholder is not an assignable property of the object
56 placeholder is not a method of the object
57 placeholder is not a property of the object
58 Expecting 0 or 1
59 Boolean expression expected
60 Numeric expression expected
61 Numeric type For variable expected
62 For...Next variable mismatch
63 Out of string storage space
64 Out of identifier storage space
68 Division by zero
69 Overflow in expression
70 Floating-point expression expected
72 Invalid floating-point operator
Error
Number Error Message
74 Single character expected
75 Subroutine identifier can't have a type-declaration character
76 Script is too large to be compiled
77 Variable type expected
78 Types and dialog variables can’t be passed by value
79 Can't assign to user or dialog type variable
80 Maximum string length exceeded
81 Identifier name already in use as a variable
84 Operator cannot be used on an object
85 placeholder is not a property or method of the object
86 Label cannot contain type-declaration character
87 Type-declaration character mismatch in placeholder
88 Destination name is already a constant
89 Can't assign to constant
91 Identifier too long
92 Expecting string or structure expression
93 Can't assign to expression
94 Dialog and Object types are not supported in this context
95 Array expression not supported as parameter
96 Dialogs, objects, and structure expressions are not supported as a
parameter
97 Invalid numeric operator
98 Invalid structure element name following "."
99 Access value can't be used with specified mode
101 Invalid operator for object
102 Can't LSet a type with a variable-length string
103 Syntax error
105 No members defined
106 Duplicate type member
107 Set is for object assignments
109 Invalid character in octal number
110 Invalid numeric prefix: expecting &H or &O
111 End of script encountered in comment: expecting */
112 Misplaced line continuation
113 Invalid escape sequence
114 Missing End Inline
115 Statement expected
116 ByRef argument mismatch
Error
Number Error Message
117 Integer overflow
118 Long overflow
119 Single overflow
120 Double overflow
121 Currency overflow
122 Optional argument must be Variant
123 Parameter must be optional
124 Parameter is not optional
125 Expected: Lib
126 Illegal external function return type
127 Illegal function return type
128 Variable not defined
129 No default property for the object
130 The object does not have an assignable default property
131 Parameters cannot be fixed length strings
132 Invalid length for a fixed length string
133 Return type is different from a prior declaration
134 Private variable too large. Storage space exceeded
135 Public variables too large. Storage space exceeded
136 Type-declaration character not allowed for variable with explicit type
137 Missing parameters are not allowed when using named parameters
138 An unnamed parameter was found following a named parameter
139 Unknown parameter name: placeholder
140 Duplicate parameter name: placeholder
141 Expecting: #If, #ElseIf, #Else, #End If, or #Const
142 Invalid preprocessor directive
143 Expecting preprocessor variable
144 Expecting: =
145 Expecting: [end of line]
146 Expecting: <expression>
148 Expecting: )
149 Unexpected value
150 Expecting: #End If
151 Expecting: Then
152 Missing #End If
153 #Else encountered without #If
154 #ElseIf encountered without #If
155 #End If encountered without #If
Error
Number Error Message
156 Invalid use of Null
157 Type mismatch
158 Not a number
159 Duplicate subroutine definition
160 Duplicate function definition
161 MBCS characters not allowed in identifiers
162 Out of range
163 Invalid date
164 Date overflow
165 Expecting: <identifier>
166 Constant type and expression are different types
167 Invalid use of New
168 Encountered: placeholder
Expecting: placeholder
169 For Each control variable on arrays must be a variant
170 For Each control variable on collections must be a variant or an object
171 For Each may not be used on an array of user-defined types or fixed-length
strings
172 For Each may only iterate over an object collection or an array
173 Not inside a For...Next statement
174 Invalid use of parenthesis with property
175 Object does not support For Each
176 Improper use of method that does not return a value
177 Improper use of method that returns a value
178 Sub or Function not allowed
179 Overflow in binary value
180 Private statement not allowed
BasicScript Limitations
• The default stack size for executing scripts is 2,048 bytes. This space contains all
local variables and passed parameters (arrays and variable-length strings only
require 2-bytes of stack, as their contents are contained in string space).
The stack is also used by the runtime for storage of intermediate values, so the
actual stack space available for storage of local variables may be slightly less.
Calls made to subroutines or functions in other scripts use the stack of the caller.
Note: The application hosting BasicScript may increase the size of the stack up
to a maximum of 8K.
• The data area that holds each script’s private variables is limited to 16K per script.
This data space contains all private variables defined within the script
(variable-length strings and arrays require only 2 bytes of storage in the private
variable space, as their contents are stored in the string space).
• The data area that holds public variables is limited to 16K. This data space contains
all public variables defined by all scripts (variable-length strings and arrays require
only 2 bytes of storage in the public variable space, as their contents are stored in
the string space).
• Fixed-length strings have the same maximum size as variable-length strings, but
have a practical limit which is imposed by the data area from which they are
allocated.
Local fixed-length strings: If the maximum size of the stack is 2,048 bytes, then
the largest local fixed-length string will be slightly less than 2,048 bytes. On Win32
platforms, since each character is 2 bytes, this translates to slightly less than 1,024
characters.
Private and Public fixed-length strings: Since the maximum size of the storage
for private and public variables is 16K, this means that the largest fixed-length
string stored in either of these data areas is 16,384 characters. On Win32 platforms,
this translates to 8192 characters, since each character is 2 bytes. Considering that
there is likely to be other variables contained in these data areas, the actual limit
may be much less.
Fixed-length strings contained in arrays and structures are stored along with the
other members of these compound data items, and are thus restricted in size to the
limits from which their containing data items are allocated.
• The Visual Basic declaration modifiers Static and Shared are not supported.
• The size of a source script is limited to 65,534 characters under Windows 3.1. This
limitation can be avoided by breaking up large scripts into smaller ones.
On all other platforms, script size is limited by available memory.
• The maximum number of lines in a script is limited to 65,535 lines.
• A compiled script consists of p-code, constant initialized data, and symbolic
information. On all platforms, the maximum size of the constant data is limited to
65,535 bytes. Similarly, the maximum size of the symbolic information is 65,535
bytes. (These limitations are rarely encountered, if ever.)
Under Windows, the maximum size of the code is 65,535 bytes. On all other
platforms, the maximum size of the code is limited only by available memory.
The 64K limitations under Windows can be avoided by breaking up large scripts
into smaller ones, which is rarely necessary.
• Arrays can have up to 60 dimensions.
• Variable names are limited to 80 characters.
• Labels are limited to 80 characters.
• Each executing script contains a table of structures that track calls made to external
routines. Each structure is approximately 88 bytes with an overall size limited to
64K.
• The number of open DDE channels is not fixed; rather, it is limited only by
available memory and system resources.
• The number of open files is limited to 512 or the operating system limit, whichever
is less.
• The maximum size of a string literal (a string enclosed within quotation marks) is
limited to 1,024 bytes. (Strings can be concatenated using the concatenation [&]
operator with the normal string limit of 32,764 bytes.)
On wide-character systems (i.e., UNICODE on Win32 platforms), 1024 bytes
ranslates to 512 characters. On single-byte, this translates to 1,024 characters. On
multibyte systems, the maximum length depends on the number of 2-byte
characters.
• The number of nesting levels (i.e., loops within loops) is limited by compiler
memory.
• Queue playback buffer size is limited to 64K. With 10 bytes per event, this allows
for 6,553 events.
• Each GoSub requires 4 bytes of the BasicScript runtime stack.
• Arrays and user-defined types cannot be passed to a method of an OLE Automation
object.
• Arrays and user-defined types cannot be set as the value of a property of an OLE
Automation object.
• Arrays and user-defined types cannot be returned from a method or property of an
OLE Automation object.
• Array indexes must be in the following range:
-32,768 <= array-index <=32,767
• The size of an array cannot exceed 32K. For example, an array of integers, each of
which requires 2 bytes of storage, is limited to the following maximum number of
elements:
max_num_elements = (32,767 - overhead) / 2
APPENDIX E
BasicScript/Visual Basic
Differences
This appendix describes the differences between Visual Basic 4.0 and BasicScript
version 2.2.
The following topics are covered:
• Arrays
• Constants
• Data Types
• Debugging
• Declarations
• Declare Statement
• Error Handling
• Floating-Point Numbers
• Currency Numbers
• Language Element Differences
• Natural Language Support
• Objects
• Parameter Passing
• Strings
• Variants
• Stack Size
• Expression Evaluation
• File Searching
Arrays
Visual Basic supports huge arrays, BasicScript does not.
BasicScript and Visual Basic differ in the way that elements are stored in memory.
Visual Basic stores elements in column-major order such as FORTRAN, meaning that
the leftmost dimension changes first. For example, consider the following statement:
Dim a(1 To 3,1 To 2)
In Visual Basic, the elements are stored in memory as follows:
a(1,1)
a(2,1)
a(3,1)
a(1,2)
a(2,2)
a(3,2)
BasicScript uses the same element ordering as C where the lower dimension changes
first, as shown below:
a(1,1)
a(1,2)
a(2,1)
a(2,2)
a(3,1)
a(3,2)
This difference impacts code that passes arrays to external routines using Declare and
the use of the For...Each statement.
Constants
Visual Basic supports shared constants (using the Public keyword). In BasicScript,
constants must be repeated within each script in which they are used.
Visual Basic does not allow the concatenation of constant elements. For example, the
following script compiles in BasicScript but not in Visual Basic:
Const t$ = "Hello" & Chr$(9) & "there."
Sub Main()
MsgBox t$
End Sub
Visual Basic allows a user to redefine global constants at the subroutine/function level
without affecting their global values; BasicScript does not. For example, the following
script will compile and execute in Visual Basic but not in BasicScript:
Const t$ = "Hello"
Sub Main()
Const t$ = "Good-bye"
MsgBox t$
End Sub
Declarations
Visual Basic supports the Static keyword as a modifier for the Sub and Function
statements. BasicScript supports use of this keyword with these statements syntactically,
but has no effect symantecally.
A variable used in a comparison expression that hasn't been declared will be implicitly
declared in Visual Basic. In BasicScript, this will be seen as an unresolved function:
Sub Main
If a$ = "Hello" Then Beep
End Sub
In BasicScript, the above script will compile, but it gives a Sub or Function not defined
error when executed. In Visual Basic, this will automatically declare a variable called a$
as a String.
Debugging
While debugging, the trace function will execute a single-line If...Then statement as
multiple units, requiring two presses of the F8 key. The first trace will execute the
condition and the second will execute one of the statements.
Declare Statements
Visual Basic supports shared Declare statements (using the Public keyword). In
BasicScript, these must be declared in every script in which they are used.
BasicScript supports a superset of that functionality available in Visual Basic—namely,
the additional calling conventions.
BasicScript and Visual Basic pass values to external routines in the same manner, with
the following exceptions:
• BasicScript passes True or False as Boolean values (signed short in C). Visual Basic
passes these as Boolean variants.
• Arrays are passed to external routines as OLE safearrays. BasicScript passes arrays
as a pointer to the first array element.
• Variants are passed as internal variant structures in both BasicScript and Visual
Basic. For all numeric values, the types are the same.
The variant structure in both systems is a 4-byte type (a 32-bit integer—the same
value as returned by the VarType function), followed by 4 bytes of slop, followed by
the value of the variable, as shown below:
Error Handling
The On Error Resume Next statement causes execution to continue on the next line
rather than at the next statement. This difference is only visible when you have placed
more than one statement on the same line, separated with a colon. For example, the
following code displays nothing in BasicScript, while, in Visual Basic, will display a
dialog:
Sub Main
On Error Resume Next
Error 10 : MsgBox "Hello, world."
End Sub
Floating-Point Numbers
In Visual Basic, floating-point numbers are interpreted as doubles unless they are
explicitly accompanied by a type-declaration character. Thus, the following line assigns
a Double in Visual Basic, whereas in BasicScript, it assigns a Single:
a = 0.00001
In BasicScript, additional checking is performed to determine whether a floating-point
number can be accurately represented as a Single. If so, then the number is stored as a
Single, requiring 4 bytes rather than 8.
The implications of this difference can be seen in the following code:
Dim a As Variant,b As Variant
a = 1000
b = .00001
a=a+b
MsgBox a
In Visual Basic, since the variables a and b are assigned Double values, the addition is
performed between two doubles, resulting in the value 1000.00001. In BasicScript, on
the other hand, a and b are assigned Single values, resulting in an addition between two
singles. When these two singles are added, there is a loss of precision resulting in the
value 1000.
In situations such as this, you should explicitly force the types using type-declaration
characters. The above code can be rewritten as follows:
Dim a As Variant,b As Variant
a = 1000#
b = .00001#
a=a+b
MsgBox a 'BasicScript displays 1000.00001.
Currency Numbers
In Visual Basic, Double numbers do not convert to Currency numbers the same way. In
Visual Basic, for example, the following script will fail:
Sub Main
result = CCur("-1.401298E-45")
End Sub
The above fails in Visual Basic because the number being converted is known to be a
Double. In BasicScript, any number between the valid range supported by Currency is
convertible to Currency, even if the number is expressed in scientific notation or is
extremely small (approaching zero).
cannot accept semi-colons as space separators, nor will it accept trailing commas or
semi-colons. Both the Print and Write statements in BasicScript reject spaces as
parameters separators.
The Const statement in BasicScript can only be used outside the scope of any subroutine
or function declaration. In Visual Basic, Const statements appearing within the
definition of a subroutine or function have scope local to that routine.
BasicScript does not support any of the following Visual Basic language elements:
Array Function
Exit Property Statement
For Each...Next Statement
LoadPicture Function
On...Gosub Statement
On...Goto Statement
Option Private Statement
Property Get...End Property Statement
Property Let...End Property Statement
Property Set...End Property Statement
SavePicture Statement
[Link] Property
Static Statement
With...End With Statement
Objects
BasicScript does not support any of Visual Basic's objects (except Clipboard, Screen,
and a few others).
Strings
In BasicScript, variable-length strings within structures require 2 bytes of storage. In
Visual Basic, variable-length strings within structures require 4 bytes of storage.
The implications of this difference can be seen in the following code:
Type Sample
LastName As String
End Type
Sub Main
Dim a As Sample
MsgBox Len(a)
End Sub
In the above code, Visual Basic displays 4, whereas BasicScript displays 2.
In BasicScript, variable-length strings are limited to 32K in length. In Visual Basic,
variable-length strings have no limits on their lengths.
Visual Basic will not accept strings in some functions expecting numbers such as Int and
Fix. BasicScript allows strings as long as they are convertible to numbers.
Dim A As Variant
Abs(19) 'OK.
A = "10"
Abs(A) 'OK.
Abs("10") 'Works in BasicScript, not in Visual Basic
In BasicScript, these functions will accept any data type convertible to a number. If the
data type is a String, BasicScript converts it to a Double.
Fixed-length strings within structures are size-adjusted upward to an even size. Thus,
structures in BasicScript are always even-sized. Visual Basic allows fixed-length strings
within structures to maintain an odd size.
Variants
Passing variants either by value or by reference to external routines (using the Declare
statement) passes either the entire variant structure (ByVal) or a pointer to a variant
structure (ByRef) used internally by BasicScript. This means that passing variants to an
externally declared routine can only be done if that routine is aware of the internal
variant structure used by BasicScript.
Visual Basic supports variant arrays; BasicScript does not. This includes use of the
Array function.
Stack Size
BasicScript uses a default stack of 2K, expandable to 8K. Visual Basic use a much
larger stack size (approximately 48K).
Since the stack for BasicScript is smaller, you may have to be more attentive when
using local variables, especially fixed-length strings and structures, since storage for all
local variables comes from the stack.
Note: Variable-length strings only require 2 bytes of storage on the stack. Wherever
possible, use variable-length strings in place of fixed-length strings.
Expression Evaluation
With Boolean expressions (i.e., expressions involving And, Or, Xor, Eqv, and Imp), if one
operand is Null and the other argument is numeric, then Null is returned regardless of the
value of the other operand. For example, the following expression returns Null:
Null And 300000
Despite the fact that the expression returns Null, Visual Basic evaluates the numeric
operand anyway, converting it to a Long. If an overflow occurs during conversion, a
trappable runtime error is generated. In BasicScript, the expression returns Null
regardless of the value of the numeric operand. For example, the following expression
will overflow in Visual Basic but not in BasicScript:
Null And 5E200
File Searching
The filename-matching algorithm used by BasicScript is different from that used by
Visual Basic. This affects commands that perform directory searching, such as Dir, Kill,
and FileList. The following differences exist:
• In Visual Basic, an asterisk within the filename matches any characters up to the
end of the filename or up to the period, whichever comes first.
• In Visual Basic, the period is a separator between the filename and the extension. In
BasicScript, the period is treated as a normal filename character.
The following table describes the meaning of some common file specifications.:
s*e All files that begin with "s". All files that begin with "s" and
end with "e".
s*.* All files that begin with "s". All files that begin with "s" and
have an extension.
test.* All files having the root name All files having the root name
"test" with any extension, such "test" with an extension. The
as "test", "[Link]", and so on. file "test" with no extension will
not be found.
This filename-matching algorithm is the same across all platforms that support
BasicScript.
active closing
application 167–168 all files 413
window 167–168 applications 47
entire screen 167–168 files 104
cascading desktop windows 165 windows 503–504
Case Else (statement) 427 collections
case sensitivity, when comparing strings 368–369 defined 358
case statement 426–428 elements, identifying 358
CBool (function) 89–90 indexing 358
CCur (function) 90–91 methods of 358
cd audio, Mci (function) 323–325 properties of 358
CDate, CVDate (functions) 91 colors, changing desktop 165–166
CDbl (function) 91–92 combo boxes
CDecl (keyword) 149–162 adding to dialog template 104–106
CDecl calling convention 150 checking
character for existence of 107–108
codes 65–66 if enabled 106–107
converting to number 65–66 getting
ChDir (statement) 92–93 number of items in 261
ChDrive (statement) 93–94 selection of 260
check boxes selecting item from 430–431
adding to dialog template 94–95 setting
checking edit field of 190
for existence of 96 items in 183–184
if enabled 95–96 ComboBox (statement) 104–106
getting state of 259 ComboBoxEnabled (function) 106–107
setting state of 193, 437 ComboBoxExists (function) 107–108
CheckBox (statement) 94–95 command line, retrieving 108
CheckBoxEnabled (function) 95–96 Command, Command$ (functions) 108
CheckBoxExists (function) 96 comments 108–109
Choose (function) 96–97 ' (apostrophe) 25
Chr, Chr$ (functions) 97–99 Rem (statement) 412–413
CInt (function) 99–100 common dialogs, file open 365–366
Clipboard comparing strings 462–463
erasing 101 comparison operators 109–111
getting table of 109
contents of 100, 102 used with
type of data in 101–102 mixed types 109
placing snapshots into 167–168 numbers 110
setting contents of 100–101, 103 strings 110
Clipboard$ (function) 100 variants 110
Clipboard$ (statement) 100–101 compatibility mode, opening files in 363
[Link] (method) 101 compiler errors 541
[Link] (method) 101–102 concatenation operator (&) 30
[Link] (method) 102 conditionals
[Link] (method) 103 Choose (function) 96–97
CLng (function) 103–104 If...Then...Else (statement) 276–277
Close (statement) 104 IIf (function) 278
MsgBox (statement), constants used with New (keyword) 173, 350–351, 435–436
ebExclamation (constant) 117 Next (keyword) 236–237, 238–239
ebIgnore (constant) 118 NLMs
ebInformation (constant) 117 file extension for, default 160
ebNo (constant) 118 search rules for 160
ebOK (constant) 118 Not (operator) 351–352
ebOKCancel (constant) 117 Nothing (constant) 113
ebOKOnly (constant) 117 used with Is (operator) 292
ebQuestion (constant) 117 Now (function) 352
ebRetry (constant) 118 NPer (function) 352–353
ebRetryCancel (constant) 117 Npv (function) 353–355
ebSystemModal (constant) 118 Null
ebYes (constant) 118 checking for 296
ebYesNo (constant) 117 propagation of 113
ebYesNoCancel (constant) 117 versus Empty 113
MsgClose (statement) 333 Null (constant) 113
nulls, embedded within strings 465
numbers
N adding 37
Name (statement) 340–341 converting
naming conventions, of from strings 490–491
constants 111 to strings 461–462
labels 269 floating-point 201, 442–443
variables 174 getting sign of 439–440
negation IsNumeric (function) 296–297
logical 351–352 octal representation 315
unary minus operator 25–26 printing 384–385
nesting, For...Next (statement) 236, 238 reading from
net present value, calculating 353–355 binary/random files 254–256
[Link] (method) 342–343 sequential files 282–284
[Link]$ (method) 343–344 testing for 296–297
[Link] (method) 344 truncating 235, 288–289
[Link] (method) 345 writing to
[Link] (method) 345–348 binary/random files 394–396
[Link]$ (method) 349–350 sequential files 385–387, 512–513
[Link]$ (property) 350 numeric operators
NetWare, BasicScript language elements supported * (operator) 32
on 517 + (operator) 36–37
networks - (operator) 25–26
canceling connection 344 / (operator) 33–34
capabilities of 345–348 \ (operator) 34
getting ^ (operator) 34–35
name of connection 349–350
user name 350 O
invoking
browse dialog box 343–344 Object (data type) 355–356
network dialog 345 storage requirements for 355
redirecting local device 342–343 objects 356–358
setting current time 481–482 UNIX, BasicScript language elements supported on 517
Time, Time$ (functions) 480–481 Unlock (statement). See Lock, Unlock (statements)
Time, Time$ (statements) 481–482 unlocking file regions 317–318
Timer (function) 482, 482 unsupported language elements 125
TimeSerial (function) 482 UPDATE (SQL statement) 457
TimeValue (function) 483 uppercasing strings 488
trigonometric functions user dialogs
Atn (function) 68–69 automatic timeout for 169
Cos (function) 121–122 available controls in 81
Sin (function) 442 Begin Dialog (statement) 81–83
Tan (function) 476–477 CheckBox (statement) 94–95
Trim, Trim$, LTrim, LTrim$, RTrim, RTrim$ ComboBox (statement) 104–106
(functions) 483–484 control outside bounds of 186
trimming, leading spaces from strings 483–484 creating 81–83
True (constant) 113 default button for 169
truncating numbers 235, 288–289 Dialog (function) 168–170
twips per pixel, calculating 423, 423 Dialog (statement) 170
Type (statement) 484–485 dialog procedures of 185–188
type checking, relaxed, with Declare (statement) 44–45 DlgControlId (function) 179–180
type coercion 224 DlgEnable (function) 180–181
type-declaration characters DlgEnable (statement) 181–182
effect on interpretation when reading numbers from DlgFocus (function) 182
sequential files 282 DlgFocus (statement) 182–183
for DlgListBoxArray (function) 183–184
Currency 130 DlgProc (function) 185–188
Double 201 DlgSetPicture (statement) 188–190
Integer 289 DlgText (statement) 190–191
Long 320 DlgText$ (function) 191–192
Single 443 DlgValue (function) 192–193
String 465 DlgValue (statement) 193–194
used DlgVisible (function) 194
when converting to number 296 DlgVisible (statement) 194–197
when declaring literals 315–316 DropListBox (statement) 201–203
with Dim (statement) 173 expression evaluation within 82
with external subroutines and functions 150 GroupBox (statement) 270–271
idle processing for 187
invoking 168–170, 170
U ListBox (statement) 312–313
UBound (function) 487–488 nesting capabilities of 187
UCase, UCase$ (functions) 488 OKButton (statement) 359–360
unary minus operator 25–26 OptionButton (statement) 371–372
underflow 38 OptionGroup (statement) 373–374
uninitialized objects 355, 356 Picture (statement) 377–379
Nothing (constant) 113 PictureButton (statement) 379–380
testing for with Is (operator) 292 pressing Enter within 359
universal date format pressing Esc within 88
reading 282 PushButton (statement) 393–394
used with literals 132, 315 required statements within 82