bm_cimplicity_basic_control_engine_and_scripting_reference_master
bm_cimplicity_basic_control_engine_and_scripting_reference_master
PROFICY CIMPLICITY
HMI/SCADA
Basic Control Engine and
Scripting Reference
Proprietary Notice
The information contained in this publication is believed to be accurate and reliable. However, General
Electric Company assumes no responsibilities for any errors, omissions or inaccuracies. Information
contained in the publication is subject to change without notice.
No part of this publication may be reproduced in any form, or stored in a database or retrieval system,
or transmitted or distributed in any form by any means, electronic, mechanical photocopying,
recording or otherwise, without the prior written permission of General Electric Company. Information
contained herein is subject to change without notice.
Trademark Notices
GE, the GE Monogram, and Predix are either registered trademarks or trademarks of General Electric
Company.
Microsoft® is a registered trademark of Microsoft Corporation, in the United States and/or other
countries.
We want to hear from you. If you have any comments, questions, or suggestions about our
documentation, send them to the following email address:
[email protected]
Contents
Chapter 1. Script Editors...................................................................................................................... 31
Dialog Editor................................................................................................................................................69
Dialog Editor........................................................................................................................................ 69
Debug Scripts....................................................................................................................................138
3. Use Breakpoints............................................................................................................................146
Run a Program..........................................................................................................................................161
Error Messages.........................................................................................................................................162
Arrays................................................................................................................................................. 195
Clipboard............................................................................................................................................196
Comments......................................................................................................................................... 196
Conversion.........................................................................................................................................198
Data Types.........................................................................................................................................199
Database............................................................................................................................................200
Date/time........................................................................................................................................... 200
DDE.....................................................................................................................................................201
Financial.............................................................................................................................................203
INI Files..............................................................................................................................................204
Logical/binary Operators..................................................................................................................205
Math................................................................................................................................................... 205
Miscellaneous................................................................................................................................... 206
Numeric Operators............................................................................................................................206
Objects............................................................................................................................................... 206
Parsing............................................................................................................................................... 207
Predefined Dialogs............................................................................................................................207
Printing...............................................................................................................................................207
Procedures.........................................................................................................................................208
Strings................................................................................................................................................ 208
Variants..............................................................................................................................................211
Symbols..................................................................................................................................................... 211
Symbols............................................................................................................................................. 211
' (keyword)..........................................................................................................................................212
- (operator).........................................................................................................................................212
() (keyword)....................................................................................................................................... 218
* (operator)........................................................................................................................................ 219
. (keyword).........................................................................................................................................220
/ (operator)........................................................................................................................................ 221
\ (operator)........................................................................................................................................ 222
Contents | vi
^ (operator)........................................................................................................................................ 223
_ (keyword)........................................................................................................................................ 224
+ (operator)....................................................................................................................................... 224
< (operator)........................................................................................................................................226
<= (operator)......................................................................................................................................226
<> (operator)......................................................................................................................................226
= (operator)........................................................................................................................................226
= (statement).....................................................................................................................................227
> (operator)........................................................................................................................................227
>= (operator)......................................................................................................................................227
A................................................................................................................................................................. 228
A......................................................................................................................................................... 228
AppGetActive$ (function).................................................................................................................237
AppGetState (function).....................................................................................................................239
AppList (statement)..........................................................................................................................241
AppMaximize (statement)................................................................................................................241
AppMinimize (statement).................................................................................................................242
AppMove (statement).......................................................................................................................243
AppSetState (statement)..................................................................................................................245
Contents | vii
AppShow (statement).......................................................................................................................246
ArrayDims (function).........................................................................................................................249
Arrays (topic).....................................................................................................................................250
B................................................................................................................................................................. 258
B......................................................................................................................................................... 258
Basic.Architecture$ (property).........................................................................................................259
Basic.HomeDir$ (property)...............................................................................................................262
Basic.OperatingSystemVersion$ (property)....................................................................................265
Basic.OS (property)...........................................................................................................................266
C................................................................................................................................................................. 274
C......................................................................................................................................................... 274
CCur (function)..................................................................................................................................278
ChDrive (statement)..........................................................................................................................280
Clipboard$ (function)........................................................................................................................288
Clipboard.GetFormat (method)........................................................................................................291
Const (statement).............................................................................................................................299
CStr (function)...................................................................................................................................307
CVar (function)..................................................................................................................................309
D................................................................................................................................................................. 311
D......................................................................................................................................................... 311
DateSerial (function).........................................................................................................................321
DateValue (function).........................................................................................................................322
Day (function)....................................................................................................................................322
DDB (function)...................................................................................................................................323
DDETerminate (statement)...............................................................................................................330
DDETimeout (statement)..................................................................................................................332
DefType (statement).........................................................................................................................333
DlgEnable (statement)......................................................................................................................346
DlgProc (function).............................................................................................................................352
DlgSetPicture (statement)................................................................................................................355
DlgValue (statement)........................................................................................................................362
Do...Loop (statement).......................................................................................................................366
DoEvents (statement).......................................................................................................................369
E................................................................................................................................................................. 373
E..........................................................................................................................................................373
ebAbort (constant)............................................................................................................................376
ebDefaultButton1 (constant)............................................................................................................381
ebDefaultButton2 (constant)............................................................................................................382
ebDefaultButton3 (constant)............................................................................................................382
ebDirectory (constant)......................................................................................................................382
ebError (constant).............................................................................................................................384
ebItalic (constant).............................................................................................................................387
ebOKOnly (constant).........................................................................................................................392
ebQuestion (constant)......................................................................................................................392
ebRetryCancel (constant).................................................................................................................394
ebSingle (constant)...........................................................................................................................395
ebSystemModal (constant)..............................................................................................................396
ebYes (constant)...............................................................................................................................398
Eqv (operator)....................................................................................................................................402
Erl (function)......................................................................................................................................404
Error (statement)...............................................................................................................................407
Err.Clear (method).............................................................................................................................408
Err.HelpFile (property).......................................................................................................................412
Err.Number (property).......................................................................................................................414
Err.Source (property).........................................................................................................................417
Exit Do (statement)...........................................................................................................................418
Exp (function)....................................................................................................................................421
F................................................................................................................................................................. 423
F..........................................................................................................................................................423
FileAttr (function)..............................................................................................................................424
FileDateTime (function)....................................................................................................................427
Contents | xiv
FileList (statement)...........................................................................................................................430
For...Next (statement).......................................................................................................................436
FreeFile (function).............................................................................................................................445
Fv (function)...................................................................................................................................... 446
G.................................................................................................................................................................447
G......................................................................................................................................................... 447
Goto (statement)...............................................................................................................................457
H.................................................................................................................................................................458
H......................................................................................................................................................... 458
HelpButton (statement)....................................................................................................................459
Hour (function)..................................................................................................................................461
Contents | xv
HScroll (statement)...........................................................................................................................462
I.................................................................................................................................................................. 465
I...........................................................................................................................................................465
IIf (function).......................................................................................................................................468
IMEStatus (function).........................................................................................................................468
Input# (statement)............................................................................................................................471
Int (function)......................................................................................................................................478
Is (operator).......................................................................................................................................482
IsError (function)...............................................................................................................................485
IsMissing (function)..........................................................................................................................486
IsNumeric (function).........................................................................................................................487
IsWebSpaceSession (function)........................................................................................................489
K................................................................................................................................................................. 491
K......................................................................................................................................................... 491
Kill (statement)..................................................................................................................................491
L................................................................................................................................................................. 493
L..........................................................................................................................................................493
Len (function)....................................................................................................................................496
Like (operator)...................................................................................................................................499
Line$ (function).................................................................................................................................501
LineCount (function).........................................................................................................................502
Loc (function)....................................................................................................................................506
Lock (statement)...............................................................................................................................507
Log (function)....................................................................................................................................510
M................................................................................................................................................................ 513
M.........................................................................................................................................................513
MkDir (statement).............................................................................................................................521
Msg.Open (method)..........................................................................................................................523
N.................................................................................................................................................................530
N......................................................................................................................................................... 530
Name (statement).............................................................................................................................531
Net.AddCon (method).......................................................................................................................533
Net.CancelCon (method)..................................................................................................................535
Net.GetCaps (method)......................................................................................................................536
Not (operator)....................................................................................................................................540
Nothing (constant)............................................................................................................................541
NPer (function)..................................................................................................................................542
O.................................................................................................................................................................545
O......................................................................................................................................................... 545
Objects (topic)...................................................................................................................................547
OKButton (statement).......................................................................................................................551
On Error (statement).........................................................................................................................552
Open (statement)..............................................................................................................................554
OpenFilename$ (function)................................................................................................................558
Or (operator)......................................................................................................................................567
P................................................................................................................................................................. 568
P......................................................................................................................................................... 568
Pi (constant)......................................................................................................................................569
Picture (statement)...........................................................................................................................570
PictureButton (statement)................................................................................................................572
PopupMenu (function)......................................................................................................................575
PPmt (function).................................................................................................................................576
Print (statement)...............................................................................................................................577
Contents | xix
Pv (function)......................................................................................................................................588
Q.................................................................................................................................................................589
R................................................................................................................................................................. 590
R..........................................................................................................................................................590
Random (function)............................................................................................................................591
Randomize (statement)....................................................................................................................591
RCPDownload (statement)...............................................................................................................593
RCPGroupExportEx (function)..........................................................................................................596
RCPUpload (statement)....................................................................................................................597
ReadIniSection (statement)..............................................................................................................600
Return (statement)............................................................................................................................604
S................................................................................................................................................................. 609
S..........................................................................................................................................................609
SaveSetting (statement)...................................................................................................................613
Seek (function)..................................................................................................................................618
Seek (statement)...............................................................................................................................619
Select...Case (statement).................................................................................................................620
Sgn (function)....................................................................................................................................628
Shell (function)..................................................................................................................................629
Sin (function).....................................................................................................................................631
Sln (function).....................................................................................................................................632
Spc (function)....................................................................................................................................633
SQLBind (function)............................................................................................................................634
SQLClose (function)..........................................................................................................................636
SQLGetSchema (function)................................................................................................................639
SQLRetrieve (function)......................................................................................................................646
StrConv (function).............................................................................................................................652
Switch (function)...............................................................................................................................657
System.MouseTrails (method).........................................................................................................660
System.TotalMemory (property)......................................................................................................661
System.WindowsDirectory$ (property)............................................................................................661
T................................................................................................................................................................. 662
T..........................................................................................................................................................662
Tab (function)....................................................................................................................................663
Tan (function)....................................................................................................................................664
Text (statement)................................................................................................................................664
True (constant)..................................................................................................................................673
Type (statement)...............................................................................................................................673
TypeName (function)........................................................................................................................675
U................................................................................................................................................................. 677
U......................................................................................................................................................... 677
UBound (function).............................................................................................................................677
V................................................................................................................................................................. 682
V......................................................................................................................................................... 682
Val (function).....................................................................................................................................683
VPage (statement)............................................................................................................................690
VScroll (statement)...........................................................................................................................690
W................................................................................................................................................................ 691
W........................................................................................................................................................ 691
Weekday (function)...........................................................................................................................692
Width# (statement)...........................................................................................................................694
WinActivate (statement)...................................................................................................................695
WinClose (statement).......................................................................................................................696
Write# (statement)............................................................................................................................706
X................................................................................................................................................................. 708
X or (operator)...................................................................................................................................708
Y................................................................................................................................................................. 710
AlarmUpdate (statement).................................................................................................................726
AlarmUpdateCA (statement)............................................................................................................727
AlarmUpdateEx (statement).............................................................................................................729
CimChangeApprovalData (Object)...................................................................................................734
CimEMEvent.PointEvent................................................................................................................... 740
CimEMPointEvent.Id......................................................................................................................... 741
CimGetEMEvent (function)...............................................................................................................747
CimLogin (statement).......................................................................................................................748
CimProjectData.GetNext (function).................................................................................................750
DoUQINTMath (function)..................................................................................................................768
GetCurTimeHR (function).................................................................................................................769
GetMemoryInfoPublicSpace (statement)........................................................................................775
Point.Cancel (method)......................................................................................................................780
Point.EnableAlarm (method)............................................................................................................785
Point.GetNext (function)...................................................................................................................788
Point.GetQuadIntValue (function)....................................................................................................789
Point.GetTimeStampHR (statement)...............................................................................................791
Point (object).....................................................................................................................................794
Point.OnAlarmAck (statement)........................................................................................................797
Point.OnTimed (statement)..............................................................................................................798
Point.SetArray (statement)...............................................................................................................807
Point.SetElement (statement)..........................................................................................................808
Point.SetNoAudit (statement)..........................................................................................................809
Point (subject)...................................................................................................................................813
PointGetMultiple (function)..............................................................................................................821
PointGetNext (function)....................................................................................................................823
SetTimecomponentsHR (function)..................................................................................................831
QINTFromString (function)...............................................................................................................833
StringFromQINT (function)...............................................................................................................833
TraceEnable/TraceDisable (statement)...........................................................................................835
BCEUI Menus.....................................................................................................................................840
BCEUI Viewer.....................................................................................................................................843
Event Configuration...........................................................................................................................954
Schedules.......................................................................................................................................... 961
Security.............................................................................................................................................. 971
Component Description
Event Editor Provides the tools to defines actions to take in response to events that
occur in a process. An event can be a changing point, alarm state, or
even a particular time of day. One event may invoke multiple actions, or
one action may be invoked by many events.
Script Editors Provide a set of sophisticated development tools that let you create pro
grams. These programs can then be executed as actions in response to
events. Following are the three script editors provided by CIMPLICITY:
Basic Control Engine Monitors for events and executes the configured actions. The Basic Con
trol Engine is based on a multi-threaded design that allows the system to
invoke and execute multiple Visual Basic programs concurrently.
Either Or
3. Right-click Scripts.
4. Select New on the Popup menu.
5. Right-click any script (.bcl file).
6. Select New on the Popup menu.
7. Do the following.
Either Or
4. Right-click Scripts.
5. Select Open on the Popup menu.
6. Right-click a script.
7. Select Open on the Popup menu.
The Program Editor window can be divided into the following sections:
Basic Control Engine and Scripting Reference | 1 - Script Editors | 36
2 (on Toolbars
page
42)
Tip:
The areas can be resized by dragging the separators.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 37
You can use the menu options to open, close, print, and compile files, to edit a file, to run a file, to debug a
file, to access tools, to view status and toolbars, to arrange windows, and access help.
• File menu
• Edit menu
• Run menu
• Debug menu
• Tools menu
• View menu
• Window menu
• Help menu
File Menu
Save All Saves all the open files in the Program Editor.
Edit Menu
Goto Line Opens a Goto Line dialog box. The insertion point goes to the line number that is entered in
the Line Number field.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 39
View Menu
Toolbars Displays the list of available toolbars. You can toggle the display of each tool
bar.
Status Bar Toggles the display of the Status Bar at the bottom of program windows.
Run Menu
Debug Menu
Add Displays the Add Watch dialog box, in which you can specify the name of a script variable
Watch
Quick Do a quick check of a variable value, without adding the variable to the Watch list.
Watch
Step Executes the next line of the script. If the line calls a procedure, the called procedure is run in
its entirety.
Step Into Executes the next line of the script. If the line calls a procedure, the next line to execute will
be the first line of the called procedure.
Set Next Sets the next statement to be executed in a paused program to the currently selected line.
state
ment
Set Com Set the command line for the script. This can be retrieved via the basic Command$ parame
mand ter. The Basic Control Engine will pass the Event & Action which caused the script to be run.
Line See BCE Manual
Set Event
Informa
tion
Reset Re-set's the contents of public and private variables to an empty state.
Public
Variables
Tools Menu
Points Displays a submenu that lets you browse for points, edit a point, and create a new point. You
can also use this menu item to include Setpoints, Get Points, and create local variables in the
program.
Alarms Displays a submenu that lets you generate or update alarms in the program.
Log Displays a dialog box that lets you generate messages for the Status Log.
Status
Window Menu
Arrange Icons Arranges the program icons in the Program Editor win
dow.
Help Menu
Index Displays the main Help window for the Program Editor.
Using Help Displays the main Help window for Microsoft Windows.
About... Displays program information, version number, and copyright for the Program Edi
tor
Toolbar Window
Standard Main
Tool Main
Basic Control Engine and Scripting Reference | 1 - Script Editors | 43
Application Script
Standard Toolbar
Tools Toolbar
Application Toolbar
Status bar
Shortcut Description
key
F3 Finds the next occurrence of the string in the Find dialog box.
Alt+D+R Trace.
Shift+F8 Steps to the next line in the script. If the section is a procedure call, the next line is the first
line in the procedure.
String space Holds all string variables, arrays, and public da
ta.
The changes apply to all Basic Control Engine scripts that run as executables within the Program Editor or
from the Event Manager.
Field Description
4. Click OK.
You must stop and restart CIMPLICITY for the changes to take effect.
5. Click OK.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 48
Note:
◦ You can substantially reduce your stack usage by explicitly defining the types of variables (in
other words, don't use variants).
◦ Recursive routines have an impact on Stack Space.
◦ If you use arrays or arrays of User Defined Types, allocation occurs in the String Space that
may alleviate some stack usage.
Although, in some respects, editing code with the Program Editor is like editing regular text with a word-
processing program, the Program Editor also has certain capabilities specifically designed to help you edit
your code.
This section describes how to move around within your script, select and edit text, add comments to your
script, break long statements across multiple lines, search for and replace selected text, and perform a
syntax check of your script. The section ends with a brief discussion of editing dialog box templates.
When you move the insertion point with a keyboard shortcut, (on page 45) the Program Editor scrolls
the new location of the insertion point into view if it is not already displayed.
You can also reposition the insertion point with the mouse and the Goto Line command.
Note:
The Program Editor allows you to place the insertion point anywhere within your script, including
in "empty spaces." (Empty spaces are areas within the script that do not contain text, such as a
tabs expanded space or the area beyond the last character on a line.)
1. Use the scroll bars at the right and bottom of the display to scroll the target area of the script into
view if it is not already visible.
2. Place the cursor where you want to position the insertion point.
3. Click the left mouse button.
Note:
◦ This approach is especially fast if the area of the screen to which you want to move the
insertion point is currently visible.
◦ When you scroll the display with the mouse, the insertion point remains in its original
position until you reposition it with a mouse click. If you attempt to perform an editing
operation when the insertion point is not in view, Program Editor automatically scrolls the
insertion point into view before performing the operation.
4. Press F4.
5. Enter the number of the line in your script to which you want to move the insertion point.
6. Click the OK button or press Enter.
The insertion point is positioned at the start of the line you specified. If that line was not already
displayed, the Program Editor scrolls it into view.
Note:
• This approach is especially fast if the area of the screen to which you want to move the insertion
point is not currently visible but you know the number of the target line.
• The insertion point cannot be moved so far below the end of a script as to scroll the script entirely
off the display. When the last line of your script becomes the first line on your screen, the script will
stop scrolling, and you will be unable to move the insertion point below the bottom of that screen.
Position the insertion point at the desired location in the script and start typing.
guide:
Guidelines
• Text does not wrap. If you continue typing on a given line, eventually you will reach a point at which
you can enter no more text on that line.
• Press Enter to control the line breaks when you want to insert a new line in your script.
The effect of pressing Enter depends on where the insertion point is located at the time:
At or beyond the end of a A new line is inserted after the current line.
line
At the start of a line A new line is inserted before the current line.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 52
Within a line The current line is broken into two lines at that loca
tion.
The tab character is inserted at the location of the insertion point, which causes text after the tab to be
moved to the next tab position.
If you insert new text within a tab's expanded space, the text that originally appeared on that line is moved
to the next tab position each time the new text that you are entering reaches the start of another tab
position.
Tip:
Because you can position the insertion point in empty spaces, you can also insert text in empty
spaces. This is useful for inserting a comment (on page 67) in the space beyond the end of a
line in the script.
When you insert characters beyond the end of a line, the space between the insertion point and the last
character on the line is back filled with tab characters.
• Select text.
• Delete text.
Select text
You can use either the mouse or the keyboard to select text and other characters in your script.
Important:
Regardless of which method you use, you can select either a portion of one line or a series of
whole lines, but you cannot select a portion of one line plus one or more whole lines.
When you select multiple lines and start or end your selection partially through a line, the Program Editor
automatically extends the selection to include the entire starting and ending lines.
1. Place the insertion point where you want your selection to begin
2. Do one of the following.
◦ While pressing the left-mouse button
a. Drag the mouse until you reach the end of your selection.
b. Release the mouse button.
◦ Using the left-mouse button.
a. Place the mouse pointer in the left margin beside the first line you want to select.
b. The pointer becomes a reverse arrow, which points toward the line of text.
c. Click the left mouse button to select a single line.
d. Press the left mouse button and drag up or down to select multiple lines.
◦ While pressing Shift
a. Place the mouse pointer where you want your selection to end
b. Click the left mouse button.
3. Place the insertion point where you want your selection to begin.
4. While pressing Shift, use one of the navigating keyboard shortcuts to extend the selection to the
desired ending point.
Note:
When you intend to select an entire single line of text in your script, it is important to
remember to extend your selection far enough to include the hidden end-of-line character,
which is the character that inserts a new line in your script.
5. Place the insertion point at the beginning of the line you want to select.
6. Press Shift + Down arrow.
Place material from your script on the Clipboard by either cutting it or copying it.
• Cut a selection.
• Copy a selection.
• Paste text.
Cut a selection
Result: The selection is cut from the script and placed on the Clipboard.
Copy a selection
Basic Control Engine and Scripting Reference | 1 - Script Editors | 55
Result: The selection remains in the script, and a copy of it is placed on the Clipboard.
Paste text
5. Position the insertion point where the copied or cut text should be placed.
6. Do one of the following.
◦ Press Ctrl+V.
◦ Click the Paste (on page 43) button on the Program Editor toolbar.
◦ Click Edit>Paste on the Program Editor menu bar.
The contents of the Clipboard are pasted at the insertion point location.
Note:
If text is selected when you paste Clipboard text, the Clipboard text is inserted before the selected
text.
Any of the following editing operations that produce a change in the script can be undone.
Important:
You can undo the last 100 operations.
• Press Ctrl+Z
• Click Edit>Undo on the Program Editor menu bar.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 56
Result: The script is restored to the way it looked before you performed the editing operation.
Note:
Operations that do not produce any change in the script and cannot be undone include:
Program Editor makes it easy to search for specified text in your script and automatically replace
instances of specified text.
3. Do the following.
Feature Description
Basic Control Engine and Scripting Reference | 1 - Script Editors | 57
Match Check to limit the results to the case entered in the Find what field.
case
Find Next Click to start the search and continue the search when a match is found. Tip: You can
also press Enter.
Results
Tip:
If the Find dialog box blocks your view of an instance of the specified text, you can do
either of the following.
◦ Move the dialog box out of your way and continue with your search.
◦ Click Cancel.
The Find dialog box closes, but maintains the established search criteria.
Press F3 to find successive occurrences of the specified text without re-opening the Find dialog
box.
Note: If you press F3 when there is no entry in the Find what field the Program Editor opens the
Find dialog box.
5. Move the insertion point to where you the replacement operation should start.
7. Do the following.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 58
Fea Description
ture
Match Check to limit the results to the case entered in the Find what field.
case
Find Click to start the search and continue the search when a match is found. Tip: You can al
Next so press Enter.
Re Click to replace a found instance of the text. Result: When the text is replaced either of
place the following happens.
◦ The cursor highlights the next found instance
◦ A message reports that there are no more instances of the Find what text.
Re (Optional) Click to automatically replace all found instances of the Find what text with the
place replacement text. Result: All instances are replaced with no requests for confirmation.
All
The Program Editor provides tools to facilitate working with points in a script, as follows.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 59
1 (on Browse
page
59)
2 (on Edit
page
60)
3 (on New
page
61)
4 (on Set
page
62)
5 (on Get
page
62)
6 (on Dim
page
63)
1 Browse
Basic Control Engine and Scripting Reference | 1 - Script Editors | 60
1. Place the insertion point in the script where the selected point will be inserted.
2. Click Tools>Points>Browse on the Program Editor menu bar.
4. Click OK.
2 Ed
it
The Point Properties dialog box opens for the selected point.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 61
3 New
9. Place the insertion point in the script where the new point will be inserted.
10. Click Tools>Points>New on the Program Editor menu bar.
11. Create and configure a new point (in the Point Properties dialog box).
Result: The new point ID is inserted in the script at the insertion point.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 62
4 Set
13. Place the insertion point in the script where the PointSet (on page 826) statement will be
inserted.
14. Click Tools>Points>Set on the Program Editor menu bar.
Field Description
826) statement.
826) statement.
Example
5 Get
17. Place the insertion point in the script where the PointGet (on page 819) function will be inserted.
18. Click Tools>Points>Get on the Program Editor menu bar.
Field Description
819) function.
819) function.
Example
P = PointGet ("TANKLEVEL")
6 Dim
21. Place the insertion point in the script where a Dim (on page 338) statement will be inserted.
22. Click Tools>Points>Dim on the Program Editor menu bar.
Field Description
Basic Control Engine and Scripting Reference | 1 - Script Editors | 64
A Dim statement for a point or new point variable is inserted at the insertion point in the script.
Example
The Program Editor provides tools to facilitate working with alarms in a script, as follows.
1 Gener
ate
The Generate tool in the Program Editor is available for $CIMBASIC alarms.
1. Place the insertion point in the script where the selected alarm will be inserted.
2. Click Tools>Alarms>Generate on the Program Editor menu bar.
1. Fill in the fields for a $CIMBASIC alarm in the Generate Alarm dialog box.
Note: The fields in the Generate Alarm dialog box correspond to the AlarmGenerate (on page 719)
(method) syntax.
1. Click OK.
Result: The Program Editor inserts the specified AlarmGenerate (on page 719) (method) code at the
location of the insertion point in the script.
2 Update
The Update tool in the Program Editor is available for any CIMPLICITY alarm.
1. Place the insertion point in the script where the selected alarm will be inserted.
2. Click Tools>Alarms>Update on the Program Editor menu bar.
Note: The fields in the Update Alarm dialog box correspond to the AlarmUpdate (on page 726) (method)
syntax.
1. Click OK.
Result: The Program Editor inserts the specified AlarmUpdate (on page 726) (method) code at the
location of the insertion point in the script.
The fields correspond to the LogStatus (on page 779) (property, read/write) syntax.
You can add comments to your script to remind yourself or others of how your code works. Comments
are ignored when your script is executed.
The apostrophe symbol ( ' ) is used to indicate that the text from the apostrophe to the end of the line is a
comment.
Add a:
Result: When the script is run, the presence of the apostrophe at the start of the line will cause the
entire line to be ignored.
3. Position the insertion point in the empty space beyond the end of the line of code.
4. Type an apostrophe ( ' ).
5. Type a comment following the apostrophe.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 68
When the script is run, the code on the first portion of the line will be executed, but the presence of the
apostrophe at the start of the comment will cause the remainder of the line to be ignored.
Note:
Although you can place a comment at the end of a line containing executable code, you cannot
place executable code at the end of a line containing a comment; the presence of the apostrophe
at the start of the comment will cause the balance of the line (including the code) to be ignored.
1. Type the statement on multiple lines, exactly the way you want it to appear.
2. Place the insertion point at the end of the first line in the series.
3. Press the spacebar once to insert a single space.
4. Type an underscore ( _ ).
Note: The underscore is the line-continuation character, which indicates that the statement
continues on the following line.
5. Repeat 2 - 4 to place a line-continuation character at the end of each line in the series, except the
last.
If Program Editor has found a syntax error, the line containing the error is highlighted on your
display.
Basic Control Engine syntax provides several options for adding dialog boxes to a script.
Write a script beginning with Begin Dialog to add a dialog box to a script.
Dialog Editor
Dialog Editor
You can use a custom dialog box to display information to a user while providing an opportunity for the
user to respond. The Dialog Editor is a tool that enables you to create and modify custom dialog boxes
for use in your scripts. Although the statements used to display a custom dialog box and respond to
the choices made by a user of the dialog box may seem complicated, the Dialog Editor makes it easy to
generate these statements.
Fea Description
ture
1 Tool Collection of tools that you can use to provide instructions to the Dialog Editor, as discussed in
bar the following subsection
2 Dia Visual layout of the dialog box that you are currently creating or editing.
log
box
3 Sta Provides key information about the operation you are currently performing, including the name
tus of the currently selected control or dialog box, together with its position on the display and its
bar dimensions; the name of a control you are about to add to the dialog box with the mouse point
er, together with the pointer's position on the display; the function of the currently selected
menu command; and the activation of Dialog Editor's testing or capturing functions.
Tool Function
2 Information Displays the Information dialog box for the selected dialog box or con
trol.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 72
7 Select Lets you select, move, and resize items and control the insertion point.
19 Drop List Box Adds a drop list box to the dialog box.
• File menu
• Edit menu
• Controls menu
• Help menu
Basic Control Engine and Scripting Reference | 1 - Script Editors | 73
File Menu
Selection Function
Open... Opens the Open Dialog File dialog box, which you can use to open an existing dialog box
template.
Update Updates the template. Does one of the following in the open Program Editor script.
Save Opens a Save As Dialog File dialog box, which you can use to save the current dialog box
As... template in a file under the same or new name.
Capture Captures the standard Windows controls from a standard Windows dialog box in another
Dialog Windows application.
Exit & Re Closes the Dialog Editor and returns you to the host application.
turn
Basic Control Engine and Scripting Reference | 1 - Script Editors | 74
Edit Menu
Selec Function
tion
Undo Undo up to 10 preceding operations. The Undo command continually indicates the next opera
tion you can undo by selecting it and grays out when there are no more operations that can be
undone.
Cut Cuts the selected dialog box or control from the Dialog Editor window and places it on the Clip
board.
Copy Copies the selected dialog box or item, without removing it from the Dialog Editor window, and
places it on the Clipboard.
Paste Inserts cut or copied dialog box or items into the Dialog Editor.
Clear Deletes the selected dialog box or control from Dialog Editor's application window without plac
ing it on the Clipboard.
Size Adjusts the borders of certain items to fit the text displayed on them.
to
Text
Info... Displays an Information dialog box for the selected dialog box or item.
Controls Menu
Selection Function
Drop list box Adds a drop list box to the dialog box.
Help Menu
Selection Function
The following keyboard shortcuts can be used for some of the operations you will perform most
frequently in Dialog Editor.
Key(s) Function
Ctrl+C Copies the selected dialog box or control, without removing it from Dialog Editor's application
window, and places it on the Clipboard.
Ctrl+I Displays the Information dialog box for the selected dialog box or control.
Ctrl+V Inserts the contents of the Clipboard into Dialog Editor. If the Clipboard contains script state
ments describing one or more controls, then Dialog Editor adds those controls to the current di
alog box. If the Clipboard contains the script template for an entire dialog box, then Dialog Editor
creates a new dialog box from the statements in the template.
Ctrl+X Removes the selected dialog box or control from Dialog Editor's application window and places
it on the Clipboard.
Del Removes the selected dialog box or control from Dialog Editor's application window without
placing it on the Clipboard.
• Available controls
• Control guidelines
Available Controls
The Dialog Editor supports the following types of standard Windows controls, all of which are illustrated in
the above dialog box:
Basic Control Engine and Scripting Reference | 1 - Script Editors | 78
Fea Description
ture
Check Box that users can check or clear to indicate their preference regarding the alternative specified
box on the check box label.
Com Text field with a displayed, scroll list beneath it. Users can either select an item from the list or
bo enter the name of the desired item in the text field. The currently selected item is displayed in
box the text field. If the item was selected from the scrolling list, it is highlighted there as well.
Drop Field that displays the currently selected item, followed by a downward-pointing arrow, which
list users can click to temporarily display a scrolling list of items. Once a user selects an item in the
box list, the list disappears and the newly selected item displays in the field.
Group Rectangular design element used to enclose a group of related controls. An optional group box
box label is available to display a title for the controls in the box..
List Displayed scroll list from which users can select one item. The currently selected item is high
box lighted on the list.
but
ton
Op One of a group of two or more linked buttons that allows users select only one from a group of
tion mutually exclusive choices. Clicking an unselected button in the group selects that button and
but automatically de-selects the previously selected button in that group.
ton
Text Field into which users can enter text (potentially, as much as 32K).
box
• By default, the Text box holds a single line of non-wrapping text.
• The field can multiple lines of wrapping text.
Control Guidelines
• General guidelines
• Tabbing order.
• Option button grouping.
• Accelerator keys.
General guidelines
An OK button and a Cancel button are provided by default on a new dialog box.
• Group boxes, text controls, and pictures are passive elements in a dialog box, inasmuch as they
are used purely for decorative or informative purposes. Users cannot act upon these controls, and
when they tab through the dialog box, the focus skips over these controls.
• A Windows bitmap or metafile can be obtained from a file or from a specified library.
Tabbing order
Basic Control Engine and Scripting Reference | 1 - Script Editors | 80
The order in which you create the controls is what determines the tabbing order, not the position of the
controls in the dialog box.
The closer you can come to creating controls in the order in which you want them to receive the tabbing
focus, the fewer tabbing-order adjustments you will have to make later on.
If you want a series of option buttons to work together as a mutually exclusive group, you must create all
the buttons in that group one right after the other, in an unbroken sequence.
If you create a different type of control before you have finished creating all the option buttons in your
group, you will split the buttons into two or more separate groups.
Example
When you test the dialog box, the five buttons will not work together as a mutually exclusive group.
Instead the:
Accelerator keys
◦ A text box, list box, combo box, or drop list box by assigning an accelerator key to an
associated text control.
◦ The controls in a group box by assigning an accelerator key to the group box label.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 81
To do this, you must create the text control or group box first, followed immediately by the controls
that you want to associate with it. If the controls are not created in the correct order, they will not
be associated in your dialog box template and any accelerator key you assign to the text control or
group box label will not work properly.
Note:
You can only insert a control within the borders of the dialog box you are creating. You cannot
insert a control on the dialog box's title bar or outside its borders.
B Click the button (on page 71) on the Dialog Editor toolbar that corresponds to the type of
control you want to add.
2. Place the cursor in the dialog box where you want the upper left corner of the control to be
positioned.
◦ As soon as you place the cursor in the dialog box it changes to a crossbar accompanied by
a small image of the selected object.
◦ The Dialog Editor status bar displays the crossbar's coordinates.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 82
Results
◦ The selected control is placed in the dialog box. The upper left corner of the control
corresponds to the position of the pointer's crossbar at the moment you clicked the mouse
button.
◦ The object's upper left corner coordinates, width and height display on the Dialog Editor
status bar.
Note: The status bar displays this information anytime the mouse passes over a control or the
control is selected.
Tip:
Press Ctrl+D on the keyboard to add another control that is the same type as the control
that was just added.
Note:
Dialog units represent increments of the font (8 point Helvetica) in which the Dialog Editor creates
dialog boxes.
Option Description
Horizontal Space between horizontal grid marks. The higher the number the further apart the
(X) grid marks.
Vertical (Y) Space between vertical grid marks. The higher the number the further apart the grid
marks.
Important:
The X and Y settings entered in the Grid dialog box remain in effect regardless of whether
you choose to display the grid.
The Dialog Editor displays or hides the grid with the settings you specified.
With the grid displayed, you can line up the crossbar on the mouse pointer with the dots on the grid to
position controls precisely and align them with respect to other controls.
The dialog box is saved as a .dlg file. The .dlg file can be moved, opened, modified, saved with a different
name at any time.
In the preceding section, you learned how to create controls and determine where they initially appear
within your dialog box. In this section, you'll learn how to make various types of changes to both the dialog
box and the controls in it. The following topics are included:
Basic Control Engine and Scripting Reference | 1 - Script Editors | 86
A message opens asking if you want to save the template for the current dialog box.
◦ Click Yes.
The current dialog box template code is inserted (on page 112) into the Program Editor script.
◦ Click No.
The Open Dialog File dialog box opens after either selection.
2. Select the file containing the dialog box template that you want to edit.
3. Click Open.
The Dialog Editor creates a dialog box from the statements in the template and displays it in the
application window.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 88
Note:
If there are any errors in the statements that describe the dialog box, the Dialog Translation Errors
dialog box will open when you attempt to load the file into Dialog Editor. This dialog box shows
the lines of code containing the errors and provides a brief description of the nature of each error.
1. Click the Select (on page 72) button on the Dialog Editor toolbar.
2. Do one of the following.
◦ Click the cursor on the title bar of the dialog box or on an empty area within the borders of
the dialog box
◦ Press the Tab key repeatedly until the focus moves to the dialog box.
Control
3. Click the Select (on page 72) button on the Dialog Editor toolbar.
4. Do one of the following.
◦ Click the cursor on the control to be selected.
◦ Press the Tab key repeatedly until the focus moves to the control.
The Dialog Editor creates the tabbing order based on the order in which you create the controls, not the
position of the controls in the dialog box.
The closer you can come to creating controls in the order in which you want them to receive the tabbing
focus, the fewer tabbing-order adjustments you will have to make later on.
When a control is pasted into the dialog box, the Dialog Editor places the descriptions of at the end of the
dialog box template.
Therefore, you can use a simple cut-and-paste technique to adjust the tabbing order.
1. Determine what item should be the starting point in the dialog box.
Note: Because the OK button and Cancel button display on a new dialog box by default, the OK
button is the starting point and the Cancel button is the first tab.
2. Cut (on page 72) and paste (on page 72) the controls to establish the desired tabbing order.
Note: If the controls were place in the dialog box in the correct order you can simply cut/paste the
OK and Cancel buttons so they are tabbed to last.
3. Test (on page 125) the tabbing order to make sure it is correct. Items that users cannot interact
with, e.g. group boxes, are not included in the tabbing order.
Information dialog box enable you to check and adjust various attributes of dialog boxes and dialog box
items.
The Dialog Box Information dialog box opens when you use any method.
At Description
tribute
Basic Control Engine and Scripting Reference | 1 - Script Editors | 92
Posi (Optional) Dialog box position (dialog units (on page 83)) in the window/screen in which it
tion opens
Size Dialog box size includes the number of dialog units (on page 83) in the:
Title Dialog box title bar. Note: Title is enabled if Close box is cleared. If Close box is
checked so the Close box button displays, the title bar must display.
Text$ (Optional) Text displayed on the title bar of the dialog box.
Variable Check to identify the Text$ entry as a variable. Note: if Text$ is a variable, spaces
Name cannot be used in the entry.
Name Name used for the dialog box template in script code
Picture (Optional) Picture library (.dll file) from which one or more pictures in the dialog box are ob
Library tained
Browse Opens a Select a Picture Library browser to help find the .dll file.
The <Item> Information dialog box opens when you use any method.
Option Description
Position Position of the check box in the dialog box from the:
Size Size of the checkbox, including the label, in dialog units (on page 83).
Text$ (Optional) Text that displays as the checkbox label. Note: if Text$ is a variable, spaces can
not be used in the entry.
Option Description
Position Position of the combo box in the dialog box from the:
Size Size of the combo box in dialog units (on page 83).
.Identifi (Optional) Name used for the combo box in a script's code.
er
Basic Control Engine and Scripting Reference | 1 - Script Editors | 96
Option Description
Position Position of the drop list box in the dialog box from the:
Size Size of the drop list box in dialog units (on page 83).
.Identifi (Optional) Name used for the drop list box in a script's code.
er
Option Description
Position Position of the group box in the dialog box from the:
Size Size of the group box in dialog units (on page 83).
Text$ (Optional) Text that displays as the group box label. Note: if Text$ is a variable, spaces
cannot be used in the entry.
.Identifier (Optional) Name used for the group box in a script's code.
Option Description
Position Position of the list box in the dialog box from the:
Size Size of the list box in dialog units (on page 83).
.Identifi (Optional) Name used for the list box in a script's code.
er
Option Description
Option Description
Position Position of the picture button in the dialog box from the:
Size Size of the picture button in dialog units (on page 83).
Option Description
Position Position of the Push Button box in the dialog box from the:
Size Size of the push button in dialog units (on page 83).
Text$ (Optional) Text that displays as the push button label. Note: if Text$ is a variable, spaces
cannot be used in the entry.
.Identifier (Optional) Name used for the push button in a script's code.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 102
Option Description
Position Position of the option button in the dialog box from the:
Size Size of the option button, including the label, in dialog units (on page 83).
Text$ (Optional) Text that displays as the checkbox label. Note: if Text$ is a variable, spaces can
not be used in the entry.
Option Description
Text$ Text that displays up to 255 characters Note: if Text$ is a variable, spaces cannot be
used in the entry.
Font Opens a Font dialog box to select the text font type, style and size.
Option Description
Position Position of the text box in the dialog box from the:
Check Require a password for a user to make a text entry if the text box is
read/write.
Clear Allow text entries without a password if the text box is read/write.
Text$ Text that displays up to 255 characters Note: if Text$ is a variable, spaces cannot be used in
the entry.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 105
Font Opens a Font dialog box to select the text font type, style and size.
The Dialog Editor provides several ways to reposition dialog boxes and items.
• Mouse.
• Arrow keys.
• Dialog Box Information dialog box.
• Item with the Information dialog box.
Mouse
1. Click the Select (on page 72) button on the Dialog Editor toolbar.
2. Place the cursor on an empty area in the dialog box or on a control.
3. Hold the left-mouse button down and drag the dialog box or control to the desired location.
Note:
The increments by which you can move a control with the mouse are governed by the grid
setting (on page 83).
Example
◦X=4
◦Y=6
◦ Horizontal = 4 X units
◦ Vertical = 6 Y units.
This feature is useful if you are trying to align controls in your dialog box. If you want to move
controls in smaller or larger increments.
Arrow Keys
Note:
When you reposition an item with the arrow keys, a faint, partial afterimage of the item may
remain visible in the item's original position. These afterimages are rare and will disappear
once you test your dialog box.
6. Open (on page 91) the Dialog Box Information dialog box.
7. Change the X and Y coordinates in the Position group box.
8. Click the OK button or press Enter on the keyboard.
If you specified X and Y coordinates, the dialog box moves to that position. If you left the X
coordinate blank, the dialog box will be centered horizontally static to the parent window of the
dialog box when the dialog box is run. If you left the Y coordinate blank, the dialog box will be
centered vertically static to the parent window of the dialog box when the dialog box is run.
9. Open (on page 91) the Information dialog box for the control that you want to move.
10. Change the X and Y coordinates in the Position group box.
11. Click the OK button or press Enter on the keyboard.
Note:
When you move a dialog box or control with the arrow keys or with the Information dialog
box, the item's movement is not restricted to the increments specified in the grid setting.
When you attempt to test a dialog box containing hidden controls (i.e., controls positioned
entirely outside the current borders of your dialog box), the Dialog Editor displays a
message advising you that there are controls outside the dialog box's borders and asks
requests confirmation to proceed with the test. If you proceed, the hidden controls will be
disabled for testing purposes.
Dialog boxes and controls can be resized either by directly manipulating them with the mouse or by using
the Information dialog box. Certain controls can also be resized automatically to fit the text displayed on
them.
1. Click the Select (on page 72) button on the Dialog Editor toolbar.
2. Place the cursor over a border or corner of the dialog box or a control..
3. Hold the the left-mouse button down and drag the border or corner until the dialog box or control
reaches the desired size.
4. Open (on page 90) the Information dialog box for the dialog box or a selected control.
5. Change the Width and Height settings in the Size group box.
6. Click OK or press Enter on the keyboard.
◦ Option button
◦ Text control
◦ Push button
◦ Check box
◦ Text box
7. Click the Select (on page 72) button on the Dialog Editor toolbar.
8. Select the control to be resized.
9. Press F2 on the keyboard..
The borders of the control will expand or contract to fit the text displayed on it.
Note:
• Windows metafiles always expand or contract proportionally to fit within the picture control or
picture button control containing them.
• Windows bitmaps are of a fixed size.
• Smaller than the bitmap, the bitmap is clipped off on the right and bottom.
• Larger than the bitmap, the bitmap is centered within the borders of the control.
Text Text
Note:
• The OK and Cancel buttons also have labels that cannot be changed.
• The following controls do not have their own labels. You can position a text control above or beside
these controls to serve as a de facto label
• Combo boxes
• Drop list boxes
Basic Control Engine and Scripting Reference | 1 - Script Editors | 109
• List boxes
• Pictures
• Picture buttons.
• Text boxes
1. Open (on page 90) the Information dialog box for the dialog box title you want to change or for
the control label you want to change.
2. Enter the new title or label in the Text$ field.
Note: Dialog box titles and control labels are optional; you can leave the Text$ field blank.
3. Check the Variable Name checkbox if the information in the Text$ field should be interpreted as a
variable name rather than a literal string.
4. Click the OK button or press Enter on the keyboard.
The Information dialog box closes; the new title or label displays in the title bar or on the control.
Accelerator keys:
• Enable users to access dialog box controls by pressing Alt + <specified letter>.
• Are essentially a single letter from a control's label.
• Combo box.
• Drop list box..
1. Open the Information dialog box for the control that will have an assigned an accelerator key.
2. Select the Text$ field.
3. Type an ampersand (&) before the letter designated as the accelerator key.
The designated letter is now underlined on the control's label; users will be able to access the control by
pressing Alt +<underlined letter>.
• Accelerator keys can be assigned directly to the following controls that have their own label
• Check boxes
• Group boxes
Basic Control Engine and Scripting Reference | 1 - Script Editors | 111
• Option buttons
• Push buttons
• The OK and Cancel buttons cannot have accelerator keys
• A de facto accelerator key can be created for certain controls that do not have their own labels by
assigning an accelerator key to an associated text control.
• Combo boxes
• Drop list boxes
• List boxes
• Text boxes
• Accelerator key assignments must be unique within a particular dialog box. If you attempt to
assign the same accelerator key to more than one control, a message displays reporting that the
letter has already been assigned.
Note:
In order for such a de facto accelerator key to work properly, the text control or group box label to
which you assign the accelerator key must be associated with the control(s) to which you want to
provide user access that is, in the dialog box template, the description of the text control or group
box must immediately precede the description of the control(s) that you want associated with it.
The simplest way to establish such an association is to create the text control or group box first,
followed immediately by the associated control(s)
• Duplicate a Control.
• Delete a Single Control.
• Delete all the Controls in a dialog box.
Duplicate a Control
3. Repeat 2 as many times as necessary to create the desired number of duplicate controls.
If the dialog box contains more than one control a message displays asking:
All the controls are deleted, but the dialog box's title bar and close box (if displayed) remain unchanged.
1. Place the cursor in a Program Editor script where the dialog box code will be inserted.
Click On the
Press On the
Ctrl+N Key
board
Ctrl+O Key
board
A message box opens asking if you want to save the dialog box template.
5. Click Yes.
Result: The dialog box template code is inserted into the Program Editor script at the specified
location.
The Dialog script is pasted at the insertion point in the Program Editor script.
There are three ways to edit an existing dialog box: (1) You can copy the template of the dialog box you
want to edit from a script to the Clipboard and paste it into Dialog Editor. (2) You can use the capture
feature to "grab" an existing dialog box from another application and insert a copy of it into Dialog Editor.
(3) You can open a dialog box template file that has been saved on a disk.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 117
5.1 (on Paste an existing dialog box into the Dialog Edi
page tor.
117)
You can use the Dialog Editor to modify the statements in your script that correspond to an entire dialog
box or to one or more dialog box controls.
1. Select code in the Program Editor for the entire dialog box.
The code:
5. Click Yes.
Result: The dialog box template code copied from the Program Editor script replaces the selected
dialog box template. The dialog box changes according to the pasted code.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 119
6. Select code in the Program Editor that defines one or more controls for a dialog box.
The selected controls are pasted into the dialog box based on the location specifications in the code.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 120
• When you paste a dialog box template into the Dialog Editor, the tabbing order of the controls is
determined by the order in which the controls are described in the template.
• When you paste one or more controls into Dialog Editor, they will come last in the tabbing order,
following the controls that are already present in the current dialog box.
• If there are any errors in the statements that describe the dialog box or controls, the Dialog
Translation Errors dialog box will open when you attempt to paste these statements into Dialog
Editor. This dialog box shows the lines of code containing the errors and provides a brief
description of the nature of each error.
The Dialog Editor provides a quick way to capture standard Windows dialog box controls from another
application and insert those controls into Dialog Editor for editing.
Important:
The Dialog Editor only supports standard Windows controls and standard Windows dialog boxes.
• Contains both standard Windows controls and custom controls, only the standard Windows
controls will appear in Dialog Editor's application window.
• Is not a standard Windows dialog box, you will be unable to capture the dialog box or any of its
controls.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 121
1. Open a standard Windows dialog box that has controls you want to use.
A message opens to confirm if you want to replace the dialog box that is currently in the Dialog
Editor.
6. Click Yes.
The captured dialog box with standard controls replaces the current dialog box.
7. Modify the layout the same as you would for any other dialog box.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 123
8. Use any of the Dialog Editor methods to save the dialog box or insert/paste the dialog box template
code into a script.
The captured dialog box template code displays in the Program Editor. The code can be modified to fill the
script's requirements.
It is recommended that you check the dialog box for these errors before testing it.
When all statements on the list are True, the dialog box is ready to be tested.
Statement T/F
The dialog box contains a command button, i.e. a default OK or Cancel button, a push button, or a
picture button.
All of the controls are labelled with their own labels or de-facto text labels.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 125
Testing a dialog box is an iterative process that involves running the dialog box to see how well it works,
identifying problems, stopping the test and fixing those problems, then running the dialog box again to
make sure the problems are fixed.
Start a Test
Test the control on the running dialog box to make sure they are functioning correctly.
If a statement is False, stop the dialog box and make the required corrections.
Statement T/F
Basic Control Engine and Scripting Reference | 1 - Script Editors | 127
The Tab key moves through the control selection in a logical order. Note: Objects that users cannot
act on, e.g. Group boxes, text controls and pictures are not selected.
Results:
◦ Click No.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 129
• Click Cancel.
After using Dialog Editor to insert a custom dialog box template into your script, you'll need to make the
following modifications to your script:
To store the values retrieved from a custom dialog box, you create a dialog record with a Dim statement,
using the following syntax:
Examples
Sample script
This sample script that illustrates how to create a dialog record named b within a dialog box template
named UserDialog . Notice that the order of the statements within the script is as follows: the dialog box
template precedes the statement that creates the dialog record, and the Dialog statement follows both
of them.
Sub Main()
Text 13,6,32,8,"&Quantity:",.Text1
TextBox 48,4,28,12,.TextBox1
ListBox 12,28,68,32,ListBox1$,.ListBox1
OKButton 112,8,40,14
CancelButton 112,28,40,14
End Dialog
End Sub
If you open and run the sample script shown in the preceding subsection, you will see a dialog box that
resembles the following.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 131
This custom dialog box is not very useful. For one thing, the user doesn't see any items in the list box
along the left side of the dialog box. To put information into this dialog box, you assign values to its
controls by modifying the statements in your script that are responsible for displaying those controls to
the user. The following table lists the dialog box controls to which you can assign values and the types of
information you can control:
You can store items in the list box shown in the example above by creating an array and then assigning
values to the elements of the array. For example, you could include the following lines to initialize an array
with three elements and assign the names of three common fruits to these elements of your array:
ListBox1$(0) = "Apples"
ListBox1$(1) = "Oranges"
ListBox1$(2) = "Pears"
You can set the default value of the text box in your script to 12 with the following statement, which must
follow the statement that defines the dialog record but precede the statement or function that displays
the custom dialog box:
b.TextBox1 = "12"
Basic Control Engine and Scripting Reference | 1 - Script Editors | 132
You can determine which control has the focus when your custom dialog box is first displayed as well
as the tabbing order between controls by understanding two rules that the Basic Control Engine script
follows. First, the focus in a custom dialog box is always set initially to the first control to appear in
the dialog box template. Second, the order in which subsequent controls appear within the dialog box
template determines the tabbing order. That is, pressing the Tab key will change the focus from the first
control to the second one, pressing the Tab key again will change the focus to the third control, and so on.
To display a custom dialog box, you can use either of the following.
Dialog() function
Dialog statement.
Dialog() Function
You can use a Dialog() function to determine how the user closed your custom dialog box. For example,
the following statement will return a value when the user clicks an OK button or a Cancel button or takes
another action:
response% = Dialog(b)
–1 The OK button.
>0 A push button. The returned number represents which button was clicked based on its order in
the dialog box template (1 is the first push button, 2 is the second push button, and so on).
Dialog Statement
You can use the Dialog statement when you don't need to determine how the user closed your dialog
box. You'll still be able to retrieve other information from the dialog box record, such as the value of a list
box or other dialog box control.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 133
Dialog mydlg
Where
After displaying a custom dialog box for your user, your script must retrieve the values of the dialog
controls. You retrieve these values by referencing the appropriate identifiers in the dialog record.
You'll find an example of how to retrieve values from a custom dialog box in the following subsection.
Sample
In the following sample script several of the techniques described earlier in this section have been used.
In this script, the array named ListBox1 is filled with three elements ( "Apples" , "Oranges" , and "Pears"
). The default value of TextBox1 is set to 12. A variable named response is used to store information
about how the custom dialog box was closed. An identifier named ListBox1 is used to determine
whether the user chose "Apples" , "Oranges" , or "Pears" in the list box named ListBox$ . Finally, a
Select Case . . . End Select statement is used to display a message box appropriate to the manner in
which the user dismissed the dialog box.
Sub Main()
Dim response%
ListBox1$(0) = "Apples"
ListBox1$(1) = "Oranges"
ListBox1$(2) = "Pears"
TextBox 48,4,28,12,.TextBox1
ListBox 12,28,68,32,ListBox1$,.ListBox1
OKButton 112,8,40,14
CancelButton 112,28,40,14
Basic Control Engine and Scripting Reference | 1 - Script Editors | 134
End Dialog
'to 1 dozen.
Case -1
Fruit$ = ListBox1$(b.ListBox1)
MsgBox "Thank you for ordering " + b.TextBox1 + " " + Fruit$ + "."
Case 0
End Select
End Sub
You can retrieve values from a custom dialog box while the dialog box is displayed, using the dynamic
dialog boxes feature.
The following script illustrates the most important concepts you'll need to understand in order to create a
dynamic dialog box in your script:
'all procedures.
'dialog box.
Case 1
'box is visible.
Case 2
DlgValue "ListBox1", 0
DlgValue "ListBox1", 0
End If
nd Select
End Function
Sub Main()
'statement in template.
Dim Produce$
'arrays.
Fruits(0) = "Apples"
Fruits(1) = "Oranges"
Fruits(2) = "Pears"
Vegetables(0) = "Carrots"
Vegetables(1) = "Peas"
Vegetables(2) = "Lettuce"
TextBox 48,4,28,12,.TextBox1
ListBox 12,28,68,32,ListBox1$,.ListBox1
OptionGroup .OptionGroup1
OptionButton 12,68,48,8,"&Fruit",.OptionButton1
OptionButton 12,80,48,8,"&Vegetables",.OptionButton2
OKButton 112,8,40,14
CancelButton 112,28,40,14
End Dialog
'box to 1 dozen.
Case -1
If b.OptionGroup1 = 0 Then
produce$ = fruits(b.ListBox1)
Else
produce$ = vegetables(b.ListBox1)
End If
MsgBox "Thank you for ordering " & b.TextBox1 & " " & produce$ & "."
ase 0
End Select
End Sub
The first thing to notice about the preceding script is that an identifier named DialogControl has been
added to the Begin Dialog statement. As you will learn in the following subsection, this parameter to the
Begin Dialog statement tells the Basic Control Engine to pass control to a function procedure named
DialogControl.
Before the Basic Control Engine displays a custom dialog box by executing a Dialog statement or
Dialog() function, it must first initialize the dialog box. During this initialization process, the Basic Control
Engine checks to see whether you've defined a dialog function as part of your dialog box template. If so,
the Basic Control Engine will give control to your dialog function, allowing your script to carry out certain
actions, such as hiding or disabling dialog box controls.
After completing its initialization process, the Basic Control Engine displays your custom dialog box.
When the user selects an item in a list box, clears a check box, or carries out certain other actions within
the dialog box, the Basic Control Engine will again call your dialog function.
The Basic Control Engine dialog function can respond to six types of user actions:
Ac Description
tion
1 This action is sent immediately before the dialog box is shown for the first time.
An option button is selected. In this case, ControlName$ contains the name of the option button
that was clicked, and SuppValue contains the index of the option button within the option button
group (0 is the first option button, 1 is the second, and so on).
The current selection is changed in a list box, drop list box, or combo box. In this case, Control-
Name$ contains the name of the list box, combo box, or drop list box, and SuppValue contains the in
dex of the new item (0 is the first item, 1 is the second, and so on).
3 This action is sent when the content of a text box or combo box has been changed and that con
trol loses focus.
5 This action is sent continuously when the dialog box is idle. The user should return a 0 or idle pro
cessing will use up the CPU.
You'll find a more complete explanation of these action codes in the A–Z Reference. See the DlgProc
(Function) entry in that documentation.
Debug Scripts
Debug Scripts
• Debug overview
• Debug options
Debug Overview
While debugging, you are actually executing the code in a script line by line.
A The Program Editor displays an instruction pointer on the line of code that is about to be exe
cuted. When the instruction pointer is on a line of code, the text on that line appears in black
on a gray background that spans the width of the entire line.
B The edit pane is read-only during the debugging process. You are free to move the insertion
point throughout the script, select text and copy it to the Clipboard as necessary, set break
points, and add and remove watch variables, but you cannot make any changes to the script
until you stop running it.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 139
Debug Options
The Event Editor allows the user to configure a script to run in response to an event. When a project is
running, the Event Manager runs a script either when a specified event or any event occurs, depending on
what is specified in the script.
However
• On one hand, when you build the script in the Program Editor there is no real event to trigger the
script.
• On the other hand, when the script runs with the Event Manager, you can not debug it in the
Program Editor.
An Event Information dialog box is available to fabricate the event information that the APIs would provide
in a real environment.
Using this fabrication you can safely test the accuracy of your script.
Because you are using the Event Information dialog box to fabricate a real world environment, what you
enter depends on what is included in your script. If the script includes specific entries for any of the fields,
you have to enter what is in the script. For any entries that are not specifically referred to in the script, you
can enter whatever you want.
Example
Basic Control Engine and Scripting Reference | 1 - Script Editors | 141
Resource ID as $SYSTEM .
As a result, Alarm Generated and $SYSTEM are selected in the Event Information dialog box.
Whenever, you run the script, it will draw its information from what you entered. You only have to change
your entries in the Event Information dialog box if a script requires a change in a specific entry.
Method Description
Procedure Does not step into calls to user defined functions and subroutines. The procedure step
step does execute the calls.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 142
1. Use either method to start stepping through your script with either the single step or procedure
step method.
Single step ◦ Click Debug>Step on the CIMPLICITY Program Editor menu bar.
◦ Press F8 on the keyboard.
The Program Editor places the instruction pointer on the sub main line of the script.
Each time you repeat the Step command, Program Editor executes the line containing the
instruction pointer and moves the instruction pointer to the next line to be executed.
3. Do one of the following when you finish stepping through the script execution.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 143
Note:
When script execution is initiated, the script will first be compiled, if necessary. Therefore,
there may be a slight pause before execution actually begins. If the script contains any
compile errors, it will not be executed.
Do the following.
When stepping through a subroutine, you can determine the procedure calls made to arrive at the
paused point in the script..
The Calls dialog box opens when you use either method.
The Calls dialog box lists the procedure calls made by the script to arrive at the selected
subroutine.
Click Description
When stepping through a subroutine, you can move the insertion point to another line within a
subroutine to repeat or skip execution of a section of code.
9. Place the insertion point in the line where you want to resume stepping through the script.
10. Do one of the following.
The instruction pointer moves to the line you selected; you can resume stepping through your script from
there.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 146
Note:
You can only use the Set Next Statement command to move the instruction pointer within the
same subroutine.
3. Use Breakpoints
If you only need to debug one or more portions of a long script one or more breakpoints can be set at
selected lines in your script.
Valid breakpoints can only be set on lines in your script that contain code, including lines in functions
and subroutines. Although you can set a breakpoint anywhere within a script prior to execution, when
you compile and run the script, invalid breakpoints (breakpoints on lines that don't contain code) are
automatically removed. While you are debugging your script, the Program Editor will beep if you try to set
a breakpoint on a line that does not contain code.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 147
Select Breakpoints
1. Place the insertion point in the line where you want to do one of the following.
• A select point.
• A line outside the current subroutine.
• Selected portions of a program.
Results
• A select point
Runs the script at full speed until it reaches the line containing the breakpoint and then pauses with the
instruction pointer on that line.
The line will be executed next when you either proceed with debugging or resume running the script.
If you want to continue debugging at another line in your script, you can use the Set Next Statement
command in the Debug menu to move the instruction pointer to the desired line—provided the line is
within the same subroutine.
Runs the script at full speed until it reaches the line containing the breakpoint and then pauses with the
instruction pointer on that line.
You can now resume stepping through your script from that point.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 149
Runs the script at full speed until it reaches the line containing the first breakpoint and then pauses with
the instruction pointer on that line.
The script executes at full speed until it reaches the line containing the second breakpoint and then
pauses with the instruction pointer on that line.
1. Repeat 1 and 2 until you have finished debugging the selected portions of your script.
Remove breakpoints
1. Place the insertion point on the line containing the breakpoint that you want to remove.
2. Do one of the following.
Result: The breakpoint is removed, and the line no longer displays in contrasting type.
Result: The Program Editor removes all breakpoints from your script.
Note:
Breakpoints are removed automatically under the following circumstances:
• When a script is compiled and executed, breakpoints are removed from lines that don't contain
code.
• When you exit from the Program Editor, all breakpoints are cleared.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 150
The Trace command can be used in Basic Control Engine scripts to print output to the Program Editor
window's Trace section.
Enable Tracing
Example
Trace is enabled.
Result: The trace results display in the Program Editor window trace section.
Result: The trace results are deleted from the Program Editor trace section.
Disable Tracing
Result: The trace entries are ignored when the script is run.
As you debug your script, you can use Program Editor's watch pane to monitor selected variables. For
each of the variables on this watch variable list, Program Editor displays the name of the variable, where
it is defined, its value (if the variable is not in scope, its value is shown as <not in context>), and other key
information such as its type and length (if it is a string). The values of the variables on the watch list are
updated each time you enter break mode.
5.1 (on Add a Watch variable to the Program Editor's Watch variable
page list.
153)
5.1. Add a Watch Variable to the Program Editor's Watch Variable List
Field Description
Variable Name of the variable you want to add to the watch variable
list.
If this is the first variable you are placing on the watch variable list, the watch pane opens far enough to
display that variable. If the watch pane was already open, it expands far enough to display the variable you
just added.
guide:
Guidelines for Variables
Cannot watch
Can watch
Examples
• Integer
• Long
• Variant
• Individual elements of arrays or structure members using the following syntax:
Where
Basic Control Engine and Scripting Reference | 1 - Script Editors | 156
Example
company(10,23).per Member age of structure person that is at element 10,23 within the array of
son.age structures named company
1. Display the names of all the variables that are in scope or defined within the current function or
subroutine on the drop-down Variable Name list.
2. Select the variable you want from that list.
• You can add as many watch variables to the list as you want.
The Watch pane only expands until it fills half of Program Editor's application window. If your list of watch
variables becomes longer than that, you can use the watch pane's scroll bars to bring hidden portions of
the list into view.
When the debugger has control (on page 138) , you can modify the value of any of the variables on
Program Editor's Watch variable list.
Field Description
Name Name of the variable to be modified. Note: If the line was double-clicked the Name
field:
◦ Displays the selected variable.
◦ Is read-only.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 158
guide:
Guidelines for Modifying Variables
• When changing the value of a variable, the Program Editor converts the new value to be of the
same type as the variable being changed.
Example
An Integer value is 3.
• When modifying a Variant variable, the Program Editor needs to determine both the type and value
of the data. Program Editor uses the following logic in performing this assignment (in this order):
Basic Control Engine and Scripting Reference | 1 - Script Editors | 159
num The value of number. The type of the variant is the smallest data type that fully represents that
ber number. You can force the data type of the variable using a type-declarator letter following
number, such as %, #, &, !, or @.
• The Program Editor will not assign a new value if it cannot be converted to the same type as the
specified variable.
When the debugger has control (on page 138) , you can use the Quick Watch window to do a quick
check of a variable value, without adding the variable to the Watch list (on page 153) .
The QuickWatch window opens displaying the value for the selected variable.
The variable is evaluated; if it has a known value, the value displays in the evaluation box.
4. Click Close.
The QuickWatch window closes; you can continue debugging the script.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 161
Note:
You must close the QuickWatch window in order to return to the script window.
Run a Program
Important:
The CIMPLICITY project must be running in order to run the script.
Once you have finished editing your programs, you will want to run it to make sure it performs the way you
intended. You can also suspend or stop an executing script.
Run a script
Note: This will also compile your script, if necessary, and then execute it.
Basic Control Engine and Scripting Reference | 1 - Script Editors | 162
The script is compiled (if it has not already been compiled), the focus is switched to the parent window,
and the script is executed.
Execution of the script is suspended, and the instruction pointer (a gray highlight) appears on the line of
code where the script stopped executing.
Note:
The instruction pointer designates the line of code that will be executed next if you resume
running your script.
Error Messages
Error Messages
This section contains listings of all the runtime errors. 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 the Basic Control Engine.
A few error messages contain placeholders that get replaced by the runtime when forming the completed
runtime error message. These placeholders appear in the following list as the italicized word placeholder.
Number Message
6 Overflow
7 Out of memory
11 Division by zero
13 Type mismatch
19 No Resume
51 Internal error
61 Disk full
68 Device unavailable
70 Permission denied
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 hidden or disabled
163 This statement can only be used when a user dialog is active
Basic Control Engine and Scripting Reference | 1 - Script Editors | 165
432 File name or class name not found during OLE Automation operation
3129 Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UP
DATE'
Number Message
The following table contains a list of all the errors generated by the Basic Control Engine 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 word placeholder.
Number Message
25 Out of memory
42 Duplicate label
48 Unknown type
52 0 expected
58 Expecting 0 or 1
Basic Control Engine and Scripting Reference | 1 - Script Editors | 170
65 Internal error 1
67 Internal error 3
68 Division by zero
69 Overflow in expression
An overview of how to open and take advantage of the CimScriptIDE editor includes the following.
Important:
If you are familiar with the Program Editor for CimBasic, it is important to note that the
CimScriptIDE Editor for .NET scripting behaves differently than the CimBasic Program Editor in
regard to Compiling. Selecting Compile (on page 181) for a .NET script saves the script file to
disk; selecting Compile (on page 37) for CimBasic it does not.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 174
Either Or
Do the following.
Cancel Closes the Create Script dialog box without creating a script.
3. Right-click Scripts.
4. Select New on the Popup menu.
5. Right-click anywhere.
6. Select New on the Popup menu.
7. Creates the script.
8. Opens the script editor window for the selected script type.
Either Or
4. Right-click Scripts.
5. Select Properties on the Popup menu.
6. Right-click a script.
7. Select Properties on the Popup menu.
• Includes features from the CIMPLICITY Program Editor that are familiar to CIMPLICITY users.
• Provides features that are designed specifically for C# and VB.Net scripting.
Important:
CimScriptIDE editor uses .NET 4.5, which was a required installation when CIMPLICITY v9.0 was
installed. However, the CimScriptIDE editor does not recognize certain keywords that are new
in .NET 4.5 and will display an error message when one is not recognized. However, you can still
compile and run scripts that contain the unrecognized keywords.
Example
• async
• await
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 178
• File menu.
• Edit menu.
• View menu.
• Run menu.
• Tools menu.
• Window menu.
• Help menu.
File Menu
Print Setup Opens the Setup dialog box for the default printer.
Edit Menu
Redo Redoes the actions that have been undone, beginning with the last undo.
View Menu
Toolbars and Docking Win Displays the list of available toolbars. You can toggle the display of each
dows toolbar.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 181
Status Bar Toggles the Status Bar at the bottom of the CimScriptIDE Editor.
Run Menu
Tools Menu
Points Displays a submenu that enables you to browse for points, edit a point, and create a new point.
You can also use this menu item to include Setpoints, Getpoints and create local variables in
the program.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 182
Alarms Displays a submenu that lets you generate or update alarms in the program.
Log Opens a Log Status dialog box enabling you to generate messages for the Status Log.
Status
Dy Toggles Dynamic Configuration of points, alarm, etc. Note: When the project is running, dynam
namic ic is enabled for users who have been assigned the Dynamic Configuration privilege.
Window Menu
Help Menu
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 183
About Cim Opens an About CimScriptIDE message box with details about the distribution number
ScriptIDE and installed service upgrades.
• Standard
• Tools
Standard Toolbar
Tools Toolbar
Buttons on the Tools toolbar open the following browser and dialog boxes.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 184
A Displays status messages or tool tips when the mouse hovers over selected items, e.g. Ready or
Copy the selection and put it on the clipboard.
• CAP
• NUM
• SCRL
• Scan a script's imports, class nodes, function, properties, constants and class variables.
• Move the cursor to any selection by double-clicking the instance in the tree.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 185
A Based on the scripting type, a Using or Imports node can be expanded to list each entry in the script.
C# Using
VB .NET Imports
B Class node
Note:
This name must be the same as the script filename. If it is changed, make sure the filename
is changed.
C Functions, nested classes, constants and class variables that are included in the class.
The CimScriptIDE editor right-pane provides a robust environment for creating and editing C Sharp and/or
VB .NET scripts.
A Multiple scripts, which can be open at the same time, are identified by tabs at the top of the right-
pane. The script for the selected tab (identified by an x) displays for editing.
C As code is being written a CodeComplete Popup lists keywords, variables and members (methods,
properties, and events) that can be used based on what was just written. Any item can be selected
and automatically inserted.
E A Trace tab traces messages from the script when the script is run.
Important:
The CimScriptIDE editor does not debug scripts; however, scripts written in the CimScriptIDE
editor can be debugged live using Visual Studio.
Feature Action
CIMPLICITY provides default .NET assembly references for C# and VB .NET; additional references can be
added or removed in the (Event Editor) Setup dialog box.
C Click Settings.
A Add a .Net Assembly ref a. Click the Open button to the right of the .Net Assembly Ref
erence. erences field.
b. An Open dialog box opens.
c. Select the .dll file that should be added to the list.
d. Click Add.
Result: The selected file is listed as one of the .Net Assembly ref
erences.
C Modify the list. Click Modify. The .Net Assembly Reference field is cleared.
4. Click the Open button to the right of the .Net Assembly References field.
5. An Open dialog box opens.
Basic Control Engine and Scripting Reference | 2 - CimScriptIDE Editor | 190
Category Description
data type Any of the support data types, such as Integer, String, and so on.
function Language element that takes zero or more parameters, performs an action, and returns a
value
keyword Language element that doesn't fit into any of the other categories
operator Language elements that cause an evaluation to be performed either on one or two operands
state Language element that takes zero or more parameters and performs an action.
ment
Each entry in the Basic Control Engine Language Reference documentation contains the following
headings:
Head
Description
ing
Syn The syntax of the language element. The conventions used in describing the syntax are de
tax scribed in Chapter 1 of the Basic Control Engine Language Reference documentation.
Com Contains any other important information about that language keyword.
ments
Exam Contains an example of that language keyword in use. An example is provided for every lan
ple guage keyword.
See Contains a list of other entries in the Reference section that relate either directly or indirectly to
Also that language element.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 192
Double-click Locate on the Help toolbar to locate the topic in the Table of Contents.
Intro (on
page
193)
Symbols
(on page
211)
Object Model
CIMPLICITY Configuration
CimLangMapper
CimEdit / CimView
CIMPLICITY XY Plot
Tracker Agents
TADB
Notation Description
While...Wend Elements belonging to the Basic Control Engine script language, referred to in this manu
al as keywords, appear in the typeface shown to the left.
variable Items that are to be replaced with information that you supply appear in italics. The type
of replacement is indicated in the following description.
text$ The presence of a type-declaration character following a parameter signifies that the pa
rameter must be a variable of that type or an expression that evaluates to that type. If a
parameter does not appear with a type-declaration character, then its type is described in
the text.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 194
Notation Description
[parameter] Square brackets indicate that the enclosed items are optional. In Basic Control Engine
script language, you cannot end a statement with a comma, even if the parameters are
optional:
{Input | Bina Braces indicate that you must choose one of the enclosed items, which are separated by
ry} a vertical bar.
... Ellipses indicate that the preceding expression can be repeated any number of times.
The following subsections list Basic Control Engine language elements by category.
Arrays
Clipboard
Comments
Comparison operators
Conversion
Data types
Database
Date/time
DDE
Error handling
File I/O
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 195
File system
Financial
INI Files
Logical/binary operators
Math
Miscellaneous
Numeric operators
Objects
Parsing
Predefined dialogs
Printing
Procedures
String operators
Strings
User Dialogs
Variants
Arrays
Option Base Change the default lower bound for array declara
tions
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 196
Clipboard
Comments
Comparison Operators
= Equal
Conversion
Data Types
Double Data type used to hold real number with 15-16 digits of precision
Integer Data type used to hold whole numbers with 4 digits of precision
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 200
Long Data type used to hold whole numbers with 10 digits of preci
sion
Single Data type used to hold real number with 7 digits of precision
Variant Data type that holds a number, string, or OLE automation objects
Database
Date/time
DDE
Error Handling
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 202
Err (function) Return the error that caused the current error
trap
File I/O
Loc Return the record position of the file pointer within a file
Seek Return the byte position of the file pointer within a file
Seek Set the byte position of the file pointer which a file
File System
FileDateTime Return the date and time when a file was last modi
fied
Financial
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 204
IRR Return the internal rate of return for a series of payments and receipts
INI Files
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 205
ReadIniSection Read all the item names from a given section of an INI
file
Logical/binary Operators
Math
Miscellaneous
_ Line continuation
Numeric Operators
* Multiply
+ Add
- Subtract
/ Divide
\ Integer divide
^ Power
Mod Remainder
Objects
GetObject Return an OLE automation object from a file, or returns a previously instantiated OLE au
tomation object
Parsing
Predefined Dialogs
Printing
Procedures
String Operators
Strings
Option Compare Change the default comparison between text and binary
User Dialogs
DlgListBoxArray Set the content of a list box or combo box in a dynamic dialog
DlgListBoxArray Set the content of a list box or combo box in a dynamic dialog
= Assignment
Variants
Symbols
Symbols
' (keyword)
- (operator)
#Const (directive)
#If...Then...#Else (directive)
& (operator)
() (keyword)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 212
* (operator)
. (keyword)
/ (operator)
\ (operator)
^ (operator)
_ (keyword)
+ (operator)
< (operator)
<= (operator)
<> (operator)
= (operator)
= (statement)
> (operator)
>= (operator)
' (keyword)
Descrip Causes the compiler to skip all characters between this character and the end of the cur
tion rent line.
Com This is very useful for commenting your code to make it more readable.
ments
End Sub
See Also Rem (on page 602) (statement); Comments (on page 311) (topic).
- (operator)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 213
Syn – expression
tax 2
De Returns the difference between expression1 and expression2 or, in the second syntax, returns
scrip the negation of expression.
tion
Com Syntax 1 The type of the result is the same as that of the most precise expression, with the fol
ments lowing exceptions:
If one expression is and the other expression is then the type result is
A runtime error is generated if the result overflows its legal range. When either or both expres
sions are Variant , then the following additional rules apply:
• If expression1 is Null and expression2 is Boolean , then the result is Empty . Otherwise,
if either expression is Null , then the result is Null .
• Empty is treated as an Integer of value 0 .
• 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.
Syntax 2 If expression is numeric, then the type of the result is the same type as expression,
with the following exception:
In 2's compliment 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 da
ta type. For example, the following generates an overflow error:
Sub Main()
Dim a As Integer
a = -32768
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 214
When negating variants, overflow will never occur because the result will be automatically pro
moted: integers to longs and longs to doubles.
Exam This example assigns values to two numeric variables and their difference to a third variable,
ple then displays the result.
Sub Main()
i% = 100
j# = 22.55
k# = i% - j#
End Sub
#Const (directive)
Com Internally, all preprocessor constants are of type Variant. Thus, the expression parameter can
ments be any type. Variables defined using #Const can only be used within the #If...Then...#Else state
ment and other #Const statements. Use the Const statement to define constants that can be
used within your code.
Exam
ple #Const
SUBPLATFORM = "XP"
#Const PLATFORM = MANUFACTURER & " " & SUBPLATFORM & " " & TYPE
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 215
Sub Main()
#End If
End Sub
#If...Then...#Else (directive)
Syn
tax #If expression Then
[statements]
[statements]]
#Else
[statements]]
#End If
De Causes the compiler to include or exclude sections of code based on conditions.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 216
Com The expression represents any valid BasicScript Boolean expression evaluating to TRUE of
ments FALSE. The expression may consist of literals, operators, constants defined with #Const, and any
of the following predefined constants:
Constant Value
Empty Empty
FALSE False
NULL Null
TRUE True
The expression can use any of the following operators: +, -, *, /, \, ^, + (unary), - (unary), Mod, &, =,
<>, >=, >, <=, <, And, Or, Xor, Imp, Eqv.
Evaluates to a: Result
Zero FALSE
Text comparisons within expression are always case-insensitive, regardless of the Option Com
pare setting You can define your own constants using the #Const directive, and test for these
constants within the expression parameter as shown below:
#Const VERSION = 2
Sub Main
directory$ = "\apps\widget"
directory$ = "\apps\widget32"
#Else
#End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 217
Any constant not already defined evaluates to Empty. A common use of the #If...Then...#Else
directive is to optionally include debugging statements in your code. The following example
shows how debugging code can be conditionally included to check parameters to a function:
#Const DEBUG = 1
Exit Sub
End If
Exit Sub
End If
#End If
End Sub
Excluded section are not compiled by BasicScript, allowing you to exclude sections of code that
has errors or doesn’t even represent valid BasicScript syntax. For example, the following code
uses the #If...Then...#Else statement to include a multi-line comment:
Sub Main
#If 0
OK button.
#End If
End Sub
In the above example, since the expression #If 0 never evaluates to TRUE, the text between that
and the matching #End If will never be compiled.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 218
& (operator)
Com If both expressions are strings, then the type of the result is String . Otherwise, the type of the
ments result is a String variant. When nonstring expressions are encountered, each expression is con
verted 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 treat
ed 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.
Exam This example assigns a concatenated string to variable s$ and a string to s2$, then concate
ple nates the two variables and displays the result in a dialog box.
Sub Main()
End Sub
See + (on page 224) (operator); Operator Precedence (on page 560) (topic).
Also
() (keyword)
De Forces parts of an expression to be evaluated before others or forces a parameter to be passed
scrip by value.
tion
Com Parentheses within Expressions Parentheses override the normal precedence order of the
ments scripts operators, forcing a subexpression to be evaluated before other parts of the expression.
For example, the use of parentheses in the following expressions causes different results: i = 1
+2*3 'Assigns 7. i = (1 + 2) * 3 'Assigns 9. Use of parentheses can make your code easier
to read, removing any ambiguity in complicated expressions.
Parentheses Used in Parameter Passing Parentheses can also be used when passing parame
ters to functions or subroutines to force a given parameter to be passed by value, as shown be
low: ShowForm i 'Pass i by reference. ShowForm (i) 'Pass i by value. Enclosing parame
ters within parentheses can be misleading. For example, the following statement appears to
be calling a function called ShowForm without assigning the result: ShowForm(i) The above
statement actually calls a subroutine called ShowForm , passing it the variable i by value. It
may be clearer to use the ByVal keyword in this case, which accomplishes the same thing:
ShowForm ByVal i The result of an expression is always passed by value.
bill = False
dave = True
jim = True
Else
End If
End Sub
See ByVal (on page 273) (keyword); Operator Precedence (on page 560) (topic).
Also
* (operator)
Com The result is the same type as the most precise expression, with the following exceptions:
ments
If one expression is and the other expression is then the type the result is
When the * operator is used with variants, the following additional rules apply:
• Empty is treated as 0.
• If the type of the result is an Integer variant that overflows, then the result is automati
cally promoted to a Long variant.
• If the type of the result is a Single , Long , or Date variant that overflows, then the re
sult is automatically promoted to a Double variant.
• If expression1 is Null and expression2 is Boolean , then the result is Empty . Other
wise, If either expression is Null , then the result is Null .
Exam This example assigns values to two variables and their product to a third variable, then displays
ple the product of s# * t#.
Sub Main()
s# = 123.55
t# = 2.55
u# = s# * t#
End Sub
. (keyword)
Syntax structure.member
2
Exam This example uses the period to separate an object from a property. Sub Main() MsgBox "The
ples clipboard text is: " & Clipboard.GetText() End Sub
Type Rect
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
Sub Main()
Dim r As Rect
r. left = 10
r. rigth = 12
Msgbox "r.left = "& r.left & ", r.right = " & r.right
End Sub
/ (operator)
Com The type of the result is Double , with the following exceptions:
ments
If one expression is and the other expression is then the type the result is
A runtime error is generated if the result overflows its legal range. When either or both expres
sions is Variant , then the following additional rules apply:
• If expression1 is Null and expression2 is Boolean , then the result is Empty . Other
wise, if either expression is Null , then the result is Null .
• Empty is treated as an Integer of value 0 .
• If both expressions are either Integer or Single variants and the result overflows, then
the result is automatically promoted to a Double variant.
Exam This example assigns values to two variables and their quotient to a third variable, then displays
ple the result.
Sub Main()
i% = 100
j# = 22.55
k# = i% / j#
End Sub
See \ (on page 222) (operator): Operator Precedence (on page 560) (topic)
Also
\ (operator)
Com Before the integer division is performed, each expression is converted to the data type of the
ments 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:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 223
Exam This example assigns the quotient of two literals to a variable and displays the result.
ple Sub Main()
s% = 100.99 \ 2.6
End Sub
See / (on page 221) (operator); Operator Precedence (on page 560) (Topic)
Also
^ (operator)
n^0 1
0^-n Undefined
0^+n 0
1^n 1
The type of the result is always Double, except with Boolean expressions, in which case the re
sult is Boolean. Fractional and negative exponents are allowed. If either expression is a Variant
containing NULL, then the result is NULL. It is important to note that raising a number to a nega
tive exponent produces a fractional result.
End Sub
_ (keyword)
Syn s$ = "This is a very long line that I want to split " & _ "onto two lines"
tax
De Line-continuation character, which allows you to split a single script onto more than one line.
scrip
tion
Com The line-continuation character cannot be used within strings and must be preceded by white
ments 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"
'long strings.
msg1 = "This line is a line of text that" & crlf & "extends beyond " _
& "the borders of the editor" & crlf & "so it is split into " _
'It is also useful for separating and continuing long calculation lines.
b# = .124
a# = .223
MsgBox msg1 & crlf & crlf & "The value of s# is: " & s#
End Sub
+ (operator)
Com Addition operates differently depending on the type of the two expressions:
ments
Empty variant Any data type Return the non- Empty expression unchanged.
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:.
A runtime error is generated if the result overflows its legal range Variant Add If both expres
sions 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:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 226
• 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.
Exam This example assigns string and numeric variable values and then uses the + operator to con
ple catenate the strings and form the sums of numeric variables.
Sub Main()
MsgBox "You can add literals or variables:" + Str(j%) + ", " + Str(k#)
End Sub
See & (on page 218) (Operator); Operator Precedence (on page 560) (topic)
Also
< (operator)
<= (operator)
<> (operator)
= (operator)
= (statement)
Com When assigning expressions to variables, internal type conversions are performed automatical
ments ly 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 convert
ing 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 perform
ing an automatic data conversion, underflow is not an error.
The assignment operator ( = ) cannot be used to assign objects. Use the Set statement in
stead.
b% = 100
c# = 1213.3443
End Sub
See Let (on page 498) (statement); Operator Precedence (on page 560) (topic); Set (on page
Also 626) (statement); Expression Evaluation (on page 421) (topic).
> (operator)
>= (operator)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 228
A
A
Abs (function)
And (operator)
AnswerBox (function)
AppActivate (statement)
AppClose (statement)
AppGetActive$ (function)
AppGetPosition (statement)
AppGetState (function)
AppHide (statement)
AppList (statement)
AppMaximize (statement)
AppMinimize (statement)
AppMove (statement)
AppRestore (statement)
AppSetState (statement)
AppShow (statement)
AppSize (statement)
AppType (function)
ArrayDims (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 229
Arrays (topic)
ArraySort (statement)
Atn (function)
Abs (function)
Com If expression is Null , then Null is returned. Empty is treated as 0 . The type of the result is
ments the same as that of expression, with the following exceptions:
• If expression is an Integer that overflows its legal range, then the result is returned as a
Long . This only occurs with the largest negative Integer :
Dim a As Variant
Dim i As Integer
i = -32768
i = Abs(i) 'Overflow!
• If expression is a Long that overflows its legal range, then the result is returned as a
Double . This only occurs with the largest negative Long :
Dim a As Variant
Dim l As Long
l = -2147483648
l = Abs(l) 'Overflow!
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 230
• If expression is a Currency value that overflows its legal range, an overflow error is gen
erated.
Exam This example assigns absolute values to variables of four types and displays the result.
ple Sub Main()
s1% = Abs(-10.55)
s2& = Abs(-10.55)
s3! = Abs(-10.55)
s4# = Abs(-10.55)
MsgBox "The absolute values are: " & s1% & "," & s2& & "," & s3! & "," & s4#
End Sub
And (operator)
Com If both expressions are either Boolean, Boolean variants, or Null variants, then a logical con
ments junction is performed as follows:
If the first expression is and the second expression 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 ex
pressions according to the following table:
1 And 1 = 1 Example:
0 And 1 = 0 5 00001001
1 And 0 = 0 6 00001010
ple n1 = 1001
n2 = 1000
b1 = True
b2 = False
n3 = n1 And n2
'the result.
If b1 And b2 Then
Else
End If
End Sub
See Al Operator Precedence (on page 560) (topic); Or (on page 567) (operator); Xor (on page
so 708) (operator); Eqv (on page 402));(operator); (operator) (on page 470).
AnswerBox (function)
De Displays a dialog box prompting the user for a response and returns an Integer indicating
scrip which button was clicked (1 for the first button, 2 for the second, and so on).
tion
Parameter Description
Prompt Text to be displayed above the text box. The prompt parameter
can be any expression convertible to a String .
The Basic Control Engine script 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. It also word-wraps any lines too long to fit
within the dialog box and truncates all lines beyond the maxi
mum number of lines that fit in the dialog box.
Button1 Text for the first button. If omitted, then "OK" and "Cancel" are
used. A runtime error is generated if this parameter is Null .
Button2 Text for the second button. A runtime error is generated if this
parameter is Null .
Button3 Text for the third button. A runtime error is generated if this para
meter is Null .
The width of each button is determined by the width of the widest button. The AnswerBox
function returns 0 if the user selects Cancel. R% = AnswerBox("Copy files?")
R% = AnswerBox("Copy files?","Save","Restore","Cancel")
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 233
Exam This example displays a dialog box containing three buttons. It displays an additional message
ple based on which of the three buttons is selected.
Sub Main()
Select Case r%
Case 1
Case 2
Case Else
End Select
End Sub
See MsgBox (on page 530) (statement); AskBox$ (on page 254) (function); AskPassword$
Also (on page 256) (function); InputBox, InputBox$ (on page 474) (functions); OpenFilename$
(on page 558) (function); SaveFilename$ (on page 611) (function); SelectBox (on page
622) (function).
Notes AnswerBox displays all text in its dialog box in 8-point MS Sans Serif.
De Used with the Declare statement to indicate that type checking is not to be performed with a
scrip given argument.
tion
Foo 10
Exam The following example calls the FindWindow to determine if Program Manager is running. This
ple example uses the Any keyword to pass a NULL pointer, which is accepted by the FindWindow
function.
Sub Main()
hWnd = FindWindow32("PROGMAN",0&)
Else
hWnd = 0
End If
End If
End Sub
AppActivate (statement)
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 235
TaskID Number specifying the task ID of the application to be activated. Acceptable task IDs
are returned by the Shell function
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 The Basic
Control Engine script is running.
End Sub
Exam This example runs another application, activates it, and maximizes it.
ple 2 Sub Main()
Dim id as variant
AppMaximize
End Sub
See Shell (on page 629) (function); SendKeys (on page 623) (statement); WinActivate (on page
Also 695) (statement).
Notes • The name$ parameter is the exact string appearing in the title bar of the named applica
tion's main window. If no application is found whose title exactly matches name$, then
a second search is performed for applications whose title string begins with name$. If
more than one application is found that matches name$, then the first application en
countered is used.
• Minimized applications are not restored before activation. Thus, activating a minimized
DOS application will not restore it; rather, it will highlight its icon.
• A runtime error results if the window being activated is not enabled, as is the case if that
application is currently displaying a modal dialog box.
AppClose (statement)
Com The name$ parameter is a String containing the name of the application. If the name$ parame
ments ter is absent, then the AppClose statement closes the active application.
Exit Sub
End If
End Sub
See AppMaximize (on page 241) (statement); AppMinimize (on page 242) (statement); AppRe
Also store (on page 244) (statement); AppMove (on page 243) (statement); AppSize (on page
247) (statement).
Notes A runtime error results if the application being closed is not enabled, as is the case if that appli
cation is currently displaying a modal dialog box. The name$ parameter is the exact string ap
pearing in the title bar of the named application's main window. If no application is found whose
title exactly matches name$, then a second search is performed for applications whose title
string begins with name$. If more than one application is found that matches name$, then the
first application encountered is used.
De Returns a String containing the full name of the application matching either title or taskID.
scrip
tion
Com The title parameter specifies the title of the application to find. If there is no exact match, Ba
ments sicScript 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, where
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 237
as 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 in
stead of a zero-length String). AppFind$ is generally used to determine whether a given applica
tion is running. The following expression returns True if Microsoft Word is running:
AppFind$("Microsoft Word")
Exam
ple 'This example checks to see whether Excel is running before
'activating it.
Sub Main()
Else
End If
End Sub
Notes This function returns a String containing the exact text appearing in the title bar of the active
application's main window.
AppGetActive$ (function)
Syn AppGetActive$()
tax
Com If no application is active, the AppGetActive$ function returns a zero-length string. You can use
ments AppGetActive$ to retrieve the name of the active application. You can then use this name in
calls to routines that require an application name.
ple n$ = AppGetActive$()
AppMinimize n$
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 238
See AppActivate (on page 234) (statement); WinFind (on page 697) (function).
Also
Notes This function returns a String containing the exact text appearing in the title bar of the active
application's main window.
AppGetPosition (statement)
Parame Description
ter
width, Names of Integer variables to receive the size of the application's window.
height
Name$ String containing the name of the application. If the name$ parameter is omitted,
then the active application is used.
The x, y, width, and height variables are filled with the position and size of the application's win
dow. If an argument is not a variable, then the argument is ignored, as in the following example,
which only retrieves the x and y parameters and ignores the width and height parameters:
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 239
See AppMove (on page 243) (statement); AppSize (on page 247) (statement).
Also
Note The position and size of the window are returned in twips. The name$ 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 name$, then a second search is performed for applications
whose title string begins with name$. If more than one application is found that matches name
$, then the first application encountered is used.
AppGetState (function)
Maximized ebMaximized
Minimized ebMinimized
Restored ebRestored
The name$ parameter is a String containing the name of the desired application. If it is omit
ted, then the AppGetState function returns the name of the active application.
Exam This example saves the state of Program Manager, changes it, then restores it to its original set
ples ting.
Sub Main()
Exit Sub
End If
End Sub
See AppMaximize (on page 241) (statement); AppMinimize (on page 242) (statement); AppRe
Also store (on page 244) (statement).
Notes The name$ 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 name$, then a second
search is performed for applications whose title string begins with name$. If more than one ap
plication is found that matches name$, then the first application encountered is used.
AppHide (statement)
Com If the named application is already hidden, the AppHide statement will have no effect. The
ments name$ parameter is a String containing the name of the desired application. If it is omitted,
then the AppHide statement hides the active application. AppHide generates a runtime error
if the named application is not enabled, as is the case if that application is displaying a modal
dialog box.
End Sub
Notes The name$ 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 name$, then a second
search is performed for applications whose title string begins with name$. If more than one ap
plication is found that matches name$, then the first application encountered is used.
AppList (statement)
Com The AppNames$ parameter must specify either a zero- or one-dimensioned dynamic String
ments array or a one-dimensional fixed String array. If the array is dynamic, then it will be redimen
sioned to match the number of open applications. For fixed arrays, AppList first erases each ar
ray element, then begins assigning application names to the elements in the array. If there are
fewer elements than will fit in the array, then the remaining elements are unused. The script re
turns a runtime error if the array is too small to hold the new elements. After calling this func
tion, you can use LBound and UBound to determine the new size of the array.
Dim apps$()
AppList apps
AppMinimize apps(i)
Next i
End Sub
Notes The name of an application is considered to be the exact text that appears in the title bar of the
application's main window.
AppMaximize (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 242
Com The name$ parameter is a String containing the name of the desired application. If it is omit
ments ted, then the AppMaximize function maximizes the active application.
End If
End Sub
See AppMinimize (on page 242) (statement); AppRestore (on page 244) (statement); AppMove
Also (on page 243) (statement); AppSize (on page 247) (statement); AppClose (on page 235)
(statement).
Notes If the named application is maximized or hidden, the AppMaximize statement will have no ef
fect. The name$ parameter is the exact string appearing in the title bar of the named applica
tion's main window. If no application is found whose title exactly matches name$, then a sec
ond search is performed for applications whose title string begins with name$. If more than one
application is found that matches name$, then the first application encountered is used. App
Maximize generates a runtime error if the named application is not enabled, as is the case if
that application is displaying a modal dialog box.
AppMinimize (statement)
Com The name$ parameter is a String containing the name of the desired application. If it is omit
ments ted, then the AppMinimize function minimizes the active application.
End If
End Sub
See AppMaximize (on page 241) (statement); AppRestore (on page 244) (statement); AppMove
Also (on page 243) (statement); AppSize (on page 247) (statement); AppClose (on page 235)
(statement).
Notes If the named application is minimized or hidden, the AppMinimize statement will have no ef
fect. The name$ parameter is the exact string appearing in the title bar of the named applica
tion's main window. If no application is found whose title exactly matches name$, then a sec
ond search is performed for applications whose title string begins with name$. If more than one
application is found that matches name$, then the first application encountered is used. App
Minimize generates a runtime error if the named application is not enabled, as is the case if
that application is displaying a modal dialog box.
AppMove (statement)
De Sets the upper left corner of the named application to a given location.
scrip
tion
Para Description
meter
X, Y Integer coordinates specifying the upper left corner of the new location of the applica
tion, static to the upper left corner of the display.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 244
name String containing the name of the application to move. If this parameter is omitted, then
$ the active application is moved.
Exam This example activates Program Manager, then moves it 10 pixels to the right.
ple Sub Main()
Dim x%,y%
End Sub
See AppMaximize (on page 241) (statement); AppMinimize (on page 242) (statement); AppRe
Also store (on page 244) (statement); AppSize (on page 247) (statement); AppClose (on page
235) (statement).
Note If the named application is maximized or hidden, the AppMove statement will have no effect.
The X and Y parameters are specified in twips. AppMove will accept X and Y parameters that
are off the screen. The name$ 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 name
$, then a second search is performed for applications whose title string begins with name$. If
more than one application is found that matches name$, then the first application encountered
is used. AppMove 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.
AppRestore (statement)
Com The name$ parameter is a String containing the name of the application to restore. If this para
ments meter is omitted, then the active application is restored.
End Sub
See AppMaximize (on page 241) (statement); AppMinimize (on page 242) (statement); AppMove
Also (on page 243) (statement); AppSize (on page 247) (statement); AppClose (on page 235)
(statement).
Notes The name$ 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 name$, then a second
search is performed for applications whose title string begins with name$. If more than one ap
plication is found that matches name$, then the first application encountered is used. AppRe
store 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 applica
tion is currently displaying a modal dialog box.
AppSetState (statement)
De Maximizes, minimizes, or restores the named application, depending on the value of newstate.
scrip
tion
Parameter Description
Newstate Integer specifying the new state of the window. It can be any of the following val
ues.
Value Description
Name$ String containing the name of the application to change. If this parameter is omit
ted, then the active application is used.
Exam This example saves the state of Program Manager, changes it, then restores it to its original set
ple ting.
Sub Main()
Exit Sub
End If
End Sub
See AppGetState (on page 239) (function); AppRestore (on page 244) (statement); AppMaxi
Also mize (on page 241) (statement); AppMinimize (on page 242) (statement)
Notes The name$ 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 name$, then a second
search is performed for applications whose title string begins with name$. If more than one ap
plication is found that matches name$, then the first application encountered is used.
AppShow (statement)
Com The name$ parameter is a String containing the name of the application to show. If this para
ments meter is omitted, then the active application is shown.
Sub Main()
End Sub
Notes: If the named application is already visible, AppShow will have no effect. The name$ parame
ter 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 name$, then a second search is performed for
applications whose title string begins with name$. If more than one application is found that
matches name$, then the first application encountered is used. 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)
Parame Description
ter
Name$ String containing the name of the application to resize. If this parameter is omitted,
then the active application is used.
Exam This example enlarges the active application by 10 pixels in both the vertical and horizontal di
ple rections.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 248
Sub Main()
Dim w%,h%
End Sub
See AppMaximize (on page 241) (statement); AppMinimize (on page 242) (statement); AppRe
Also store (on page 244) (statement); AppMove (on page 243) (statement); AppClose (on page
235) (statement).
Note The width and height parameters are specified in twips. This statement will only work if the
named application is restored (i.e., not minimized or maximized). The name$ 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 name$, then a second search is performed for applications
whose title string begins with name$. If more than one application is found that matches name
$, then the first application encountered is used. A runtime error results if the application be
ing 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)
De Returns an Integer indicating the executable file type of the named application:
scrip
tion
Com The name$ parameter is a String containing the name of the application. If this parameter is
ments omitted, then the active application is used.
Exam This example creates an array of strings containing the names of all the running Windows appli
ple cations. It uses the AppType command to determine whether an application is a Windows appli
cation or a DOS application.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 249
Sub Main()
Dim apps$(),wapps$()
If ArrayDims(apps) = 0 Then
Exit Sub
End If
ReDim wapps$(UBound(apps))
n = 0 'Copy the Windows apps from one array to the target array.
wapps(n) = apps(i)
n = n + 1
End If
Next I
Exit Sub
End If
End Sub
Notes The name$ 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 name$, then a second
search is performed for applications whose title string begins with name$. If more than one ap
plication is found that matches name$, then the first application encountered is used.
ArrayDims (function)
Com This function can be used to determine whether a given array contains any elements or if the ar
ments ray is initially created with no dimensions and then redimensioned by another function, such as
the FileList function, as shown in the following example.
Exam This example allocates an empty (null-dimensioned) array; fills the array with a list of filenames,
ple which resizes the array; then tests the array dimension and displays an appropriate message.
Sub Main()
Dim f$()
FileList f$,"c:\*.bat"
If ArrayDims(f$) = 0 Then
Else
End If
End Sub
See LBound (on page 493) (function); UBound (on page 677) (function); Arrays (topic)
Also
Arrays (topic)
Declaring Array Variables Arrays in a Basic Control Engine script are declared using any of the following
statements:
Dim
Public
Private
For example:
Private
Arrays of any data type can be created, including Integer, Long, Single, Double, Boolean, Date, Variant,
Object, user-defined structures, and data objects. The lower and upper bounds of each array dimension
must be within the following range:
Arrays can have up to 60 dimensions. Arrays can be declared as either fixed or dynamic, as described
below.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 251
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 ten strings:
Fixed arrays can be used as members of user-defined data types. The following example shows a struc
ture 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:
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:
Querying Arrays The following table describes the functions used to retrieve information about arrays.
LBound Retrieve the lower bound of an array. A runtime error is generated if the array has no di
mensions.
UBound Retrieve the upper bound of an array. A runtime error is generated if the array has no di
mensions.
ArrayDims Retrieve the number of dimensions of an array. This function returns 0 if the array has
no dimensions
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 252
Operations on Arrays
ArraySort Sort an array of integers, longs, singles, doubles, currency, Booleans, dates, or vari
ants.
ReadIniSection Fill an array with the item names from a section in an ini file.
ArraySort (statement)
Com If a string array is specified, then the routine sorts alphabetically in ascending order using case-
ments sensitive string comparisons. If a numeric array is specified, the ArraySort statement sorts
smaller numbers to the lowest array index locations. The script generates a runtime error if you
specify an array with more than one dimension. When sorting an array of variants, the following
rules apply:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 253
String comparison is case-sensitive (this function is not affected by the Option Compare set
ting).
Exam This example dimensions an array and fills it with filenames using FileList, then sorts the array
ple and displays it in a select box.
Sub Main()
Dim f$()
FileList f$,"c:\*.*"
ArraySort f$
r% = SelectBox("Files","Choose one:",f$)
End Sub
See ArrayDims (on page 249) (function); LBound (on page 493) (function); UBound (on page
Also 677) (function)
De Returns an Integer containing the numeric code for the first character of string.
scrip
tion
Com This function returns the character value of the first character of string. On single-byte systems,
ments this function returns a number between 0 and 255, whereas on MBCS systems, this function re
turns a number between -32768 and 32767. On wide platforms, this function returns the MBCS
character code after converting the wide character to MBCS. To return the value of the first byte of
a string, use the AscB function. This function is used when you need the value of the first byte of
a string known to contain byte data rather than character data. On single-byte systems, the As-
cB function is identical to the Asc function. On platforms where BasicScript uses wide string in
ternally (such as Win32), the AscW function returns the character value native to that platform.
For example, on Win32 platforms, this function returns the UNICODE character code. On sin
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 254
gle-byte and MBCS platforms, the AscW function is equivalent to the Asc function. The following
table summarizes the values returned by these functions:
Exam This example fills an array with the ASCII values of the string s components and displays the re
ple sult.
Sub Main()
msg1 = ""
For i = 1 To Len(s$)
Next i
End Sub
See Chr (on page 283), Chr$ (on page 283) (functions).
Also
De Displays a dialog box requesting input from the user and returns that input as a String .
scrip
tion
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.
Function Returns
AskBox$ String containing the input typed by the user in the text box. A zero-length
string is returned if the user selects Cancel.
AskBox 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 para
meters are specified, then a Help button is added in addition to the OK and Cancel buttons. Con
text-sensitive help can be invoked by selecting this button or using the help key (F1). Invoking
help does not remove the dialog.
Exam This example asks the user to enter a filename and then displays what he or she has typed.
ple Sub Main()
End Sub
See MsgBox (on page 527) (statement); AskPassword$ (function); InputBox, InputBox$ (on page
Also 474) (functions); OpenFilename$ (on page 558) (function); SaveFilename$ (on page 611)
(function); SelectBox (on page 622) (function).
Note The text in the dialog box is displayed in 8-point MS Sans Serif.
De Returns a String containing the text that the user typed.
scrip
tion
Com Unlike the AskBox/AskBox$ functions, the user sees asterisks in place of the characters that are
ments actually typed. This allows the hidden input of passwords. The AskPassword/AskPassword$ func
tions take the following parameters:
Parameter Description
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 257
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.
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.
Function Returns
AskPassword$ text typed into the text box, up to a maximum of 255 characters. A ze
ro-length string is returned if the user selects Cancel.
AskPassword 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.
End Sub
See MsgBox (on page 527) (statement); AskBox$ (on page 254) (function); InputBox, InputBox$
Also (on page 474) (functions); OpenFilename$ (on page 558) (function); SaveFilename$ (on
page 611) (function); SelectBox (on page 622) (function); AnswerBox (on page 231) (func
tion).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 258
Notes The text in the dialog box is displayed in 8-point MS Sans Serif.
Atn (function)
Example This example finds the angle whose tangent is 1 (45 degrees) and displays the re
sult.
Sub Main()
a# = Atn(1.00)
MsgBox "1.00 is the tangent of " & a# & " radians (45 degrees)."
End Sub
See Also Tan (on page 664) (function); Sin (on page 631) (function); Cos (on page 306)
(function).
B
B
Basic.Architecture$ (property)
Basic.Capability (method)
Basic.CodePage (property)
Basic.Eoln$ (property)
Basic.FreeMemory (property)
Basic.HomeDir$ (property)
Basic.Locale$ (property)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 259
Basic.OperatingSystem$ (Proper
ty)
Basic.OperatingSystemVendor$
Basic.OperatingSystemVersion$
Basic.OS (property)
Basic.Pathseparator$ (property)
Basic.Processor$ (Property)
Basic.ProcessorCount$ (property)
Basic.Version$ (property)
Beep (statement)
ByRef (keyword)
ByVal (keyword)
Basic.Architecture$ (property)
Syntax Basic.Architecture$
Descrip Returns a String containing the CPU architecture on which BasicScript is executing.
tion
The Basic.Architecture$ property returns an empty string if the architecture cannot be deter
mined by BasicScript.
Example
'
'
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 260
MsgBox Basic.Architecture$
End Sub
See Also Basic.Processor$ (on page 267) (property), Basic.ProcessorCount (on page 268) (proper
ty)
Basic.Capability (method)
Syntax Basic.Capability(which)
De Returns True if the specified capability exists on the current platform; returns False other
scrip wise.
tion
Com The which parameter is an Integer specifying the capability for which to test. It can be any of
ments the following values:
1 Disk drives
Exam This example tests to see whether your current platform supports disk drives and hidden file
ple attributes and displays the result.
Sub Main()
If Basic.Capability(1) Then
Else
End If
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 261
MsgBox msg1
End Sub
Basic.CodePage (property)
Syntax Basic.CodePage
Descrip Returns an Integer representing the code page for the current locale.
tion
Com Basic.CodePage returns ANSI code page for the current locale, such as 437 for MS-DOS Latin
ments US or 932 for Japanese.
Example
Sub Main
End If
End Sub
See Also Basic.Locale$ (on page 263) (property); Basic.OS (on page 266) (property)
Basic.Eoln$ (property)
Syntax Basic.Eoln$
Descrip Returns a String containing the end-of-line character sequence appropriate to the current
tion platform.
Com This string will be either a carriage return, a carriage return/line feed, or a line feed.
ments
Sub Main()
MsgBox "This is the first line of text." & Basic.Eoln$ & "This is the second line of text."
End Sub
Basic.FreeMemory (property)
Syn Basic.FreeMemory
tax
De Returns a Long representing the number of bytes of free memory in the script's data space.
scrip
tion
Com This function returns the size of the largest free block in the script's data space. Before this
ments number is returned, the data space is compacted, consolidating free space into a single contigu
ous free block. The script's data space contains strings and dynamic arrays.
MsgBox "The largest free memory block is: " & Basic.FreeMemory
End Sub
See System.TotalMemory (on page 661) (property); System.FreeMemory (on page 659) (prop
Also erty); System.FreeResources (on page 660) (property); Basic.FreeMemory (on page 262)
(property).
Basic.HomeDir$ (property)
Syntax Basic.HomeDir$
Descrip Returns the path to the basic script runtime engine components, e.g. c:\Program Files\Profi
tion cy\Proficy CIMPLICITY\exe.
Com This method is used to find the HMI/SCADA CIMPLICITY exe directory.
ments
Example This example assigns the home directory to HD and displays it.
Sub Main()
hd$ = Basic.HomeDir$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 263
MsgBox "The Basic Control Engine home directory is: " & hd$
End Sub
Basic.Locale$ (property)
Syn Basic.Locale$
tax
De Returns a String containing the locale under which BasicScript is running.
scrip
tion
Com The locale helps you identify information about your environment, such as the date formats,
ments time format, and other country-sensitive information. The following table describes the returned
value from Basic.Locale$ on the Win32 platform.
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.
englang: Full English name of the language as defined by ISO standard 639.
Exam
ple 'This example checks to see if we are running in a Japanese
'version of Windows.
Sub Main
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 264
See Basic.OS (on page 266) (property) , Basic.CodePage (on page 261) (property)
Also
Basic.OperatingSystem$ (property)
Syntax Basic.OperatingSystem$
Com The value returned by this function for the Win32 operating systems is Win32s.
ments
Example
'This script checks the Windows version for special networking
’capabilities.
'
Sub Main()
End If
End Sub
Basic.OperatingSystemVendor$ (property)
Syntax Basic.OperatingSystemVendor$
Descrip Returns a String containing the version of the operating system under which BasicScript is
tion running.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 265
Example
'
'
Sub Main
Basic.OperatingSystemVendor$
End Sub
Basic.OperatingSystemVersion$ (property)
Syntax Basic.OperatingSystemVersion$
De Returns a String containing the version of the operating system under which BasicScript is
scrip running.
tion
Com The version number is returned in the following format: major.minor.buildnumber The parts of
ments the version number are as follows.
Exam
ple '
'feature is supported.
'
Sub Main
If Basic.OperatingSystem$ = "Windows"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 266
Else
End If
End If
End Sub
Basic.OS (property)
Syn Basic.OS
tax
The value returned is not necessarily the platform under which the Basic Control Language
script is running but rather an indicator of the platform for which the script was created.
Exam This example determines the operating system for which this version was created and displays
ple the appropriate message.
Sub Main()
Case ebWin32
s = "Windows XP"
Case Else
End Select
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 267
Basic.PathSeparator$ (property)
Syntax Basic.PathSeparator$
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)
MsgBox "The path separator for this platform is: " & Basic.PathSeparator$
End Sub
Basic.Processor$ (property)
Syntax Basic.Processor$
Descrip Returns a String containing the name of the CPU in the computer on which BasicScript is
tion running.
PowerPC 601
603
604
603+
604+
620
Example
'
'BasicScript is executing.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 268
'
Sub Main()
End Sub
Note You can retrieve the number of processors within the computer using the Basic.Processor-
Count property.
Basic.ProcessorCount$ (property)
Syntax Basic.ProcessorCount
De Returns the number of CPUs installed on the computer on which BasicScript is running.
scrip
tion
Com Basic.ProcessorCount$ returns 1 if the CPU has only one processor or is otherwise incapable
ments of containing more than one processor.
Exam
ple '
'
Sub Main()
End Sub
Basic.Version$ (Property)
Syntax Basic.Version$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 269
Com This function returns the major and minor version numbers in the format major.minor.Build
ments Number, as in "2.00.30."
Example This example displays the current version of the Basic Control Engine.
Sub Main()
MsgBox "Version " & Basic.Version$ & " of Basic Control Engine is running"
End Sub
Beep (statement)
Syntax Beep
Example This example causes the system to beep five times and displays a reminder mes
sage.
Sub Main()
For i = 1 To 5
Beep
Sleep 200
Next i
End Sub
De Defines a dialog box template for use with the Dialog statement and function.
scrip
tion
Com A dialog box template is constructed by placing any of the following statements between the
ments Begin Dialog and End Dialog statements (no other statements besides comments can appear
within a dialog box template):
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 270
Button
PushBut- OKButton
ton
Parame Description
ter
x, y Integer coordinates specifying the position of the upper left corner of the dialog box
static to the parent window. These coordinates are in dialog units. If either coordi
nate is unspecified, then the dialog box will be centered in that direction on the par
ent window.
width, Integer coordinates specifying the width and height of the dialog box (in dialog
height units).
Dialog Name of the dialog box template. Once a dialog box template has been created, a
Name variable can be dimensioned using this name.
title$ String containing the name to appear in the title bar of the dialog box. If this parame
ter specifies a zero-length string, then the name "Basic Control Engine" is used.
.DlgProc Name of the dialog function. The routine specified by .DlgProc will be called by the
script when certain actions occur during processing of the dialog box. (See DlgProc
[prototype] for additional information about dialog functions.) If this omitted, then the
script processes the dialog box using the default dialog box processing behavior.
style Specifies extra styles for the dialog. It can be any of the following values:
Value Meaning
2 (or omitted) Dialog contains both the title and close box.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 271
The script generates an error if the dialog box template contains no controls. A dialog box tem
plate must have at least one PushButton , OKButton , or CancelButton statement. Otherwise,
there will be no way to close the dialog box. Dialog units are defined as ¼ the width of the font
in the horizontal direction and 1/8 the height of the font in the vertical direction. Any number of
user dialog boxes can be created, but each one must be created using a different name as the
DialogName. Only one user dialog box may be invoked at any time. Expression Evaluation with
in the Dialog Box Template The Begin Dialog statement creates the template for the dialog box.
Any expression or variable name that appears within any of the statements in the dialog box
template is not evaluated until a variable is dimensioned of type DialogName. The following ex
ample shows this behavior:
Sub Main()
OKButton 12,40,40,14
End Dialog
rc% = Dialog(dummy)
End Sub
The above example creates a dialog box with the title " Sample Dialog ". Expressions within dia
log box templates cannot reference external subroutines or functions. All controls within a dia
log box use the same font. The fonts used for text and text box control can be changed explicit
ly by setting the font parameters in the Text and TextBox statements. A maximum of 128 fonts
can be used within a single dialog, although the practical limitation may be less.
OKButton 12,40,40,14
CancelButton 60,40,40,14
End Dialog
rc% = Dialog(QuitDialog)
Case -1
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 272
Case 1
End Select
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); Combo
Also Box (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338)
(statement); DropListBox (on page 371) (statement); End Dialog (on page 400) (statement);
GroupBox (on page 457) (statement); ListBox (on page 504) (statement); OKButton (on page
551) (statement); OptionButton (on page 564) (statement); OptionGroup (on page 566)
(statement); Picture (statement; PushButton (on page 584) (statement); Text (on page 664)
(statement); TextBox (on page 666) (statement); DlgProc (on page 352) (function).
Note Within user dialog boxes, the default font is 8-point MS Sans Serif.
Syn Boolean
tax
De A data type capable of representing the logical values TRUE and FALSE .
scrip
tion
Com Boolean variables are used to hold a binary value—either TRUE or FALSE. Variables can be de
ments clared 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 appearing as a structure member, Boolean members
require 2 bytes of storage. When used within binary or random files, 2 bytes of storage are re
quired. 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-de
claration character for Boolean variables.
Boolean variables that have not yet been assigned are given an initial value of False .
See Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Integer (on page 479) (data type); Long (on page 511) (data type); Object (on
page 546) (data type); Single (on page 631) (data type); String (on page 654) (data type);
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 273
Variant (on page 684) (data type); DefType (on page 333) (statement); CBool (on page
277) (function); True (on page 673) (constant); False (on page 424) (constant).
ByRef (keyword)
De Used within the Sub...End Sub, Function...End Function, or Declare statement to specify that
scrip a given parameter can be modified by the called routine.
tion
Com Passing a parameter by reference means that the caller can modify that variable's value. Unlike
ments 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:
ple a = 14
End Sub
Sub Main()
b = 12
Test b
MsgBox "The ByRef value is: " & b ' <-- Displays 14.
End Sub
See () (on page 218) (keyword), ByVal (on page 273) (keyword).
Also
ByVal (keyword)
Com The ByVal keyword can appear before any parameter passed to any function, statement, or
ments method to force that parameter to be passed by value. Passing a parameter by value means
that the caller cannot modify that variable's value. Enclosing a variable within parentheses has
the same effect as the ByVal keyword:
When calling external statements and functions (that is, routines defined using the Declare
statement), the ByVal keyword forces the parameter to be passed by value regardless of the de
claration of that parameter in the Declare statement. The following example shows the effect of
the ByVal keyword used to passed an Integer to an external routine:
i% = 6
Since the Foo routine expects to receive a pointer to an Integer , the first call to Foo will have
unpredictable results.
a = a + 1
End Sub
Sub Main()
Dim i As Integer
i = 10
Foo i
MsgBox "The ByVal value is: " & i 'Displays 11 (Foo changed the value).
Foo ByVal i
MsgBox "The ByVal value is still: " & i 'Displays 11 (Foo did not change the value).
End Sub
See () (on page 218) (keyword), ByRef (on page 273) (keyword).
Also
C
C
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 275
Call (statement)
CancelButton (statement)
CBool (function)
CCur (function)
CDbl (function)
ChDir (statement)
ChDrive (statement)
CheckBox (statement)
Choose (function)
Clnt (function)
Clipboard$ (function)
Clipboard$ (statement)
Clipboard.Clear (method)
Clipboard.GetFormat (method)
Clipboard.GetText (method)
Clipboard.SetText (method)
CLng (function)
Close (statement)
ComboBox (statement)
Comments (topic)
Const (statement)
Constants (topic)
Cos (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 276
CreateObject (function)
CSng (function)
CStr (function)
CVar (function)
CVErr (function)
Call (statement)
De Transfers control to the given subroutine, optionally passing the specified arguments.
scrip
tion
Com Using this statement is equivalent to: subroutine_name [arguments] Use of the Call statement
ments 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 state
ment must be declared outside of the Main procedure, as shown in the following example.
Exam This example demonstrates the use of the Call statement to pass control to another function.
ple Sub Example_Call(s$)
End Sub
Sub Main()
s$ = "DAVE"
Example_Call s$
Call Example_Call("SUSAN")
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 277
See Goto (on page 457) (statement); GoSub (on page 455) (statement); Declare (on page 333)
Also (statement).
CDbl (function)
Syn CDbl(expression)
tax
Com This function accepts any expression convertible to a Double , including strings. A runtime error
ments is generated if expression is Null . Empty is treated as 0.0 . When passed a numeric expres
sion, this function has the same effect as assigning the numeric expression number to a Dou
ble . When used with variants, this function guarantees that the variant will be assigned a Dou
ble ( VarType 5 ).
i% = 100
j! = 123.44
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CInt (on page 285) (function); CLng (on page 293) (function); CSng (on
page 306) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Double (on page 370) (data type).
CBool (function)
Com The expression parameter is any expression that can be converted to a Boolean . A runtime
ments error is generated if expression is Null . All numeric data types are convertible to Boolean . If
expression is zero, then the CBool returns False ; otherwise, CBool returns True . Empty is
treated as False . If expression is a String , then CBool first attempts to convert it to a num
ber, then converts the number to a Boolean . A runtime error is generated if expression cannot
be converted to a number. A runtime error is generated if expression cannot be converted to a
Boolean .
Exam This example uses CBool to determine whether a string is numeric or just plain text.
ple Sub Main()
s$ = 34224.54
IsNumeric = CBool(IsNumeric(s$))
Else
End If
End Sub
See CCur (on page 278) (function); CDate, CVDate (on page 279) (functions); CDbl (on page
Also 277) (function); CInt (on page 285) (function); CLng (on page 293) (function); CSng (on
page 306) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Boolean (on page 272) (data type).
CCur (function)
Com This function accepts any expression convertible to a Currency , including strings. A runtime er
ments ror is generated if expression is Null or a String not convertible to a number. Empty is treat
ed as 0. When passed a numeric expression, this function has the same effect as assigning the
numeric expression number to a Currency . When used with variants, this function guarantees
that the variant will be assigned a Currency ( VarType 6).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 279
Exam This example displays the value of a String converted into a Currency value.
ple Sub Main()
i$ = "100.44"
End Sub
See CBool (on page 277) (function); CDate, CVDate (on page 279) (functions); CDbl (on page
Also 277) (function); CInt (on page 285) (function); CLng (on page 293) (function); CSng (on
page 306) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Currency (on page 308) (data type).
Com The expression parameter is any expression that can be converted to a Date . A runtime error is
ments generated if expression is Null . If expression is a String , an attempt is made to convert it to a
Date using the current country settings. If expression does not represent a valid date, then an
attempt is made to convert expression to a number. A runtime error is generated if expression
cannot be represented as a date. These functions are sensitive to the date and time formats of
your computer. The CDate and CVDate functions are identical.
Exam This example takes two dates and computes the difference between them.
ple Sub Main()
date1 = CDate(#1/1/1994#)
diff = DateDiff("d",date1,date2)
MsgBox "The date difference is " & CInt(diff) & " days."
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 280
See CCur (on page 278) (function); CBool (on page 277) (function); CDbl (on page 277) (func
Also tion); CInt (on page 285) (function); CLng (on page 293) (function); CSng (on page 306)
(function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr (on page
310) (function); Date (on page 313) (data type).
ChDir (statement)
De Changes the current directory of the specified drive to newdir$. This routine will not change the
scrip current drive. (See ChDrive [statement].)
tion
Exam This example saves the current directory, then changes to the root directory, displays the old
ple and new directories, restores the old directory, and displays it.
Sub Main()
save$ = CurDir$
ChDir(Basic.PathSeparator$)
MsgBox "Old directory: " & save$ & crlf & "New directory: " & CurDir$
ChDir(save$)
End Sub
See ChDrive (on page 280) (statement); CurDir, CurDir$ (on page 308) (functions); Dir, Dir$ (on
Also page 339) (functions); MkDir (on page 521) (statement); RmDir (on page 606) (statement).
ChDrive (statement)
Com Only the first character of DriveLetter$ is used. DriveLetter$ is not case-sensitive. If DriveLet
ments ter$ is empty, then the current drive is not changed.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 281
Exam This example allows the user to select a new current drive and uses ChDrive to make their
ple choice the new current drive.
Sub Main()
Dim d()
old$ = FileParse$(CurDir,1)
DiskDrives d
Again:
MsgBox "Old Current Drive: " & old$ & crlf & "New Current Drive: " & CurDir
End
Error_Trap:
MsgBox Error(err)
Resume Again
End Sub
See Al ChDir (on page 280) (statement); CurDir, CurDir$ (on page 308) (functions); Dir, Dir$ (on
so page 339) (functions); MkDir (on page 521) (statement); RmDir (on page 606) (state
ment); DiskDrives (on page 341) (statement).
CheckBox (statement)
Com Check box controls are either on or off, depending on the value of .Identifier. This statement can
ments only appear within a dialog box template (i.e., between the Begin Dialog and End Dialog state
ments). The CheckBox statement requires the following parameters:
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 282
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
Width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Title$ String containing the text that appears within the check box. This text may contain an
ampersand character to denote an accelerator letter, such as "&Font" for Font (indicat
ing that the Font control may be selected by pressing the F accelerator key).
Identi Name by which this control can be referenced by statements in a dialog function (such
fier as DlgFocus and DlgEnable ). This parameter also creates an integer variable whose
value corresponds to the state of the check box (1 = checked; 0 = unchecked). This vari
able can be accessed using the syntax: DialogVariable.Identifier.
When the dialog box is first created, the value referenced by .Identifier is used to set the initial
state of the check box. When the dialog box is dismissed, the final state of the check box is
placed into this variable. By default, the .Identifier variable contains 0, meaning that the check
box is unchecked.
Exam This example displays a dialog box with two check boxes in different states.
ple Sub Main()
GroupBox 4,4,84,40,"GroupBox"
OKButton 104,8,40,14,.OK
CancelButton 104,28,40,14,.Cancel
End Dialog
r% = Dialog(SaveOptions)
If r% = -1 Then
End If
End Sub
See CancelButton (on page 286) (statement); Dialog (on page 336) (function); Dialog (on page
Also 338) (statement); DropListBox (on page 371) (statement); GroupBox (on page 457) (state
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 283
ment); ListBox (on page 504) (statement); OKButton (on page 551) (statement); OptionBut
ton (on page 564) (statement); OptionGroup (on page 566) (statement); Picture (on page
570) (statement); PushButton (on page 584) (statement); Text (on page 664) (statement);
TextBox (on page 666) (statement); Begin Dialog (on page 269) (statement), PictureButton
(on page 584) (statement).
Notes Accelerators are underlined, and the accelerator combination Alt+letter is used.
Choose (function)
Syn Choose(index,expression1,expression2,...,expression13)
tax
Com The index parameter specifies which expression is to be returned. If index is 1, then expression1
ments is returned; if index is 2, then expression2 is returned, and so on. If index is less than 1 or greater
than the number of supplied expressions, then Null is returned. The Choose function returns
the expression without converting its type. Each expression is evaluated before returning the se
lected one.
Dim a As Variant
Dim c As Integer
c% = 2
a = Choose(c%,"Hello, world",#1/1/94#,5.5,False)
MsgBox "Item " & c% & " is '" & a & "'" 'Displays the date passed as parameter 2.
End Sub
See Switch (on page 657) (function); IIf (on page 468) (function); If...Then...Else (on page 466)
Also (statement); Select...Case (on page 620) (statement).
tax
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 284
Com The Chr$, ChrB$, and ChrW$ functions return a String, whereas the Chr, ChrB, and ChrW functions re
ments turn a String variant. These functions behave differently depending on the string format used by
BasicScript. These differences are summarized in the following table:
ChrW[$] SBCS 0 and 255 1-byte character string (same as the Chr and Chr$ func
tions)
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
Exam
ple Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 285
Dim a%(2)
For i = 0 To 2
a%(i) = (65 + i)
Next i
End Sub
See Asc, AscB, AscW (on page 253) (functions); Str, Str$ (on page 650) (functions).
Also
CInt (function)
Syn CInt(expression)
tax
Com This function accepts any expression convertible to an Integer , including strings. A runtime er
ments ror is generated if expression is Null . Empty is treated as 0 . The passed numeric expression
must be within the valid range for integers:
A runtime error results if the passed expression is not within the above range. When passed a
numeric expression, this function has the same effect as assigning a numeric expression to an
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 286
Integer . Note that integer variables are rounded before conversion. When used with variants,
this function guarantees that the expression is converted to an Integer variant ( VarType 2).
Exam This example demonstrates the various results of integer manipulation with CInt.
ple Sub Main()
I# = 100.55
j# = 100.22
'(3) Assigns k% (integer) to the CInt sum of j# and k% and displays k% '(201).
k% = CInt(i# + j#)
MsgBox "The integer sum of 100.55 and 100.22 is: " & k%
'(4) Reassigns i# to 50.35 and recalculates k%, then displays the result
'(note rounding).
i# = 50.35
k% = CInt(i# + j#)
MsgBox "The integer sum of 50.35 and 100.22 is: " & k%
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CLng (on page 293) (function); CSng (on
page 306) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Integer (on page 479) (data type).
CancelButton (statement)
De Defines a Cancel button that appears within a dialog box template.
scrip
tion
Com This statement can only appear within a dialog box template (i.e., between the Begin Dialog
ments 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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 287
box does not contain a CancelButton statement. The CancelButton statement requires the
following parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Identi Optional parameter specifying the name by which this control can be referenced by
fier statements in a dialog function (such as DlgFocus and DlgEnable ). If omitted, then
the word Cancel is used.
A dialog box must contain at least one OKButton, CancelButton, or PushButton statement; oth
erwise, the dialog box cannot be dismissed.
Exam This example creates a sample dialog box with OK and Cancel buttons.
ple Sub Main()
OKButton 12,40,40,14
CancelButton 60,40,40,14
End Dialog
rc% = Dialog(QuitDialog)
Case -1
Case 1
End Select
End Sub
See CheckBox (on page 281) (statement); ComboBox (on page 294) (statement); Dialog (on page
Also 336) (function); Dialog (on page 338) (statement); DropListBox (on page 371) (statement);
GroupBox (on page 457) (statement); ListBox (on page 504) (statement); OKButton (on page
551) (statement); OptionButton (on page 564) (statement); OptionGroup (on page 566)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 288
(statement); Picture (on page 570) (statement); PushButton (on page 584) (statement); Text
(on page 664) (statement); TextBox (on page 666) (statement); Begin (on page 269) Dialog
(on page 269) (statement), PictureButton (on page 572) (statement).
Clipboard$ (function)
Syntax Clipboard$[()]
Com If the Clipboard doesn't contain text or the Clipboard is empty, then a zero-length string is re
ments turned.
Example This example puts text on the Clipboard, displays it, clears the Clipboard, and displays the
Clipboard again.
Sub Main()
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
Clipboard.Clear
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
End Sub
See Also Clipboard$ (on page 288) (statement); Clipboard.GetText (on page 292) (method); Clip
board.SetText (on page 292) (method).
Clipboard $ (statement)
Example This example puts text on the Clipboard, displays it, clears the Clipboard, and displays the
Clipboard again.
Sub Main()
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 289
Clipboard.Clear
MsgBox "The text in the Clipboard is now:" & crlf & Clipboard$
End Sub
See Also Clipboard$ (on page 288) (function); Clipboard.GetText (on page 292) (method); Clip
board.SetText (on page 292) (method).
Clipboard.Clear (method)
Syntax Clipboard.Clear
Example This example puts text on the Clipboard, displays it, clears the Clipboard, and displays the
Clipboard again.
Sub Main()
MsgBox "The text in the Clipboard before clearing:" & crlf & Clipboard$
Clipboard.Clear
MsgBox "The text in the Clipboard after clearing:" & crlf & Clipboard$
End Sub
CreateObject (function)
De Creates an OLE automation object and returns a reference to that object.
scrip
tion
Com The class$ parameter specifies the application used to create the object and the type of object
ments being created. It uses the following syntax: "application.class", where application is the applica
tion used to create the object and class is the type of the object to create. At runtime, Create
Object looks for the given application and runs that application if found. Once the object is cre
ated, its properties and methods can be accessed using the dot syntax (e.g., object.property =
value). There may be a slight delay when an automation server is loaded (this depends on the
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 290
speed with which a server can be loaded from disk). This delay is reduced if an instance of the
automation server is already loaded.
Exam This first example instantiates Microsoft Excel. It then uses the resulting object to make Excel
ples visible and then close Excel.
Sub Main()
Trap1:
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()
On Error Goto 0
End
NO_VISIO:
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 291
See GetObject (on page 453) (function); Object (on page 546) (data type).
Also
Clipboard.GetFormat (method)
De Returns TRUE if data of the specified format is available in the Clipboard; returns FALSE other
scrip wise.
tion
Com This method is used to determine whether the data in the Clipboard is of a particular format.
ments The format parameter is an Integer representing the format to be queried:
Format Description
1 Text
2 Bitmap
3 Metafile
9 Color palette
Exam This example checks to see whether there is any text on the Clipboard, if so, it searches the text
ple for a string matching what the user entered.
Sub Main()
If Clipboard.GetFormat(1) Then
If Instr(Clipboard.GetText(1),r) = 0 Then
MsgBox """" & r & """" & " was not found in the clipboard."
Else
MsgBox """" & r & """" & " is definitely in the clipboard."
End If
Else
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 292
See Clipboard$ (on page 288) (function); Clipboard$ (on page 288) (statement).
Also
Exam This example checks to see whether there is any text on the Clipboard, if so, it searches the
ple text for a string matching what the user entered.
Sub Main()
If Clipboard.GetFormat(1) Then
If Instr(Clipboard.GetText(1),r) = 0 Then
MsgBox """" & r & """" & " was not found in the clipboard."
Else
MsgBox """" & r & """" & " is definitely in the clipboard."
End If
Else
End If
End Sub
See Al Clipboard$ (on page 288) (statement); Clipboard$ (on page 288) (function); Clipboard.Set
so Text (on page 292) (method).
Com The data$ parameter specifies the text to be copied to the Clipboard. The format parameter,
ments if specified, must be 1 .
Example This example gets the contents of the Clipboard and uppercases it.
Sub Main()
Clipboard.SetText UCase(Clipboard.GetText(1)),1
End Sub
See Also Clipboard$ (on page 288) (statement); Clipboard.GetText (on page 292) (method); Clip
board$ (on page 288) (function).
CLng (function)
Com This function accepts any expression convertible to a Long , including strings. A runtime error is
ments generated if expression is Null . Empty is treated as 0 . The passed expression must be within
the following range:
A runtime error results if the passed expression is not within the above range. When passed a
numeric expression, this function has the same effect as assigning the numeric expression to
a Long . Note that long variables are rounded before conversion. When used with variants, this
function guarantees that the expression is converted to a Long variant ( VarType 3 ).
Exam This example displays the results for various conversions of i and j (note rounding).
ple Sub Main()
I% = 100
j& = 123.666
MsgBox "The result of i * j is: " & CLng(i% * j&) 'Displays 12367.
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 294
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CInt (on page 285) (function); CSng (on
page 306) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Long (on page 511) (data type).
Close (statement)
Example This example opens four files and closes them in various combina
tions.
Sub Main()
MsgBox "The next available file number is: " & FreeFile()
MsgBox "The next available file number is: " & FreeFile()
End Sub
See Also Open (on page 554) (statement); Reset (on page 603) (statement);
End (on page 399) (statement).
ComboBox (statement)
De This statement defines a combo box within a dialog box template.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 295
Com When the dialog box is invoked, the combo box will be filled with the elements from the speci
ments fied 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 follow
ing parameters:
Parame Description
ter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Array Single-dimensioned array used to initialize the elements of the combo box. If this ar
Variable ray has no dimensions, then the combo box will be initialized with no elements. A run
time error results if the specified array contains more than one dimension. ArrayVari
able can specify an array of any fundamental data type (structures are not allowed).
Null and Empty values are treated as zero-length strings.
Identifi Name by which this control can be referenced by statements in a dialog function
er (such as DlgFocus and DlgEnable ). This parameter also creates a string variable
whose value corresponds to the content of the edit field of the combo box. This vari
able can be accessed using the syntax: DialogVariable.Identifier
When the dialog box is invoked, the elements from ArrayVariable are placed into the combo box.
The .Identifier variable defines the initial content of the edit field of the combo box. When the di
alog box is dismissed, the .Identifier variable is updated to contain the current value of the edit
field.
Exam This example creates a dialog box that allows the user to select a day of the week.
ple Sub Main()
Dim days$(6)
days$(0) = "Monday"
days$(1) = "Tuesday"
days$(2) = "Wednesday"
days$(3) = "Thursday"
days$(4) = "Friday"
days$(5) = "Saturday"
days$(6) = "Sunday"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 296
OKButton 76,8,40,14,.OK
Text 8,10,39,8,"&Weekdays:"
ComboBox 8,20,60,72,days$,.Days
End Dialog
r% = Dialog(DaysDialog)
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); Dialog (on
Also page 336) (function); Dialog (on page 338) (statement); DropListBox (on page 371) (state
ment); GroupBox (on page 457) (statement); ListBox (on page 504) (statement); OKButton
(on page 551) (statement); OptionButton (on page 564) (statement); OptionGroup (on page
566) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
Syn Command[$][()]
tax
De Returns the argument from the command line used to start the application.
scrip
tion
Exam This example checks to see if any command line parameters were used. If parameters were
ple used they are displayed and a check is made to see if the user used the "/s" switch.
Sub Main()
cmd$ = Command
Else
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 297
End If
MsgBox "The command line startup options were: " & cmd$
Else
End If
End Sub
This operator behaves differently depending on the types of the expressions, as shown in the
following table:
String Comparisons If the two expressions are strings, then the operator performs a text com
parison between the two string expressions, returning True if expression1 is less than expres
sion2. The text comparison is case-sensitive if Option Compare is Binary; otherwise, the com
parison 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()
date1 = Now
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:
If 5 < 2 Then
Else
End If
Else
End If
End Sub
See Operator Precedence (on page 560) (topic); Is (on page 482) (operator); Like (on page 499)
Also (operator); Option Compare (on page 562) (statement).
Const (statement)
Com The name is only valid within the current Basic Control Engine script. Constant names must fol
ments low these rules: 1. Must begin with a letter. 2. May contain only letters, digits, and the under
score character. 3. Must not exceed 80 characters in length. 4. Cannot be a reserved word.
Constant names are not case-sensitive.
The expression must be assembled from literals or other constants. Calls to functions are not
allowed except calls to the Chr$ function, as shown below:
Constants can be given an explicit type by declaring the name with a type-declaration character,
as shown below:
If an explicit type is not given, then the Basic Control Engine script will choose the most impre
cise type that completely represents the data, as shown below:
Constants defined within a Sub or Function are local to that subroutine or function. Constants
defined outside of all subroutines and function can be used anywhere within that script. The fol
lowing example demonstrates the scoping of constants:
Sub Test1
End Sub
Sub Test2
End Sub
Exam This example displays the declared constants in a dialog box (crlf produces a new line in the di
ple alog box).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 301
Sub Main()
End Sub
See DefType (on page 333) (statement); Let (on page 498) (statement); = (statement); Constants
Also (on page 301) (topic).
Constants (topic)
Constants are variables that cannot change value during script execution. The following constants are
predefined by the Basic Control Engine:
Null Null Variant of type 1, indicating that the variant contains no data.
ebCFText 1 Text.
ebCFBitmap 2 Bitmap
ebCFMetafile 3 Metafile.
ebCFPalette 9 Palette
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.
ebDirectory 16 Subdirectory
ebIMEOn 1 IME on
ebApplication 0 The current application is suspended until the dialog box is closed.
Modal
ebSystemModal 4096 All applications are suspended until the dialog box is closed.
ebNormalFocus 1 Application is displayed at the default position and has the focus.
ebNormalNoFocus 4 Application is displayed at the default position and does not have
the focus.
ebArray 8192 Added to any of the other types to indicate an array of that type.
ebNullString 0 Special string value used to pass null pointers to external rou
tines.
Constant Value
Empty Empty
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 306
False False
Null Null
True True
You can define your own constants using the Const statement. Preprocessor constants are defined us
ing #Const.
Cos (function)
Example This example assigns the cosine of pi/4 radians (45 degrees) to C# and displays its val
ue.
Sub Main()
c# = Cos(3.14159 / 4)
End Sub
See Also Tan (on page 664) (function); Sin (on page 631) (function); Atn (on page 258) (func
tion).
CSng (function)
Com This function accepts any expression convertible to a Single , including strings. A runtime er
ments ror is generated if expression is Null . Empty is treated as 0.0 . A runtime error results if the
passed expression is not within the valid range for Single . When passed a numeric expression,
this function has the same effect as assigning the numeric expression to a Single . When used
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 307
with variants, this function guarantees that the expression is converted to a Single variant (
VarType 4 ).
s$ = "100"
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CInt (on page 285) (function); CLng (on
page 293) (function); CStr (on page 307) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); Single (on page 631) (data type).
CStr (function)
Com Unlike Str$ or Str , the string returned by CStr will not contain a leading space if the expres
ments sion is positive. Further, the CStr function correctly recognizes thousands and decimal separa
tors for your locale. Different data types are converted to String in accordance with the follow
ing rules:
Any numeric type A string containing the number without the leading space for positive values.
s# = 123.456
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 308
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CInt (on page 285) (function); CLng (on
page 293) (function); CSng (on page 306) (function); CVar (on page 309) (function); CVErr
(on page 310) (function); String (on page 654) (data type); Str, Str$ (on page 650) (func
tions).
De Returns the current directory on the specified drive. If no drive$ is specified or drive$ is ze
scrip ro-length, then the current directory on the current drive is returned.
tion
Com CurDir$ returns a String , whereas CurDir returns a String variant. The script generates a run
ments time error if drive$ is invalid.
Exam This example saves the current directory, changes to the next higher directory, and displays the
ple change; then restores the original directory and displays the change. Note: The dot designators
will not work with all platforms.
Sub Main()
save$ = CurDir
ChDir ("..")
MsgBox "Old directory: " & save$ & crlf & "New directory: " & CurDir
ChDir (save$)
End Sub
See ChDir (on page 280) (statement); ChDrive (on page 280) (statement); Dir, Dir$ (on page
Also 339) (functions); MkDir (on page 521) (statement); RmDir (on page 606) (statement).
Syn Currency
tax
De A data type used to declare variables capable of holding fixed-point numbers with 15 digits to
scrip the left of the decimal point and 4 digits to the right.
tion
Com Currency variables are used to hold numbers within the following range:
ments –922,337,203,685,477.5808 <= currency <= 922,337,203,685,477.5807
Due to their accuracy, Currency variables are useful within calculations involving money. The
type-declaration character for Currency is @ . 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 Date (on page 313) (data type); Double (on page 370) (data type); Integer (data type); Long
Also (on page 511) (data type); Object (on page 546) (data type); Single (on page 631) (data
type); String (on page 654) (data type); Variant (on page 684) (data type); Boolean (on page
272) (data type); DefType (on page 333) (statement); CCur (on page 278) (function).
CVar (function)
Com This function is used to convert an expression into a variant. Use of this function is not neces
ments sary (except for code documentation purposes) because assignment to variant variables auto
matically performs the necessary conversion:
Sub Main()
Dim v As Variant
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 310
Dim s As String
Dim a As Variant
MsgBox msg1
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CInt (on page 285) (function); CLng (on
page 293) (function); CSng (on page 306) (function); CStr (on page 307) (function); CVErr
(on page 310) (function); Variant (on page 684) (data type).
CVErr (function)
Com This function is used to convert an expression into a user-defined error number. A runtime er
ments ror is generated under the following conditions: If expression is Null . If expression is a number
outside the legal range for errors, which is as follows:
Exam This example simulates a user-defined error and displays the error number.
ple Sub Main()
End Sub
See CCur (on page 278) (function); CBool (on page 277) (function); CDate, CVDate (on page
Also 279) (functions); CDbl (on page 277) (function); CInt (on page 285) (function); CLng (on
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 311
page 293) (function); CSng (on page 306) (function); CStr (on page 307) (function); CVar
(on page 309) (function), IsError (on page 485) (function).
Comments (topic)
Comments can be added to Basic Control Engine script code in the following manner: All text between a
single quotation mark and the end of the line is ignored:
The REM statement causes the compiler to ignore the entire line:
The Basic Control Engine supports C-style multiline comment blocks /*...*/, as shown in the following
example:
D
D
DateAdd (function)
DateDiff (function)
DatePart (function)
DateSerial (function)
DateValue (function)
Day (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 312
DDB (function)
DDEExecute (statement)
DDEInitiate (function)
DDEPoke (statement)
DDESend (statement)
DDETerminate (statement)
DDETerminateAll (statement)
DDETimeout (statement)
Declare (statement)
DefType (statement)
DeleteSetting (statement)
Dialog (function)
Dialog (statement)
Dim (statement)
DiskDrives (statement)
DiskFree (function)
DlgCaption (function)
DlgCaption (statement)
DlgControlId (function)
DlgEnable (function)
DlgEnable (statement)
DlgFocus (function)
DlgFocus (statement)
DlgListBoxArray (function)
DlgListBoxArray (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 313
DlgProc (function)
DlgSetPicture (statement)
DlgText (statement)
DlgText$ (function)
DlgValue (function)
DlgValue (statement)
DlgVisible (function)
DlgVisible (statement)
Do...Loop (statement)
DoEvents (function)
DoEvents (statement)
DropListBox (statement)
Syn Date
tax
Com Date variables are used to hold dates within the following range:
ments January 1, 100 00:00:00 <= date <= December 31, 9999 23:59:59
Internally, dates are stored as 8-byte IEEE double values. The integer part holds the number of
days since December 31, 1899, and the fractional part holds the number of seconds as a frac
tion of the day. For example, the number 32874.5 represents January 1, 1990 at 12:00:00. When
appearing within a structure, dates require 8 bytes of storage. Similarly, when used with binary
or random files, 8 bytes of storage are required. There is no type-declaration character for Date
.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 314
Date variables that haven't been assigned are given an initial value of 0 (i.e., December 31,
1899).
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 Currency (on page 308) (data type); Double (on page 370) (data type); Integer (on page
Also 479) (data type); Long (on page 511) (data type); Object (on page 546) (data type); Single
(on page 631) (data type); String (on page 654) (data type); Variant (on page 684) (data
type); Boolean (on page 272) (data type); DefType (on page 333) (statement); CDate, CVDate
(on page 279) (functions).
Com The Date$ function returns the date using the short date format. The Date function returns the
ments date as a Date variant. Use the Date/Date$ statements to set the system date. The date is re
turned using the current short date format (defined by the operating system).
The Date$ function does not properly support international formats. Use the Date function in
stead.
Exam This example saves the current date to TheDate$, then changes the date and displays the re
ple sult. It then changes the date back to the saved date and displays the restored date.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 315
' One set of International Date Formats which shows this is:
' Short Date Format: dd.M.yy (ex: 02.01.97 for 2 January 1997)
Sub Main()
TheDate$ = Date
' Set the date to one that may confuse the library functions
Date = TheDate$
End Sub
See CDate, CVDate (on page 279) (functions); Time, Time$ (on page 668) (functions); Date, Date
Also $ (on page 315) (statements); Now (on page 541) (function); Format, Format$ (on page
438) (functions); DateSerial (on page 321) (function); DateValue (on page 322) (function).
Com The Date$ statement requires a string variable using one of the following formats: MM-DD-
ments YYYY MM-DD-YY MM/DD/YYYY MM/DD/YY, 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 numer
ic 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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 316
component, it is accepted, but the time is not changed. An error occurs if newdate cannot be in
terpreted as a valid date.
Exam This example saves the current date to Cdate$, then changes the date and displays the result. It
ple then changes the date back to the saved date and displays the result.
Sub Main()
TheDate$ = Date
Date = "01/01/95"
MsgBox "Saved date is: " & TheDate$ & crlf & "Changed date is: " & Date
Date = TheDate$
End Sub
See Date, Date$ (on page 314) (functions); Time, Time$ (on page 668) (statements).
Also
Notes If you do not have permission to change the date, runtime error 70 will be generated.
DateAdd (function)
De Returns a Date variant representing the sum of date and a specified number (increment) of time
scrip intervals (interval$).
tion
Com This function adds a specified number (increment) of time intervals (interval$) to the specified
ments date (date). The following table describes the parameters to the DateAdd function:
Para Description
me
ter
Inter String expression indicating the time interval used in the addition.
val$
Incre Integer indicating the number of time intervals you wish to add. Positive values result in
ment dates in the future; negative values result in dates in the past.
The interval$ parameter specifies what unit of time is to be added to the given date. It can be
any of the following:
Time Intervale
"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 equiv
alent (" 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 ". A runtime error is generated if you try to subtract a time interval that
is larger than the time value of the date.
Exam This example gets today's date using the Date$ function; adds three years, two months, one
ple week, and two days to it; and then displays the result in a dialog box.
Sub Main()
Dim sdate$
sdate$ = Date$
NewDate# = DateAdd("yyyy",4,sdate$)
NewDate# = DateAdd("m",3,NewDate#)
NewDate# = DateAdd("ww",2,NewDate#)
NewDate# = DateAdd("d",1,NewDate#)
s$ = "Four years, three months, two weeks, and one day from now will be: "
MsgBox s$
End Sub
DateDiff (function)
De Returns a Date variant representing the number of given time intervals between date1 and
scrip date2.
tion
Para Description
meter
Inter String expression indicating the specific time interval you wish to find the difference
val$ between.
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 ".
The following table lists the valid time interval strings and the meanings of each. The Format$
function uses the same expressions.
Time Interval
"yyyy" Year
"d" Day
"m" Month
"q" Quarter
"ww" Week
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 319
"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 DateDiff function will return a negative date/time value if date1
is a date later in time than date2.
Exam This example gets today's date and adds ten days to it. It then calculates the difference be
ple tween the two dates in days and weeks and displays the result.
Sub Main()
DifDays# = DateDiff("d",today$,NextWeek)
DifWeek# = DateDiff("w",today$,NextWeek)
s$ = "The difference between " & today$ & " and " & NextWeek
s$ = s$ & " is: " & DifDays# & " days or " & DifWeek# & " weeks"
MsgBox s$
End Sub
DatePart (function)
Com The DatePart function decomposes the specified date and returns a given date/time element.
ments The following table describes the parameters:
Para Description
meter
Inter String expression indicating the specific time interval you wish to find the difference
val$ between.
Date Any expression convertible to a Date. An example of a valid date/time string would be
" January 1, 1995" .
The following table lists the valid time interval strings and the meanings of each. The Format$
function uses the same expressions.
Time Interval
"yyyy" Year
"d" Day
"m" Month
"q" Quarter
"ww" Week
"h" Hour
"n" Minute
"s" Second
"w" Weekday
The weekday expression starts with Sunday as 1 and ends with Saturday as 7.
Sub Main()
today$ = Date$
qt = DatePart("q",today$)
yr = DatePart("yyyy",today$)
mo = DatePart("m",today$)
wk = DatePart("ww",today$)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 321
da = DatePart("d",today$)
MsgBox s$
End Sub
See Day (on page 322) (function); Minute (on page 519) (function); Second (on page 617)
Also (function); Month (on page 522) (function); Year (on page 710) (function); Hour (on page
461) (function); Weekday (on page 692) (function), Format (on page 438) (function).
DateSerial (function)
Parameter Description
Exam This example converts a date to a real number representing the serial date in days since De
ple cember 30, 1899 (which is day 0).
Sub Main()
tdate# = DateSerial(1993,08,22)
MsgBox "The DateSerial value for August 22, 1993, is: " & tdate#
End Sub
See Al DateValue (on page 322) (function); TimeSerial (on page 670) (function); TimeValue (on
so page 670) (function); CDate, CVDate (on page 279) (functions).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 322
DateValue (function)
Description Returns a Date variant representing the date contained in the specified string argu
ment.
Example This example returns the day of the month for today's date.
Sub Main()
Tdate$ = Date$
tday$ = DateValue(tdate$)
MsgBox "The date value of " & tdate$ & " is: " & tday$
End Sub
See Also TimeSerial (on page 670) (function); TimeValue (on page 670) (function); DateSerial
(on page 321) (function).
Platform(s) All.
Day (function)
Com The value returned is an Integer between 0 and 31 inclusive. The date parameter is any ex
ments pression that converts to a Date .
Exam This example gets the current date and then displays it.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
CurDate = Now()
MsgBox "Today is day " & Day(CurDate) & " of the month." & crlf & "Tomorrow is day " & Day(CurDate + 1) &
"."
End Sub
See Minute (on page 519) (function); Second (on page 617) (function); Month (on page 522)
Also (function); Year (on page 710) (function); Hour (on page 461) (function); Weekday (on page
692) (function); DatePart (on page 319) (function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 323
DDB (function)
De Calculates the depreciation of an asset for a specified Period of time using the double-declining
scrip balance method.
tion
Com The double-declining balance method calculates the depreciation of an asset at an accelerat
ments ed 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:
Parame Description
ter
Salvage Double representing the estimated value of the asset at the end of its predicted use
ful life
Life Double representing the predicted length of the asset's useful life
Period Double representing the period for which you wish to calculate the depreciation
Life and Period must be expressed using the same units. For example, if Life is expressed in
months, then Period must also be expressed in months.
Exam This example calculates the depreciation for capital equipment that cost $10,000, has a service
ple life of ten years, and is worth $2,000 as scrap. The dialog box displays the depreciation for each
of the first four years.
Sub Main()
For yy = 1 To 4
CurDep# = DDB(10000.0,2000.0,10,yy)
s$ = s$ & "Year " & yy & " : " & CurDep# & crlf
Next yy
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 324
MsgBox s$
End Sub
See Sln (on page 632) (function); SYD (on page 658) (function).
Also
DDEExecute (statement)
Parame Description
ter
Channel Integer containing the DDE channel number returned from DDEInitiate. An error will re
sult if channel is invalid.
Com String containing the command to be executed. The format of command$ depends
mand$ on the receiving application.
If the receiving application does not execute the instructions, a runtime error is generated.
Exam This example sets and retrieves a cell in an Excel spreadsheet. The command strings being
ple created contain Microsoft Excel macro commands and may be concatenated and sent as one
string to speed things up.
Sub Main()
Dim cmd,q,ch%
ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 325
DDETerminate ch%
Msgbox "Finished..."
End Sub
See DDEInitiate (on page 325) (function); DDEPoke (on page 326) (statement); DDERequest,
Also DDERequest$ (on page 328) (functions); DDESend (on page 329) (function); DDETerminate
(on page 330) (statement); DDETerminateAll (on page 331) (statement); DDETimeout (on
page 332) (statement).
DDEInitiate (function)
De Initializes a DDE link to another application and returns a unique number subsequently used to
scrip refer to the open DDE channel.
tion
Para Description
meter
Ap String containing the name of the application (the server) with which a DDE conversa
plica tion will be established.
tion$
Top String containing the name of the topic for the conversation. The possible values for
ic$ this parameter are described in the documentation for the server application.
This function returns 0 if the link cannot be established. This will occur under any of the follow
ing circumstances:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 326
Dim cmd,q,ch%
ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
DDETerminate ch%
Msgbox "Finished..."
End Sub
See DDEExecute (on page 324) (statement); DDEPoke (on page 326) (statement); DDERequest,
Also DDERequest$ (on page 328) (functions); DDESend (on page 329) (function); DDETerminate
(on page 330) (statement); DDETerminateAll (on page 331) (statement); DDETimeout (on
page 332) (statement).
DDEPoke (statement)
De Sets the value of a data item in the receiving application associated with an open DDE link.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 327
Parame Description
ter
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.
Dim cmd,q,ch%
Ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
DDETerminate ch%
Msgbox "Finished..."
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDERequest,
Also DDERequest$ (on page 328) (functions); DDESend (on page 329) (function); DDETerminate
(on page 330) (statement); DDETerminateAll (on page 331) (statement); DDETimeout (on
page 332) (statement).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 328
De Returns the value of the given data item in the receiving application associated with the open
scrip DDE channel.
tion
Com DDERequest$ returns a String , whereas DDERequest returns a String variant. The
ments DDERequest/DDERequest$ functions take the following parameters:
Parame Description
ter
channel Integer containing the DDE channel number returned from DDEInitiate. An error will
result if channel is invalid.
DataItem String containing the name of the data item to request. The format for this parameter
$ depends on the server.
Dim cmd,q,ch%
ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
DDETerminate ch%
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 329
Msgbox "Finished..."
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDEPoke (on
Also page 326) (statement); DDESend (on page 329) (function); DDETerminate (on page 330)
(statement); DDETerminateAll (on page 331) (statement); DDETimeout (on page 332) (state
ment).
DDESend (statement)
De Initiates a DDE conversation with the server as specified by application$ and topic$ and sends
scrip that server a new value for the specified item.
tion
Parame Description
ter
applica String containing the name of the application (the server) with which a DDE conver
tion$ sation 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.
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.
ch% = DDEInitiate(application$,topic$)
DDEPoke ch%,item,data
DDETerminate ch%
Exam This example sets the content of the first cell in an Excel spreadsheet.
ple
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 330
Sub Main()
Dim cmd,ch%
Exit Sub
ExcelError:
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDEPoke (on
Also page 326) (statement); DDERequest (on page 328), DDERequest$ (on page 328) (func
tions); DDETerminate (on page 330) (statement); DDETerminateAll (on page 331) (state
ment); DDETimeout (on page 332) (statement).
DDETerminate (statement)
Com The channel parameter is an Integer containing the DDE channel number returned from
ments DDEInitiate . An error will result if channel is invalid. All open DDE channels are automatically
terminated when the script ends.
Dim cmd,q,ch%
Ch% = DDEInitiate("Excel","Sheet1")
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 331
DDEExecute ch%,cmd
DDETerminate ch%
Msgbox "Finished..."
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDEPoke (on
Also page 326) (statement); DDERequest (on page 328), DDERequest$ (on page 328) (func
tions); DDESend (on page 329) (function); DDETerminateAll (on page 331) (statement); DDE
Timeout (on page 332) (statement).
DDETerminateAll (statement)
Syn DDETerminateAll
tax
Com All open DDE channels are automatically terminated when the script ends.
ments
Dim cmd,q,ch%
ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
DDETerminateAll
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDEPoke (on
Also page 326) (statement); DDERequest (on page 328), DDERequest$ (on page 328) (func
tions); DDESend (on page 329) (function); DDETerminate (on page 330) (statement); DDE
Timeout (on page 332) (statement).
DDETimeout (statement)
De Sets the number of milliseconds that must elapse before any DDE command times out.
scrip
tion
Com The milliseconds parameter is a Long and must be within the following range: 0 <= millisec
ments onds <= 2,147,483,647 The default is 10,000 (10 seconds).
Exam This example sets and retrieves a cell in an Excel spreadsheet. The timeout has been set to wait
ple 2 seconds for Excel to respond before timing out.
Sub Main()
Dim cmd,q,ch%
ch% = DDEInitiate("Excel","Sheet1")
DDEExecute ch%,cmd
DDETerminate ch%
End Sub
See DDEExecute (on page 324) (statement); DDEInitiate (on page 325) (function); DDEPoke (on
Also page 326) (statement); DDERequest (on page 328), DDERequest$ (on page 328) (func
tions); DDESend (on page 329) (function); DDETerminate (on page 330) (statement); DDE
TerminateAll (on page 331) (statement).
Declare (statement)
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):
DefType (statement)
Syn DefInt letterrange DefLng letterrange DefStr letterrange DefSng letterrange DefDbl letter
tax range DefCur letterrange DefObj letterrange DefVar letterrange DefBool letterrange Def
Date letterrange
Com The Def Type statement controls automatic type declaration of variables. Normally, if a vari
ments able is encountered that hasn't yet been declared with the Dim , Public , or Private statement
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 334
or does not appear with an explicit type-declaration character, then that variable is declared im
plicitly as a variant ( DefVar A–Z) . This can be changed using the Def Type statement to speci
fy 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]]... Def Type variable types are super
seded by an explicit type declaration¾using either a type-declaration character or the Dim ,
Public , or Private statement.
The Def Type statement only affects how the Basic Control Engine compiles scripts and has no
effect at runtime. The Def Type statement can only appear outside all Sub and Function dec
larations. The following table describes the data types referenced by the different variations of
the Def Type statement:
DefInt Integer
DefLng Long
DefStr String
DefSng Single
DefDbl Double
DefCur Currency
DefObj Object
DefVar Variant
DefBool Boolean
DefDate Date
DefSng s-u
DefDbl v-w
DefInt x-z
Sub Main()
a = 100.52
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 335
n = 100.52
s = 100.52
v = 100.52
x = 100.52
MsgBox msg1
End Sub
See Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Long (on page 511) (data type); Object (on page 546) (data type); Single (on
page 631) (data type); String (on page 654) (data type); Variant (on page 684) (data type);
Boolean (on page 272) (data type); Integer (on page 479) (data type).
DeleteSetting (statement)
Com You can control the behavior of DeleteSetting by omitting parameters. If you specify all three
ments parameters, then DeleteSetting deletes your specified setting. If you omit key, then DeleteSet-
ting deletes all of the keys from section. If both section and key are omitted, then DeleteSet-
ting removes that application’s entry from the system registry. The following table describes
the named parameters to the DeleteSetting statement:
Parame Description
ter
appname String expression indicating the name of the application whose setting will be delet
ed.
section String expression indicating the name of the section whose setting will be deleted.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 336
key String expression indicating the name of the setting to be deleted from the registry.
Exam
ple 'The following example adds two entries to the Windows registry
Sub Main()
End Sub
See SaveSetting (on page 613) (statement), GetSetting (on page 454) (function), GetAllSettings
Also (on page 450) (function)
Notes Under Win32, this statement operates on the system registry. All settings are saved under the
following entry in the system registry: HKEY_CURRENT_USER\Software\BasicScript Program
Settings\appname\section\key
Dialog (function)
De Displays the dialog box associated with DialogVariable, returning an Integer indicating which
scrip button was clicked.
tion
>0 A push button was clicked. The returned number represents which button was clicked
based on its order in the dialog box template (1 is the first push button, 2 is the second push
button, and so on).
Parame Description
ter
Dialog Name of a variable that has previously been dimensioned as a user dialog box. This
Variable is accomplished using the Dim statement:
All dialog variables are local to the Sub or Function in which they are defined. Pri
vate and public dialog variables are not allowed.
Default An Integer specifying which button is to act as the default button in the dialog box.
Button The value of DefaultButton can be any of the following:
-1 This value indicates that the OK button, if present, should be used as the default.
0 This value indicates that the Cancel button, if present, should be used as the de
fault.
>0 This value indicates that the Nth button should be used as the default. This
number is the index of a push button within the dialog box template.
Timeout An Integer specifying the number of milliseconds to display the dialog box before
automatically dismissing it. If TimeOut is not specified or is equal to 0 , then the di
alog box will be displayed until dismissed by the user. If a dialog box has been dis
missed due to a timeout, the Dialog function returns 0 .
PushButton 8,24,40,14,"Abort",.Abort
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 338
PushButton 56,24,40,14,"Retry",.Retry
PushButton 104,24,40,14,"Ignore",.Ignore
End Dialog
r% = Dialog(DiskError,3,0)
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 338) (statement); DlgProc (on page 352) (func
tion); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
564) (statement); OptionGroup (on page 566) (statement); Picture (on page 570) (state
ment); PushButton (on page 584) (statement); Text (on page 664) (statement); TextBox (on
page 666) (statement); Begin (on page 269) Dialog (on page 269) (statement), PictureBut
ton (on page 572) (statement).
Dialog (statement)
Description Same as the Dialog (on page 336) function, except that the Dialog statement does not
return a value.
Sub Main()
PushButton 8,24,40,14,"Abort",.Abort
PushButton 56,24,40,14,"Retry",.Retry
PushButton 104,24,40,14,"Ignore",.Ignore
End Dialog
Dialog DiskError,3,0
End Sub
See Also Dialog (on page 336) (function); DlgProc (on page 352) (function)
Dim (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 339
De Returns a String containing the first or next file matching filespec$. If filespec$ is specified, then
scrip the first file matching that filespec$ is returned. If filespec$ is not specified, then the next file
tion matching the initial filespec$ is returned.
Com Dir$ returns a String , whereas Dir returns a String variant. The Dir$ / Dir functions take the
ments following parameters:
Parameter Description
filespec$ 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 filespec$, then the current directory is used.
attributes Integer specifying attributes of files you want included in the list, as described
below. If 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 filespec$. If there is no
matching filespec$, then a zero-length string is returned.
Wildcards The filespec$ 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 pat
terns. The following table shows some examples:
SAMS.TXT
* (All files)
Attributes You can control which files are included in the search by specifying the optional attrib
utes 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 combi
nation of the following attributes (combined with the Or operator):
Exam This example uses Dir to fill a SelectBox with the first 10 directory entries.
ple Const crlf = Chr$(13) + Chr$(10)
Option Base 1
Sub Main()
Dim a$(10)
i% = 1
a(i%) = Dir("*.*")
i% = i% + 1
a(i%) = Dir
Wend
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 341
See ChDir (on page 280) (statement); ChDrive (on page 280) (statement); CurDir, CurDir$ (on
Also page 308) (functions); MkDir (on page 521) (statement); RmDir (on page 606) (statement);
FileList (on page 430) (statement).
DiskDrives (statement)
De Fills the specified String or Variant array with a list of valid drive letters.
scrip
tion
Com The array () parameter specifies either a zero- or a one-dimensioned array of strings or vari
ments ants. The array can be either dynamic or fixed. If array () is dynamic, then it will be redimen
sioned 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 Array
Dims 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.
Exam This example builds and displays an array containing the first three available disk drives.
ple Sub Main()
Dim drive$()
DiskDrives drive$
End Sub
See ChDrive (on page 280) (statement); DiskFree (on page 341) (function).
Also
DiskFree (function)
Descrip Returns a Long containing the free space (in bytes) available on the specified drive.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 342
Com If drive$ is zero-length or not specified, then the current drive is assumed. Only the first char
ments acter of the drive$ string is used.
Exam This example uses DiskFree to set the value of i and then displays the result in a message
ple box.
Sub Main()
s$ = "c"
i# = DiskFree(s$)
MsgBox "Free disk space on drive '" & s$ & "' is: " & i#
End Sub
See Al ChDrive (on page 280) (statement); DiskDrives (on page 341) (statement).
so
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)
Example
'This example displays a dialog box, adjusting the caption
'button.
If a = 1 Then
DlgCaption choose(DlgValue("OptionGroup1") + 1, _
"Blue","Green")
ElseIf a = 2 Then
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 343
DlgCaption choose(DlgValue("OptionGroup1") + 1, _
"Blue","Green")
End If
End Function
Sub Main()
OKButton 96,8,40,14
OptionGroup .OptionGroup1
OptionButton 12,12,56,8,"Blue",.OptionButton1
OptionButton 12,28,56,8,"Green",.OptionButton2
End Dialog
Dim d As UserDialog
Dialog d
End Sub
DlgControlId (function)
De Returns an Integer containing the index of the specified control as it appears in the dialog box
scrip template.
tion
Com The first control in the dialog box template is at index 0, the second is at index 1, and so on. The
ments ControlName$ parameter contains the name of the .Identifier parameter associated with that
control in the dialog box template.
The Basic Control Engine statements and functions that dynamically manipulate dialog box con
trols identify individual controls using either the .Identifier name of the control or the control's in
dex. Using the index to refer to a control is slightly faster but results in code that is more difficult
to maintain.
Exam This example uses DlgControlId to verify which control was triggered and branches the dynamic
ple dialog script accordingly.
If Action% = 2 Then
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 344
If DlgControlId(ControlName$) = 2 Then
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
End Function
Sub Main()
OKButton 132,8,40,14
CancelButton 132,28,40,14
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 349)
(function); DlgListBoxArray (on page 351) (statement); DlgSetPicture (on page 355) (state
ment); DlgText (on page 357) (statement); DlgText$ (on page 359) (function); DlgValue (on
page 361) (function); DlgValue (on page 362) (statement); DlgVisible (on page 364) (state
ment); DlgVisible (on page 363) (function).
DlgEnable (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 345
De Returns True if the specified control is enabled; returns False otherwise.
scrip
tion
Com Disabled controls are dimmed and cannot receive keyboard or mouse input. The ControlName$
ments parameter contains the name of the .Identifier parameter associated with a control in the dia
log 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). You cannot disable the control with the focus.
Exam This example checks the status of a checkbox at the end of the dialog procedure and notifies
ple the user accordingly.
If Action% = 2 Then
If DlgControlId(ControlName$) = 2 Then
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
MsgBox "You do not have the required disk space.",ebExclamation,"Insufficient Disk Space"
End If
End Function
Sub Main()
OKButton 132,8,40,14
CancelButton 132,28,40,14
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgControl (on page 343) (statement); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 349)
(function); DlgListBoxArray (on page 351) (statement); DlgSetPicture (on page 355) (state
ment); DlgText (on page 357) (statement); DlgText$ (on page 359) (function); DlgValue (on
page 361) (function); DlgValue (on page 362) (statement); DlgVisible (on page 364) (state
ment); DlgVisible (on page 363) (function).
DlgEnable (statement)
Com Disabled controls are dimmed and cannot receive keyboard or mouse input. The isOn parameter
ments is an Integer specifying the new state of the control. It can be any of the following values: 0 The
control is disabled. 1 The control is enabled. Omitted Toggles the control between enabled and
disabled.
Option buttons can be manipulated individually (by specifying an individual option button) or as
a group (by specifying the name of the option group).
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).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 347
Exam This example uses DlgEnable to turn on/off various dialog options.
ple Function DlgProc(ControlName$,Action%,SuppValue%) As Integer
If Action% = 2 Then
If DlgControlId(ControlName$) = 2 Then
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
For i = 3 to 5
DlgEnable i,DlgValue("CheckBox1")
Next i
End If
End Function
Sub Main()
OKButton 132,8,40,14
CancelButton 132,28,40,14
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgEnable (on page 346) (function); DlgFocus (on page 348) (function); DlgFocus (on page
Also 348) (statement); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page
351) (statement); DlgSetPicture (on page 355) (statement); DlgText (on page 357) (state
ment); DlgText$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on
page 362) (statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363)
(function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 348
DlgFocus (function)
Syn DlgFocus$[()]
tax
De Returns a String containing the name of the control with the focus.
scrip
tion
Com The name of the control is the .Identifier parameter associated with the control in the dialog box
ments template.
Exam This code fragment makes sure that the control being disabled does not currently have the fo
ple cus (otherwise, a runtime error would occur).
Sub Main()
End If
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (statement); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page
351) (statement); DlgSetPicture (on page 355) (statement); DlgText (on page 357) (state
ment); DlgText$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on
page 362) (statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363)
(function).
DlgFocus (statement)
Com A runtime error results if the specified control is hidden, disabled, or nonexistent. The Control
ments Name$ 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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 349
within the template. Alternatively, by specifying the ControlIndex parameter, a control can be re
ferred to using its index in the dialog box template (0 is the first control in the template, 1 is the
second, and so on).
Exam This code fragment makes sure the user enters a correct value. If not, the control returns focus
ple back to the TextBox for correction.
If IsNumeric(DlgText$("TextBox1")) Then
Else
DlgFocus "TextBox1"
DlgProc = 1
End If
End If
End Function
Sub Main()
Dim ListBox1$()
TextBox 12,20,88,12,.TextBox1
OKButton 12,44,40,14
CancelButton 60,44,40,14
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page
351) (statement); DlgSetPicture (on page 355) (statement); DlgText (on page 357) (state
ment); DlgText$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on
page 362) (statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363)
(function).
DlgListBoxArray (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 350
De Fills a list box, combo box, or drop list box with the elements of an array, returning an Integer
scrip containing the number of elements that were actually set into the control.
tion
Com The ControlName$ parameter contains the name of the .Identifier parameter associated with a
ments control in the dialog box template. A case-insensitive comparison is used to locate the specif
ic 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).
The ArrayVariable parameter specifies a single-dimensioned array used to initialize the ele
ments of the control. If this array has no dimensions, then the control will be initialized with no
elements. A runtime error results if the specified array contains more than one dimension. Ar
rayVariable can specify an array of any fundamental data type (structures are not allowed). Null
and Empty values are treated as zero-length strings.
If Action% = 1 Then
End If
End Function
Sub Main()
Dim ListBox1$()
OKButton 132,8,40,14
CancelButton 132,28,40,14
ListBox 8,12,112,72,ListBox1$,.Files
End Dialog
Dim d As UserDialog
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 351
Dialog d
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 351)
(statement); DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement);
DlgText$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on page
362) (statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363) (func
tion).
DlgListBoxArray (statement)
De Fills a list box, combo box, or drop list box with the elements of an array.
scrip
tion
Com The ControlName$ parameter contains the name of the .Identifier parameter associated with a
ments control in the dialog box template. A case-insensitive comparison is used to locate the specif
ic 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).
The ArrayVariable parameter specifies a single-dimensioned array used to initialize the ele
ments of the control. If this array has no dimensions, then the control will be initialized with no
elements. A runtime error results if the specified array contains more than one dimension. Ar
rayVariable can specify an array of any fundamental data type (structures are not allowed). Null
and Empty values are treated as zero-length strings.
If Action% = 1 Then
End If
End Function
Sub Main()
Dim ListBox1$()
OKButton 132,8,40,14
CancelButton 132,28,40,14
ListBox 8,12,112,72,ListBox1$,.Files
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 349)
(function); DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement); Dlg
Text$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on page 362)
(statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363) (function).
DlgProc (function)
De Describes the syntax, parameters, and return value for dialog functions.
scrip
tion
Com Dialog functions are called by a script during the processing of a custom dialog box. The name
ments of a dialog function (DlgProc) appears in the Begin Dialog statement as the .DlgProc parame
ter. Dialog functions require the following parameters:
Parameter Description
Control String containing the name of the control associated with Action.
Name$
Action Integer containing the action that called the dialog function.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 353
SuppValue Integer of extra information associated with Action. For some actions, this para
meter is not used.
When a script 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, the Basic
Control Engine 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 follow
ing table describes the different actions sent to dialog functions:
Ac Description
tion
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. Before Showing the Dialog Box After ac
tion 1 is sent, the Basic Control Engine performs additional processing before the dia
log box is shown. Specifically, it cycles though the dialog box controls checking for vis
ible picture or picture button controls. For each visible picture or picture button control,
the Basic Control Engine attempts to load the associated picture. In addition to check
ing picture or picture button controls, the Basic Control Engine will automatically hide
any control outside the confines of the visible portion of the dialog box. This prevents
the user from tabbing to controls that cannot be seen. However, it does not prevent you
from showing these controls with the DlgVisible statement in the dialog function.
• A button is clicked, such as OK, Cancel, or a push button. In this case, Control
Name$ contains the name of the button. SuppValue contains 1 if an OK button
was clicked and 2 if a Cancel button was clicked; SuppValue is undefined other
wise.
If the dialog function returns 0 in response to this action, then the dialog box will be
closed. Any other value causes the Basic Control Engine to continue dialog processing.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 354
• A check box's state has been modified. In this case, ControlName$ contains the
name of the check box, and SuppValue contains the new state of the check box (1
if on, 0 if off).
• An option button is selected. In this case, ControlName$ contains the name of
the option button that was clicked, and SuppValue contains the index of the op
tion button within the option button group (0-based).
• The current selection is changed in a list box, drop list box, or combo box. In this
case, ControlName$ contains the name of the list box, combo box, or drop list
box, and SuppValue contains the index of the new item (0 is the first item, 1 is the
second, and so on).
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, Control
Name$ 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 ig
nored with this action.
5 This action is sent continuously when the dialog box is idle. If the dialog function re
turns 1 in response to this action, then the idle action will continue to be sent. If the dia
log function returns 0, then the Basic Control Engine will not send any additional idle ac
tions. When the idle action is sent, ControlName$ contains a zero-length string, and Sup
pValue contains the number of times the idle action has been sent so far. Note: Not re
turning zero will cause your application to use all available CPU time and may adversely
affect your CIMPLICITY System.
6 This action is sent when the dialog box is moved. The ControlName$ parameter con
tains a zero-length string, and SuppValue is 0. The dialog function's return value is ig
nored 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 statements and functions. These
statements allow you to manipulate the dialog box controls dynamically.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 355
DlgEnable DlgControlId
The dialog function can optionally be declared to return a Variant . When returning a variable,
the Basic Control Engine 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.
Exam This dialog function enables/disables a group of option buttons when a check box is clicked.
ple Function SampleDlgProc(ControlName$,Action%,SuppValue%)
DlgEnable "PrintOptions",SuppValue%
End If
End Function
Sub Main()
OKButton 4,4,40,14
CancelButton 4,24,40,14
CheckBox 56,8,38,8,"Printing",.Printing
OptionGroup .PrintOptions
OptionButton 56,20,51,8,"Landscape",.Landscape
OptionButton 56,32,40,8,"Portrait",.Portrait
End Dialog
SampleDialog.Printing = 1
r% = Dialog(SampleDialog)
End Sub
DlgSetPicture (statement)
De Changes the content of the specified picture or picture button control.
scrip
tion
Para Description
meter
Con String containing the name of the .Identifier parameter associated with a control in the
trol dialog box template. A case-insensitive comparison is used to locate the specified con
Name$ trol within the template. Alternatively, by specifying the ControlIndex parameter, a con
trol 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).
Pic String containing the name of the picture. If PictureType is 0, then this parameter spec
ture ifies the name of the file containing the image. If PictureType is 10, then PictureName$
Name$ specifies the name of the image within the resource of the picture library. If Picture
Name$ is empty, then the current picture associated with the specified control will be
deleted. Thus, a technique for conserving memory and resources would involve setting
the picture to empty before hiding a picture control.
Pic Integer specifying the source for the image. The following sources are supported:
ture
Type
10 The image is contained in the picture library specified by the Begin Dialog state
ment. When this type is used, the PictureName$ parameter must be specified with
the Begin Dialog statement.
'from a library.
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 349)
(function); DlgListBoxArray (on page 351) (statement); DlgText (on page 357) (statement);
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 357
DlgText$ (on page 359) (function); DlgValue (on page 361) (function); DlgValue (on page
362) (statement); DlgVisible (on page 364) (statement); DlgVisible (on page 363) (func
tion), Picture (on page 570) (statement), PictureButton (on page 572) (statement).
Notes Picture controls can contain either bitmaps or WMFs (Windows metafiles). When extracting
images from a picture library, the Basic Control Engine assumes that the resource type for
metafiles is 256. Picture libraries are implemented as DLLs on the Windows and Win32 plat
forms.
DlgText (statement)
Com The effect of this statement depends on the type of the specified control:
ments
Drop Sets the current selection to the item matching NewText$. If an exact match cannot
list be found, the DlgText statement searches from the first item looking for an item that
box starts with NewText$. If no match is found, then the selection is removed.
but
ton
List Sets the current selection to the item matching NewText$. If an exact match cannot
box be found, the DlgText statement searches from the first item looking for an item that
starts with NewText$. If no match is found, then the selection is removed.
Com Sets the content of the edit field of the combo box to NewText$.
bo
box
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 specif
ic 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).
End If
End Sub
See DlgEnable (on page 344) (function); DlgEnable (on page 346) (statement); DlgFocus (on
Also page 348) (function); DlgFocus (on page 348) (statement); DlgListBoxArray (on page 349)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 359
(function); DlgListBoxArray (on page 351) (statement); DlgSetPicture (on page 355) (state
ment); DlgText (on page 357) (statement); DlgValue (on page 362) (statement); DlgValue (on
page 361) (function); DlgVisible (on page 364) (statement); DlgVisible (on page 363) (func
tion).
DlgText$ (function)
Com The text returned depends on the type of the specified control:
ments
Drop list Returns the currently selected item. A zero-length string is returned if no item is
box currently selected.
List box Returns the currently selected item. A zero-length string is returned if no item is
currently selected.
Combo box Returns the content of the edit field portion of the combo box.
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 specif
ic 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).
Exam This code fragment makes sure the user enters a correct value. If not, the control returns focus
ple back to the TextBox for correction.
If IsNumeric(DlgText$("TextBox1")) Then
Else
DlgFocus "TextBox1"
DlgProc = 1
End If
End If
End Function
Sub Main()
Dim ListBox1$()
TextBox 12,20,88,12,.TextBox1
OKButton 12,44,40,14
CancelButton 60,44,40,14
End Dialog
Dim d As UserDialog
Dialog d
End Sub
See DlgControlId (on page 343) (function); DlgEnable (on page 344) (function); DlgEnable (on
Also page 346) (statement); DlgFocus (on page 348) (function); DlgFocus (on page 348) (state
ment); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page 351) (statement);
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 361
DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement); DlgValue (on
page 361) (function); DlgValue (on page 362) (statement); DlgVisible (on page 364) (state
ment); DlgVisible (on page 363) (function).
DlgValue (function)
Com The value of any given control depends on its type, according to the following table:
ments
Option The index of the selected option button within the group (0 is the first option button,
group 1 is the second, and so on).
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 asso
ciated with a control in the dialog box template. Alternatively, by specifying the ControlIndex pa
rameter, a control can be referred to using its index in the dialog box template (0 is the first con
trol in the template, 1 is the second, and so on).
If DlgValue("MyCheckBox") = 1 Then
DlgValue "MyCheckBox",0
Else
DlgValue "MyCheckBox",1
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 362
End If
End Sub
See DlgControlId (on page 343) (function); DlgEnable (on page 344) (function); DlgEnable (on
Also page 346) (statement); DlgFocus (on page 348) (function); DlgFocus (on page 348) (state
ment); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page 351) (statement);
DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement); DlgText$ (on
page 359) (function); DlgValue (on page 362) (statement); DlgVisible (on page 364) (state
ment); DlgVisible (on page 363) (function).
DlgValue (statement)
Com The value of any given control is an Integer and depends on its type, according to the following
ments table:
Option The index of the new selected option button within the group (0 is the first option but
group ton, 1 is the second, and so on).
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. A case-insensitive comparison is used to locate the specif
ic control within the template. Alternatively, by specifying the ControlIndex parameter, a control
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 363
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 DlgValue("MyCheckBox") = 1 Then
DlgValue "MyCheckBox",0
Else
DlgValue "MyCheckBox",1
End If
End Sub
See DlgControlId (on page 343) (function); DlgEnable (on page 344) (function); DlgEnable (on
Also page 346) (statement); DlgFocus (on page 348) (function); DlgFocus (on page 348) (state
ment); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page 351) (statement);
DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement); DlgText$ (on
page 359) (function); DlgValue (on page 361) (function); DlgVisible (on page 364) (state
ment); DlgVisible (on page 363) (function).
DlgVisible (function)
De Returns True if the specified control is visible; returns False otherwise .
scrip
tion
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 con
trol 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). A runtime error is generated if DlgVisible is called with no user dialog is ac
tive.
ple
If DlgVisible(10) And DlgVisible(12) Then
End If
End Sub
See DlgControlId (on page 343) (function); DlgEnable (on page 344) (function); DlgEnable (on page
Also 346) (statement); DlgFocus (on page 348) (function); DlgFocus (on page 348) (statement);
DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page 351) (statement); Dlg
SetPicture (on page 355) (statement); DlgText (on page 357) (statement); DlgText$ (on page
359) (function); DlgValue (on page 362) (statement); DlgValue (on page 362) (statement);
DlgVisible (on page 363) (function).
DlgVisible (statement)
Com Hidden controls cannot be seen in the dialog box and cannot receive the focus using Tab. The
ments isOn parameter is an Integer specifying the new state of the control. It can be any of the follow
ing values:
Omitted Toggles the visibility of the control. Option buttons can be manipulated individually
(by specifying an individual option button) or as a group (by specifying the name of the option
group).
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 specif
ic 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).
Picture Caching When the dialog box is first created and before it is shown, the Basic Control
Engine 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 dia
log function and before the dialog box is shown, the Basic Control Engine will load the pictures
of all visible picture controls. Thus, it is possible for the dialog function to hide certain picture
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 365
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.
Exam This example creates a dialog box with two panels. The DlgVisible statement is used to show or
ple hide the controls of the different panels.
Sub EnableGroup(start%,finish%)
DlgVisible i,False
Next i
DlgVisible i,True
Next i
End Sub
Function DlgProc(ControlName$,Action%,SuppValue%)
If Action% = 1 Then
End If
End If
End If
End Function
Sub Main()
GroupBox 8,40,152,84,""
OptionGroup .WhichOptions
OKButton 116,7,44,14
CancelButton 116,24,44,14
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 366
End Dialog
Dialog OptionsDialog
End Sub
See DlgControlId (on page 343) (function); DlgEnable (on page 344) (function); DlgEnable (on
Also page 346) (statement); DlgFocus (on page 348) (function); DlgFocus (on page 348) (state
ment); DlgListBoxArray (on page 349) (function); DlgListBoxArray (on page 351) (statement);
DlgSetPicture (on page 355) (statement); DlgText (on page 357) (statement); DlgText$ (on
page 359) (function); DlgValue (on page 362) (statement); DlgValue (on page 361) (func
tion); DlgVisible (on page 364) (statement).
Do...Loop (statement)
De Repeats a block of Basic Control Engine statements while a condition is True or until a condi
scrip tion is True .
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 367
Com If the {While | Until} conditional clause is not specified, then the loop repeats the statements
ments forever (or until the script encounters an Exit Do statement). The condition parameter speci
fies any Boolean expression.
ples 'This first example uses the Do...While statement, which performs
'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
End Sub
Sub Main()
Dim a$(100)
i% = 0
a(i%) = Dir("*")
i% = i% + 1
a(i%) = Dir
Loop
End Sub
Sub Main()
'condition is True.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 368
Dim a$(100)
i% = 0
a(i%) = Dir("*")
i% = i% + 1
a(i%) = Dir
Loop
End Sub
Sub Main()
'This last example uses the Do...Until Loop, which performs 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
End Sub
See For...Next (on page 436) (statement); While ...WEnd (on page 693) (statement).
Also
Notes: Due to errors in program logic, you can inadvertently create infinite loops in your code. You can
break out of infinite loops using Ctrl+Break.
DoEvents (function)
Syn DoEvents[()]
tax
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 369
Com This statement yields control to the operating system, allowing other applications to process
ments mouse, keyboard, and other messages. If a SendKeys statement is active, this statement waits
until all the keys in the queue have been processed.
Exam The following routine explicitly yields to allow other applications to execute and refresh on a
ple regular basis.
Sub Main()
For i = 1 To 10000
r = DoEvents
Next i
Close #1
End Sub
DoEvents (statement)
Syn DoEvents
tax
Com This statement yields control to the operating system, allowing other applications to process
ments mouse, keyboard, and other messages. If a SendKeys statement is active, this statement waits
until all the keys in the queue have been processed.
Exam This first example shows a script that takes a long time and hogs the system. The following rou
ples tine explicitly yields to allow other applications to execute and refresh on a regular basis.
Sub Main()
For i = 1 To 10000
DoEvents
Next i
Close #1
End Sub
In this second example, the DoEvents statement is used to wait until the queue has been com
pletely flushed.
Sub Main()
End Sub
Syn Double
tax
De A data type used to declare variables capable of holding real numbers with 15–16 digits of pre
scrip cision.
tion
Com Double variables are used to hold numbers within the following ranges:
ments
Sign Range
-4.94066E-324
• Internally, doubles are 8-byte (64-bit) IEEE values. Thus, when appearing within a struc
ture, doubles require 8 bytes of storage. When used with binary or random files, 8 bytes
of storage are required.
• A 1-bit sign
• An 11-bit exponent
• A 53-bit significand (mantissa)
See Currency (on page 308) (data type); Date (on page 313) (data type); Integer (on page 479)
Also (data type); Long (on page 511) (data type); Object (on page 546) (data type); Single (on
page 631) (data type); String (on page 654) (data type); Variant (on page 684) (data type);
Boolean (on page 272) (data type); DefType (on page 333) (statement); CDbl (on page 277)
(function).
DropListBox (statement)
Com When the dialog box is invoked, the drop list box will be filled with the elements contained in Ar
ments rayVariable. Drop list boxes are similar to combo boxes, with the following exceptions:
• The list box portion of a drop list box is not opened by default. The user must open it by
clicking the down arrow.
• 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:
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 372
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Array Single-dimensioned array used to initialize the elements of the drop list box. If this array
Vari has no dimensions, then the drop list box will be initialized with no elements. A runtime
able error results if the specified array contains more than one dimension.
ArrayVariable can specify an array of any fundamental data type (structures are not al
lowed). Null and Empty values are treated as zero-length strings.
.Iden Name by which this control can be referenced by statements in a dialog function (such
tifier as DlgFocus and DlgEnable ). This parameter also creates an integer variable whose
value corresponds to the index of the drop list box's selection (0 is the first item, 1 is the
second, and so on). This variable can be accessed using the following syntax:
DialogVariable.Identifier
Exam This example allows the user to choose a field name from a drop list box.
ple Sub Main()
Dim FieldNames$(4)
FieldNames$(3) = "State"
FieldNames$(4) = "City"
DropListBox 48,6,64,80,FieldNames,.WhichField
OKButton 120,7,40,14
CancelButton 120,27,40,14
End Dialog
FindDialog.WhichField = 1
Dialog FindDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 373
ment); GroupBox (on page 457) (statement); ListBox (on page 504) (statement); OKButton
(on page 551) (statement); OptionButton (on page 564) (statement); OptionGroup (on page
566) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
E
E
ebAbort (constant)
ebAbortRetryIgnore (constant)
ebApplicationModal (constant)
ebArchive (constant)
ebBold (constant)
ebBoldItalic (constant)
ebBoolean (constant)
ebCancel (constant)
ebCritical (constant)
ebCurrency (constant)
ebDataObject (constant)
ebDate (constant)
ebDefaultButton1 (constant)
ebDefaultbutton2 (constant)
ebDefaultbutton3 (constant)
ebDirectory (constant)
ebDos (constant)
ebDouble (constant)
ebEmpty (constant)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 374
ebError (constant)
ebExclamation (constant)
ebHidden (constant)
ebIgnore (constant)
ebInformation (constant)
ebInteger (constant)
ebItalic (constant)
ebLong (constant)
ebNo (constant)
ebNone (constant)
ebNormal (constant)
ebNull (constant)
ebObject (constant)
ebOK (constant)
ebOKCancel (constant)
ebOKOnly (constant)
ebQuestion (constant)
ebReadOnly (constant)
ebRegular (constant)
ebRetry (constant)
ebRetryCancel (constant)
ebSingle (constant)
ebString (constant)
ebSystem (constant)
ebSystemModal (constant)
ebVariant (constant)
ebVolume (constant
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 375
ebYes (constant)
ebYesNo (constant)
ebYesNoCancel (constant)
Empty (constant)
End (statement)
EOF (function)
Eqv (operator)
Erase (statement)
Erl (function)
Err (statement)
Err.Clear (method)
Err.Description (property)
Err.HelpContext (property)
Err.HelpFile (property)
Err.LastDLLError (property)
Err.Number (property)
Err.Raise (method)
Err.Source (property)
Error (statement)
Exit Do (statement)
Exp (function)
ebAbort (constant)
Description Returned by the MsgBox function when the Abort button is chosen.
Example This example displays a dialog box with Abort, Retry, and Ignore but
tons.
Sub Main()
Again:
End
Goto Again
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (state
ment).
ebAbortRetryIgnore (constant)
Example This example displays a dialog box with Abort, Retry, and Ignore but
tons.
Sub Main()
Again:
End
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 377
Goto Again
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (state
ment).
ebApplicationModal (constant)
Example This example displays an application-modal dialog box (which is the de
fault).
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebArchive (constant)
Descrip Bit position of a file attribute indicating that a file hasn't been backed up.
tion
Example This example dimensions an array and fills it with filenames with the Archive bit set.
Sub Main()
Dim s$()
FileList s$,"*",ebArchive
Else
End If
End Sub
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebBold (constant)
Description Used with the Text and TextBox statement to specify a bold
font.
OKButton 96,110,40,14
End Dialog
Dim a As UserDialog
Dialog a
End Sub
See Also Text (on page 664) (statement), TextBox (on page 666)
(statement).
ebBoldItalic (constant)
Description Used with the Text and TextBox statement to specify a bold-italic
font.
OKButton 96,110,40,14
End Dialog
Dim a As UserDialog
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 379
Dialog a
End Sub
See Also Text (on page 664) (statement), TextBox (on page 666) (state
ment).
ebBoolean (constant)
MyVariant = True
MyVariant = 5.5
End If
End Sub
ebCancel (constant)
Description Returned by the MsgBox function when the Cancel button is cho
sen.
'Invoke MsgBox and check whether the Cancel button was pressed.
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 380
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (state
ment).
ebCritical (constant)
'Invoke MsgBox with Abort, Retry, and Ignore buttons and a Stop icon.
If rc% = 3 Then
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (state
ment).
ebCurrency (constant)
Sub Main()
Dim MyVariant
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page 684) (da
ta type).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 381
ebDataObject (constant)
Sub Main()
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page 684)
(data type).
ebDate (constant)
Else
End If
End Sub
ebDefaultButton1 (constant)
Example This example invokes MsgBox with the focus on the OK button by de
fault.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebDefaultButton2 (constant)
Example This example invokes MsgBox with the focus on the Cancel button by de
fault.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebDefaultButton3 (constant)
Example This example invokes MsgBox with the focus on the Ignore button by de
fault.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebDirectory (constant)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 383
Descrip Bit position of a file attribute indicating that a file is a directory entry.
tion
Example This example dimensions an array and fills it with directory names using the ebDirectory con
stant.
Sub Main()
Dim s$()
FileList s$,"c:\*",ebDirectory
If a% >= 0 Then
Else
End If
End Sub
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebDos (constant)
Description Used with the AppType or FileType functions to indicate a DOS applica
tion.
Sub Main()
s$ = OpenFilename$("Run","Programs:*.exe")
End If
End If
End Sub
ebDouble (constant)
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement); VarType (on
page 686) (function); Variant (on page 684) (data type).
ebEmpty (constant)
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page
684) (data type).
ebError (constant)
Div = a / b
End Function
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 385
res = Div(a,b)
res = CStr(res)
res = Error(Mid(res,7,Len(res)))
Else
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page
684) (data type).
ebExclamation (constant)
Example This example displays a dialog box with an OK button and an exclamation
icon.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebHidden (constant)
Example This example dimensions an array and fills it with filenames using the ebHidden attribute.
Sub Main()
Dim s$()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 386
FileList s$,"*",ebHidden
If ArrayDims(s$) = 0 Then
End
End If
If a% >= 0 Then
Else
End If
End Sub
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebIgnore (constant)
Description Returned by the MsgBox function when the Ignore button is chosen.
Example This example displays a critical error dialog box and sees what the user wants to
do.
Sub Main()
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement).
ebInformation (constant)
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebInteger (constant)
Example This example defines a function that returns True if a variant contains an Integer value (either
a 16-bit or 32-bit Integer).
IsInteger = True
Else
IsInteger = False
End If
End Function
Sub Main()
Dim i as Integer
i = 123
If IsInteger(i) then
End If
End Sub
See Al VarType (on page 686) (function); Variant (on page 684) (data type).
so
ebItalic (constant)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 388
Description Used with the Text and TextBox statement to specify an italic
font.
OKButton 96,110,40,14
End Dialog
Dim a As UserDialog
Dialog a
End Sub
See Also Text (on page 664) (statement), TextBox (on page 666) (state
ment).
ebLong (constant)
ebNo (constant)
Example This example asks a question and queries the user's response.
Sub Main()
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebNone (constant)
Com This value can be used with the Dir$ and FileList commands. These functions will return only
ments files with no attributes set when used with this constant. This constant is equal to 64.
Exam This example dimensions an array and fills it with filenames with no attributes set.
ple Sub Main()
Dim s$()
FileList s$,"*",ebNone
If ArrayDims(s$) = 0 Then
End
End If
If a% >= 0 Then
Else
End If
End Sub
See Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
Also 627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebNormal (constant)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 390
Com This value can be used with the Dir$ and FileList commands and will return files with the
ments Archive, Volume, ReadOnly, or no attributes set. It will not match files with Hidden, System, or Di
rectory attributes. This constant is equal to 0.
Exam This example dimensions an array and fills it with filenames with Normal attributes.
ple Sub Main()
Dim s$()
If ArrayDims(s$) = 0 Then
End
End If
If a% >= 0 Then
Else
End If
End Sub
See Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
Also 627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebNull (constant)
Dim MyVariant
MyVariant = Null
End If
End Sub
ebObject (constant)
Description Number representing the type of an Object variant (an OLE automation ob
ject).
Dim MyVariant
MsgBox MyVariant.Value
Else
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page 684) (data type).
ebOK (constant)
Example This example displays a dialog box that allows the user to can
cel.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 392
ebOKCancel (constant)
Example This example displays a dialog box that allows the user to can
cel.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebOKOnly (constant)
Example This example informs the user of what is going on (no options).
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement)
ebQuestion (constant)
Example This example displays a dialog box with OK and Cancel buttons and a question
icon.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 393
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (statement)
ebReadOnly (constant)
Example This example dimensions an array and fills it with filenames with ReadOnly attributes.
Sub Main()
Dim s$()
If ArrayDims(s$) = 0 Then
End
End If
If a% >= 0 Then
Else
End If
End Sub
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebRegular (constant)
Descrip Used with the Text and TextBox statement to specify an normal-styled font (i.e., neither
tion bold or italic).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 394
OKButton 96,110,40,14
End Dialog
Dim a As UserDialog
Dialog a
End Sub
See Also Text (on page 664) (statement), TextBox (on page 666) (statement)
ebRetry (constant)
Description Returned by the MsgBox function when the Retry button is cho
sen.
Sub Main()
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement)
ebRetryCancel (constant)
Example This example invokes a dialog box with Retry and Cancel but
tons.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebSingle (constant)
Example This example defines a function that returns True if the passed variant is a Real num
ber.
IsReal = True
Else
IsReal = False
End If
End Function
Sub Main()
Dim i as Integer
i = 123
If IsReal(i) then
End If
End Sub
See Also VarType (on page 686) (function); Variant (on page 684) (data type).
ebString (constant)
End If
End Sub
ebSystem (constant)
Descrip Bit position of a file attribute indicating that a file is a system file.
tion
Example This example dimensions an array and fills it with filenames with System attributes.
Sub Main()
Dim s$()
FileList s$,"*",ebSystem
If a% >= 0 Then
Else
End If
End Sub
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebSystemModal (constant)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 397
End Sub
See Also ebApplicationModal (on page 377) (constant); Constants (topic); MsgBox (on page 527)
(function); MsgBox (on page 530) (statement).
ebVariant (constant)
Comments Currently, it is not possible for variants to use this subtype. This constant is equal to
12.
See Also VarType (on page 686) (function); Variant (on page 684) (data type).
ebVolume (constant)
Descrip Bit position of a file attribute indicating that a file is the volume label.
tion
Example This example dimensions an array and fills it with filenames with Volume attributes.
Sub Main()
Dim s$()
Else
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 398
See Also Dir, Dir$ (on page 339) (functions); FileList (on page 430) (statement); SetAttr (on page
627) (statement); GetAttr (on page 451) (function); FileAttr (on page 424) (function).
ebYes (constant)
Description Returned by the MsgBox function when the Yes button is cho
sen.
Sub Main()
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebYesNo (constant)
Example This example displays a dialog box with Yes and No buttons.
Sub Main()
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530)
(statement).
ebYesNoCancel (constant)
Example This example displays a dialog box with Yes, No, and Cancel but
tons.
Sub Main()
End If
End Sub
See Also MsgBox (on page 527) (function); MsgBox (on page 530) (state
ment).
Empty (constant)
Com The Empty value has special meaning indicating that a Variant is uninitialized. When Emp
ments ty is assigned to numbers, the value 0 is assigned. When Empty is assigned to a String , the
string is assigned a zero-length string.
a = Empty
End Sub
See Null (on page 544) (constant); Variant (on page 684) (data type); VarType (on page 686)
Also (function).
End (statement)
Syntax End
De Terminates execution of the current script, closing all open files.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 400
End
End Sub
See Al Close (on page 294) (statement); Stop (on page 649) (statement); Exit For (on page 419)
so (statement); Exit Do (on page 418) (statement); Exit Function (on page 419) (statement);
Exit Sub (on page 420) (function).
Syn Begin Dialog (on page 269) DialogName [x],[y],width,height,title$ [,[.DlgProc] [,[PicName$]
tax [,style]]] Dialog Statements End Dialog
De Defines the end of the dialog box template for use with the Dialog statement and function.
scrip
tion
See Begin Dialog (on page 269) (statement), CancelButton (on page 286) (statement); CheckBox
Also (on page 281) (statement); ComboBox (on page 294) (statement); Dialog (on page 336)
(function); Dialog (on page 338) (statement); DlgProc (on page 352) (function); DropListBox
(on page 371) (statement); GroupBox (on page 457) (statement); ListBox (on page 504)
(statement); OKButton (on page 551) (statement); OptionButton (on page 564) (statement);
OptionGroup (on page 566) (statement); Picture (on page 570) (statement; PictureButton (on
page 572) (statement); PushButton (on page 584) (statement); Text (on page 664) (state
ment); TextBox (on page 666) (statement).
Note Within user dialog boxes, the default font is 8-point MS Sans Serif.
Com Environ$ returns a String , whereas Environ returns a String variant. If variable$ is specified,
ments then this function looks for that variable$ in the environment. If the variable$ name cannot be
found, then a zero-length string is returned. If VariableNumber is specified, then this function
looks for the Nth variable within the environment (the first variable being number 1). If there is
no such environment variable, then a zero-length string is returned. Otherwise, the entire entry
from the environment is returned in the following format:
variable = value
Exam This example looks for the DOS Comspec variable and displays the value in a dialog box.
ple Sub Main()
Dim a$(1)
a$(1) = Environ("SITE_Root")
End Sub
See Command (on page 296), Command$ (on page 296) (functions).
Also
EOF (function)
De Returns True if the end-of-file has been reached for the given file; returns False otherwise.
scrip
tion
Com The filenumber parameter is an Integer used by the Basic Control Engine to refer to the open
ments 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 er
ror). 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.
Exam This example opens the autoexec.bat file and reads lines from the file until the end-of-file is
ple reached.
Sub Main()
file$ = "c:\autoexec.bat"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 402
Loop
Close
MsgBox "The last line of '" & file$ "' is:" & crlf & crlf & newline
End Sub
See Open (on page 554) (statement); LOF (on page 509) (function).
Also
Eqv (operator)
Com If both expressions are either Boolean , Boolean variants, or Null variants, then a logical
ments equivalence is performed as follows:
If the first expres and the second ex then the result is
sion is pression 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 ex
pressions, according to the following table:
1 Eqv 1 = 1 Example
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 403
0 Eqv 1 = 0 5 01101001
1 Eqv 0 = 0 6 10101010
Exam This example assigns False to A, performs some equivalent operations, and displays a dialog
ple box with the result. Since A is equivalent to False, and False is equivalent to 0, and by definition,
A = 0, then the dialog box will display "A is False."
Sub Main()
a = False
Else
End If
End Sub
See Operator Precedence (on page 560) (topic); Or (on page 567) (operator); Xor (on page 708)
Also (operator); Imp (on page 470) (operator); And (on page 230) (operator).
Erase (statement)
Com For dynamic arrays, the elements are erased, and the array is redimensioned to have no dimen
ments sions (and therefore no elements). For fixed arrays, only the elements are erased; the array di
mensions are not changed.
After a dynamic array is erased, the array will contain no elements and no dimensions. Thus, be
fore the array can be used by your program, the dimensions must be reestablished using the
Redim statement. Up to 32 parameters can be specified with the Erase statement.
The meaning of erasing an array element depends on the type of the element being erased:
String (variable-length) Frees the string, then sets the element to a zero-length string.
Object Decrements the reference count and sets the element to Nothing .
Exam This example fills an array with a list of available disk drives, displays the list, erases the array
ple and then redisplays the list.
Sub Main()
End Sub
See Redim (on page 601) (statement); Arrays (on page 250) (topic).
Also
Erl (function)
Syn Erl[()]
tax
Com The first line of the script is 1, the second line is 2, and so on. The internal value of Erl is reset
ments to 0 with any of the following statements: Resume , Exit Sub , Exit Function . Thus, if you want
to use this value outside an error handler, you must assign it to a variable.
Exam This example generates an error and then determines the line on which the error occurred.
ple Sub Main()
Dim i As Integer
i = i + 1
Exit Sub
Trap1:
End Sub
See Err (on page 405) (function); Error, Error$ (on page 406) (functions); Error Handling (on page
Also 408) (topic).
Err (function)
Err (statement)
De Sets the value returned by the Err function to a specific Integer value.
scrip
tion
Com Only positive values less than or equal to 32767 can be used. Setting value to -1 has the side
ments effect of resetting the error state. This allows you to perform error trapping within an error han
dler. The ability to reset the error handler while within an error trap is not standard Basic. Nor
mally, the error handler is reset only with the Resume , Exit Sub , or Exit Function statement.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 406
Exam This example forces error 10, with a subsequent transfer to the TestError label. TestError tests
ple the error and, if not error 55, resets Err to 999 (user-defined error) and returns to the Main sub
routine.
Sub Main()
Error 10
MsgBox "The returned error is: '" & Err() & " - " & Error$ & "'"
Exit Sub
TestError:
Else
Err = 999
End If
Resume Next
End Sub
See Error (on page 407) (statement); Error Handling (on page 408) (topic).
Also
De Returns a String containing the text corresponding to the given error number or the most recent
scrip error.
tion
Com Error$ returns a String, whereas Error returns a String variant. The errornumber parameter is
ments 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. If no runtime
error has occurred, then a zero-length string is returned. If the Error statement was used to gen
erate a user-defined runtime error, then this function will return a zero-length string ("").
Exam This example forces error 10, with a subsequent transfer to the TestError label. TestError tests
ple the error and, if not error 55, resets Err to 999 (user-defined error) and returns to the Main sub
routine.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 407
Sub Main()
Error 10
MsgBox "The returned error is: '" & Err & " - " & Error & "'"
Exit Sub
TestError:
Else
Err = 999
End If
Resume Next
End Sub
See Erl (on page 404) (function); Err (on page 405) (function); Error Handling (on page 408)
Also (topic).
Error (statement)
Com The errornumber parameter is any Integer containing either a built-in error number or a user-de
ments fined error number. The Err function can be used within the error trap handler to determine the
value of the error.
Exam This example forces error 10, with a subsequent transfer to the TestError label. TestError tests
ple the error and, if not error 55, resets Err to 999 (user-defined error) and returns to the Main sub
routine.
Sub Main()
Error 10
MsgBox "The returned error is: '" & Err() & " - " & Error$ & "'"
Exit Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 408
TestError:
Else
Err = 999
End If
Resume Next
End Sub
See Err (on page 405) (statement); Error Handling (on page 408) (topic).
Also
1. Visual Basic–compatible errors: These errors, numbered between 0 and 799, are numbered and
named according to the errors supported by Visual Basic.
2. Basic Control Engine script errors: These errors, numbered from 800 to 999, are unique to the
Basic Control Engine..
3. User-defined errors: These errors, equal to or greater than 1,000, are available for use by
extensions or by the script itself.
Err.Clear (method)
Syn Err.Clear
tax
Com After this method has been called, the properties of the Err object will have the following values:
ments
Property Value
Err.Description ""
Err.HelpContext 0
Err.HelpFile ""
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 409
Err.LastDLLError 0
Err.Number 0
Err.Source ""
The properties of the Err object are automatically reset when any of the following statements
are executed:
Exam
ple 'The following script gets input from the user using error
'checking.
Sub Main()
Dim x As Integer
x = InputBox("Type in a number")
Err.Clear
x = 0
End If
MsgBox x
End Sub
See Error Handling (on page 408) (topic), Err.Description (on page 409) (property), Err.Help
Also Context (on page 410) (property), Err.HelpFile (on page 412) (property), Err.LastDLLError
(on page 413) (property), Err.Number (on page 414) (property), Err.Source (on page 417)
(property)
Err.Description (property)
Com For errors generated by BasicScript, the Err.Description property is automatically set. For user-
ments defined errors, you should set this property to be a description of your error. If you set the Er-
r.Number property to one of BasicScript’s internal error numbers and you don’t set the Err.De-
scription property, then the Err.Description property is automatically set when the error is gen
erated (i.e., with Err.Raise).
Exam
ple 'The following script gets input from the user using error
'value.
Sub Main()
Dim x As Integer
x = InputBox("Type in a number")
x = 0
End If
MsgBox x
End Sub
See Error Handling (on page 408) (topic), Err.Clear (on page 408) (method), Err.HelpContext (on
Also page 410) (property), Err.HelpFile (on page 412) (property), Err.LastDLLError (on page 413)
(property), Err.Number (on page 414) (property), Err.Source (on page 417) (property)
Err.HelpContext (property)
De Sets or retrieves the help context ID that identifies the help topic for information on the error.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 411
Com The Err.HelpContext property, together with the Err.HelpFile property, contain sufficient infor
ments mation to display help for the error. When BasicScript generates an error, the Err.HelpContext
property is set to 0 and the and the Err.HelpFile property is set to ""; the value of the Err.Number
property is sufficient for displaying help in this case. The exception is with errors generated by
an OLE automation server; both the Err.HelpFile and Err.HelpContext properties are set by the
server to values appropriate for the generated error. When generating your own user-define er
rors, you should set the Err.HelpContext property and the Err.HelpFile property appropriately
for your error. If these are not set, then BasicScript displays its own help at an appropriate place.
Exam
ple 'This example defines a replacement for InputBox that deals
Dim x As Integer
x = InputBox(Prompt,Title,Def)
If Err.Number Then
Err.HelpFile = "AZ.HLP"
Err.HelpContext = 2
InputInteger = Null
Err.Raise 3000
End If
InputInteger = x
End Function
Sub Main
Dim x As Integer
Do
x = InputInteger("Enter a number:")
,,,Err.HelpFile,Err.HelpContext
End If
End Sub
See Error Handling (on page 408) (topic), Err.Clear (on page 408) (method), Err.Description (on
Also page 409) (property), Err.HelpFile (on page 412) (property), Err.LastDLLError (on page 413)
(property), Err.Number (on page 414) (property), Err.Source (on page 417) (property)
Err.HelpFile (property)
De Sets or retrieves the name of the help file associated with the error.
scrip
tion
Com The Err.HelpFile property, together with the Err.HelpContents property, contain sufficient infor
ments mation to display help for the error. When BasicScript generates an error, the Err.HelpContents
property is set to 0 and the Err.HelpFile property is set to ""; the value of the Err.Number proper
ty is sufficient for displaying help in this case. The exception is with errors generated by an OLE
automation server; both the Err.HelpFile and Err.HelpContext properties are set by the server
to values appropriate for the generated error. When generating your own user-define errors, you
should set the Err.HelpContext property and the Err.HelpFile property appropriately for your er
ror. If these are not set, then BasicScript displays its own help at an appropriate place.
Exam
ple 'This example defines a replacement for InputBox that deals
Dim x As Integer
x = InputBox(Prompt,Title,Def)
If Err.Number Then
Err.HelpFile = "AZ.HLP"
Err.HelpContext = 2
InputInteger = Null
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 413
Err.Raise 3000
End If
InputInteger = x
End Function
Sub Main
Dim x As Integer
Do
x = InputInteger("Enter a number:")
,,, Err.HelpFile,Err.HelpContext
End If
End Sub
See Error Handling (on page 408) (topic)m Err.Clear (on page 408) (method), Err.HelpContext (on
Also page 410) (property), Err.Description ( (on page 409)(property), Err.LastDLLError (on page
413) (property), Err.Number (on page 414) (property), Err.Source (on page 417) (property)
Note The Err.HelpFile property can be set to any valid Windows help file (i.e., a file with a .HLP exten
sion compatible with the WINHELP help engine).
Err.LastDLLError (property)
Syn Err.LastDLLError
tax
De Returns the last error generated by an external call, i.e. a call to a routine declared with the De-
scrip clare statement that resides in an external module.
tion
Com The Err.LastDLLError property is automatically set when calling a routine defined in an external
ments module. If no error occurs within the external call this property will automatically be set to 0.
Sub Main()
Err.Clear
GetCurrentDirectoryA len(dest),dest
Else
End If
End Sub
See Error Handling (on page 408) (topic), Err.Clear (on page 408) (method), Err.HelpContext (on
Also page 410) (property), Err.Description (on page 409) (property), Err.HelpFile (on page 412)
(property), Err.Number (on page 414) (property), Err.Source (on page 417) (property)
Note This property is set by DLL routines that set the last error using the Win32 function SetLastEr-
ror(). 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.
Err.Number (property)
Com The Err.Number property is set automatically when an error occurs. This property can be used
ments within an error trap to determine which error occurred. You can set the Err.Number property to
any Long value. The Number property is the default property of the Err object. This allows you to
use older style syntax such as those shown below: Err = 6 If Err = 6 Then MsgBox "Overflow"
The Err function can only be used while within an error trap. The internal value of the Err.Num-
ber property is reset to 0 with any of the following statements: Resume, Exit Sub, Exit Function.
Thus, if you want to use this value outside an error handler, you must assign it to a variable. Set
ting Err.Number to –1 has the side effect of resetting the error state. This allows you to perform
error trapping within an error handler. The ability to reset the error handler while within an error
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 415
trap is not standard Basic. Normally, the error handler is reset only with the Resume, Exit Sub, Ex-
Exam
ple 'This example forces error 10, with a subsequent transfer to
Sub Main()
Error 10
MsgBox "The returned error is: '" & Err() & " - " & _
Exit Sub
TestError:
Else
Err = 999
End If
Resume Next
End Sub
Err.Raise (method)
De Generates a runtime error, setting the specified properties of the Err object.
scrip
tion
Para Description
meter
num A Long value indicating the error number to be generated. This parameter is required.
ber Errors 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 mod
ule that generated the error. If omitted, then BasicScript uses the name of the currently
executing script.
de An optional String expression describing the error. If omitted and number maps to a
scrip predefined BasicScript error number, then the corresponding predefined description is
tion used. Otherwise, the error "Application-defined or object-define error" is used.
help An optional String expression specifying the name of the help file containing con
file text-sensitive help for this error. If omitted and number maps to a predefined Basic
Script error number, then the default help file is assumed.
help An optional Long value specifying the topic within helpfile containing context-sensitive
con help for this error. If some arguments are omitted, then the current property values of
text the Err object are used. This method can be used in place of the Error statement for
generating errors. Using the Err.Raise method gives you the opportunity to set the de
sired properties of the Err object in one statement.
Exam
ple 'The following example uses the Err.Raise method to generate
Sub Main()
Dim x As Variant
x = InputBox("Enter a number:")
End If
MsgBox x
Exit Sub
TRAP:
MsgBox Err.Description
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 417
See Error (on page 407) (statement), Error Handling (on page 408) (topic), Err.Clear (on page
Also 408) (method), Err.HelpContext (on page 410) (property), Err.Description (on page 409)
(property), Err.HelpFile (on page 412) (property), Err.Number (on page 414) (property), Er
r.Source (on page 417) (property)
Err.Source (property)
Com For OLE automation errors generated by the OLE server, the Err.Source property is set to the
ments name of the object that generated the error. For all other errors generated by BasicScript, the Er-
r.Source property is automatically set to be the name of the script that generated the error. For
user-defined errors, the Err.Source property can be set to any valid String expression indicating
the source of the error. If the Err.Source property is not explicitly set for user-defined errors, the
BasicScript sets the value to be the name of the script in which the error was generated.
Exam
ple 'The following script generates an error, setting the source
Dim x As Integer
x = InputBox(Prompt,Title,Def)
If Err.Number Then
Err.Source = "InputInteger"
InputInteger = Null
Err.Raise 3000
End If
InputInteger = x
End Function
Sub Main
x = InputInteger("Enter a number:")
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 418
End Sub
See Error Handling (on page 408) (topic), Err.Clear (on page 408) (method), Err.HelpContext (on
Also page 410) (property), Err.Description (on page 409) (property), Err.HelpFile (on page 412)
(property), Err.Number (on page 414) (property), Err.LastDLLError (on page 413) (property)
Exit Do (statement)
Syntax Exit Do
De Causes execution to continue on the statement following the Loop clause.
scrip
tion
Exam This example will load an array with directory entries unless there are more than ten entries-in
ple which case, the Exit Do terminates the loop.
Sub Main()
Dim a$(5)
Do
i% = i% + 1
If i% = 1 Then
a(i%) = Dir("*")
Else
a(i%) = Dir
End If
If i% = 5 Then
Else
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 419
See Al Stop (on page 649) (statement); Exit For (on page 419) (statement); Exit Function (on page
so 419) (statement); Exit Sub (on page 420) (statement); End (on page 399) (statement);
Do...Loop (on page 366) (statement).
De Causes execution to exit the innermost For loop, continuing execution on the line following the
scrip Next statement.
tion
Exam This example enters a large user-defined cycle, performs a calculation and exits the For...Next
ple loop when the result exceeds a certain value.
Sub Main()
For i = 1 To Val(num)
newpressure = i * 2
Next i
End Sub
See Al Stop (on page 649) (statement); Exit Do (on page 418) (statement); Exit Function (on page
so 419) (statement); Exit Sub (on page 420) (statement); End (on page 399) (statement);
Do...Loop (on page 366) (statement).
De Causes execution to exit the current function, continuing execution on the statement following
scrip the call to this function.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 420
Exam This function displays a message and then terminates with Exit Function.
ple Function Test_Exit() As Integer
Test_Exit = 0
Exit Function
End Function
Sub Main()
a% = Test_Exit()
End Sub
See Al Stop (on page 649) (statement); Exit For (on page 419) (statement); Exit Do (on page 418)
so (statement); Exit Sub (on page 420) (statement); End (on page 399) (statement); Do...Loop
(on page 366) (statement).
De Causes execution to exit the current subroutine, continuing execution on the statement follow
scrip ing the call to this subroutine.
tion
Com This statement can appear anywhere within a subroutine. It cannot appear within a function.
ments
Exam This example displays a dialog box and then exits. The last line should never execute because
ple of the Exit Sub statement.
Sub Main()
Exit Sub
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 421
See Al Stop (on page 649) (statement); Exit For (on page 419) (statement); Exit Function (on page
so 419) (statement); Exit Do (on page 418) (statement); End (on page 399) (statement);
Do...Loop (on page 366) (statement).
Exp (function)
A runtime error is generated if value is out of the range specified above. The value of e is
2.71828 .
Example This example assigns a to e raised to the 12.4 power and displays it in a dialog box.
Sub Main()
a# = Exp(12.4)
End Sub
Basic Control Engine scripts allows expressions to involve data of different types. When this occurs, the
two arguments are converted to be of the same type by promoting the less precise operand to the same
type as the more precise operand. For example, the Basic Control Engine will promote the value of i% to a
Double in the following expression:
result# = i% * d#
In some cases, the data type to which each operand is promoted is different than that of the most precise
operand. This is dependent on the operator and the data types of the two operands and is noted in the
description of each operator.
If an operation is performed between a numeric expression and a String expression, then the String
expression is usually converted to be of the same type as the numeric expression. For example, the
following expression converts the String expression to an Integer before performing the multiplication:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 422
There are exceptions to this rule as noted in the description of the individual operators.
Type Coercion
The Basic Control Engine 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. The Basic Control
Engine 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:
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:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 423
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:
F
F
False (constant)
FileAttr (function)
FileCopy (statement)
FileDateTime (function)
FileDirs (statement)
FileExists (function)
FileLen (function)
FileList (statement)
FileParse$ (function)
Fix (function)
For...Next (statement)
FreeFile (function)
False (constant)
Exam This example assigns False to a, performs some equivalent operations, and displays a dialog
ple box with the result. Since a is equivalent to False, and False is equivalent to 0, and by definition,
a = 0, then the dialog box will display "a is False."
Sub Main()
a = False
Else
End If
End Sub
See True (on page 673) (constant); Constants (topic); Boolean (on page 272) (data type).
Also
FileAttr (function)
De Returns an Integer specifying the file mode (if attribute is 1) or the operating system file handle
scrip (if attribute is 2).
tion
Parameter Description
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 425
Filenumber Integer value used by Basic Control Engine to refer to the open file;
the number passed to the Open statement.
1 Input
2 Output
4 Random
8 Append
32 Binary
Exam This example opens a file for input, reads the file attributes, and determines the file mode for
ple which it was opened. The result is displayed in a dialog box.
Sub Main()
a% = FileAttr(1,1)
Select Case a%
Case 1
Case 2
Case 4
Case 8
Case 32
Case Else
End Select
a% = FileAttr(1,2)
Close
End Sub
See FileLen (on page 429) (function); GetAttr (on page 451) (function); FileExists (on page 429)
Also (function); Open (on page 554) (statement); SetAttr (on page 627) (statement).
FileCopy (statement)
Para Description
meter
source String containing the name of a single file to copy. The source$ parameter cannot con
$ tain wildcards ( ? or * ) but may contain path information.
des String containing a single, unique destination file, which may contain a drive and path
tina specification.
tion$
The file will be copied and renamed if the source$ and destination$ filenames are not the same.
Some platforms do not support drive letters and may not support dots to indicate current and
parent directories.
Exam This example copies the autoexec.bat file to "autoexec.sav", then opens the copied file and tries
ple to copy it again--which generates an error.
Sub Main()
FileCopy "c:\autoexec.bat","c:\autoexec.sav"
FileCopy "c:\autoexec.sav","c:\autoexec.sv2"
Close
Exit Sub
ErrHandler:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 427
Else
End If
Resume Next
End Sub
See Kill (on page 491) (statement); Name (on page 531) (statement).
Also
FileDateTime (function)
De Returns a Date variant representing the date and time of the last modification of a file.
scrip
tion
Com This function retrieves the date and time of the last modification of the file specified by file
ments name$ (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.
Exam This example gets the file date/time of the autoexec.bat file and displays it in a dialog box.
ple Sub Main()
If FileExists("c:\autoexec.bat") Then
a# = FileDateTime("c:\autoexec.bat")
MsgBox "The date/time information for the file is: " & Year(a#) & "-" & Month(a#) & "-" & Day(a#)
Else
End If
End Sub
See FileLen (on page 429) (function); GetAttr (on page 451) (function); FileAttr (on page 424)
Also (function); FileExists (on page 429) (function).
Notes: The Win32 operating system stores 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.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 428
FileDirs (statement)
De Fills a String or Variant array with directory names from disk.
scrip
tion
Para Description
meter
Array() 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 er
ror results if the array is too small to hold the new elements.
t*. c:\*
If this parameter is omitted, then * is used, which fills the array with all the subdirecto
ry names within the current directory.
Exam This example fills an array with directory entries and displays the first one.
ple Sub Main()
Dim a$()
FileDirs a$,"c:\*"
End Sub
See FileList (on page 430) (statement); Dir, Dir$ (on page 339) (functions); CurDir, CurDir$ (on
Also page 308) (functions); ChDir (on page 280) (statement).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 429
FileExists (function)
Com This function determines whether a given filename$ is valid. This function will return False if
ments filename$ specifies a subdirectory.
Exam This example checks to see whether there is an autoexec.bat file in the root directory of the C
ple drive, then displays either its creation date and time or the fact that it does not exist.
Sub Main()
If FileExists("c:\autoexec.bat") Then
Else
End If
End Sub
See FileLen (on page 429) (function); GetAttr (on page 451) (function); FileAttr (on page 424)
Also (function); FileParse$ (on page 432) (function).
FileLen (function)
Com This function is used in place of the LOF function to retrieve the length of a file without first
ments opening the file. A runtime error results if the file does not exist.
Exam This example checks to see whether there is a c:\autoexec.bat file and, if there is, displays the
ple length of the file.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 430
Sub Main()
file$ = "c:\autoexec.bat"
b% = FileLen(file$)
MsgBox "'" & file$ & "' is " & b% & " bytes."
Else
End If
End Sub
See GetAttr (on page 451) (function); FileAttr (on page 424) (function); FileParse$ (on page
Also 432) (function); FileExists (on page 429) (function); Loc (on page 506) (function).
FileList (statement)
Parame Description
ter
Array() Either a zero- or a one-dimensioned array of strings or variants. The array can be ei
ther dynamic or fixed. If array() is dynamic, then it will be redimensioned to exact
ly 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 dimen
sions. 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 Emp
ty (for Variant arrays). A runtime error results if the array is too small to hold the
new elements.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 431
Filespec$ String specifying which filenames are to be included in the list. The filespec$ para
meter can include wildcards, such as * and ? . If this parameter is omitted, then *
is used.
Include_ Integer specifying attributes of files you want included in the list. It can be any com
attr bination of the attributes listed below. If this parameter is omitted, then the value 97
is used ( ebReadOnly Or ebArchive Or ebNone ).
Exclude_ Integer specifying attributes of files you want excluded from the list. It can be any
attr combination of the attributes listed below. If this parameter is omitted, then the val
ue 18 is used ( ebHidden Or ebDirectory ). In other words, hidden files and subdirec
tories are excluded from the list.
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:
GOOSE.TXT SAMPLE.DAT
SAMS.TXT
ACATS.TXT
CAP.TXT
CUT CAPIT
CT
* (All files)
Exam This example fills an array a with the directory of the current drive for all files that have normal
ple or no attributes and excludes those with system attributes. The dialog box displays four file
names from the array.
Sub Main()
Dim a$()
Else
End If
End Sub
See FileDirs (on page 428) (statement); Dir, Dir$ (on page 339) (functions).
Also
FileParse$ (function)
De Returns a String containing a portion of filename$ such as the path, drive, or file extension.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 433
Com The filename$ parameter can specify any valid filename (it does not have to exist). For example:
ments ..\test.dat
c:\sheets\test.dat
test.dat
A runtime error is generated if filename$ is a zero-length string. The optional operation parame
ter is an Integer specifying which portion of the filename$ to extract. It can be any of the follow
ing values.
1 Drive c
2 Path c:\sheets
3 Name test.dat
4 Root test
5 Extension dat
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.
Exam This example parses the file string c:\temp\autoexec.bat into its component parts and dis
ple plays them in a dialog box.
Sub Main()
Dim a$(5)
file$ = "c:\temp\autoexec.bat"
For i = 1 To 5
a$(i) = FileParse$(file$,i)
Next i
msg1 = "The breakdown of '" & file$ & "' is:" & crlf & crlf
msg1 = msg & a$(1) & crlf & a$(2) & crlf & a$(3) & crlf & a$(4) & crlf & a$(5)
MsgBox msg1
End Sub
See FileLen (on page 429) (function); GetAttr (on page 451) (function); FileAttr (on page 424)
Also (function); FileExists (on page 429) (function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 434
Note The backslash and forward slash can be used interchangeably. For example, c:\test.dat is the
same as c:/test.dat.
Fix (function)
Com This function returns the integer part of the given value by removing the fractional part. The sign
ments is preserved. The Fix function returns the same type as number, with the following exceptions:
Exam This example returns the fixed part of a number and assigns it to b, then displays the result in a
ple dialog box.
Sub Main()
a# = -19923.45
b% = Fix(a#)
End Sub
See Int (on page 478) (function); CInt (on page 285) (function).
Also
Syn For Each member in group [statements] [Exit For] [statements] Next [member]
tax
Para Description
meter
mem Name of the variable used for each iteration of the loop. If group is an array, then mem
ber ber 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.
BasicScript supports iteration through the elements of OLE collections or arrays, unless the ar
rays contain user-defined types or fixed-length strings. The iteration variable is a copy of the col
lection or array element in the sense that 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 con
tained 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 rel
evant to the correct operation of the script. The For Each...Next statement continues execut
ing 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.
Exam
ple ’The following subroutine iterates through the elements
Sub Main()
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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 436
Next i
s = ""
For Each i In a
s = s & i
Next i
MsgBox s
End Sub
Sub Main()
Excel.Visible = 1
Excel.Workbooks.Add
MsgBox a.Name
Next a
End Sub
See Do...Loop (on page 366) (statement), While...Wend (on page 693) (statement), For...Next (on
Also page 436) (statement)
Note Due to errors in program logic, you can inadvertently create infinite loops in your code. Under
Windows and Win32, you can break out of infinite loops using Ctrl+Break.
For...Next (statement)
Syn For counter = start To end [Step increment] [statements] [Exit For] [statements] Next [counter
tax [,nextcounter]... ]
De Repeats a block of statements a specified number of times, incrementing a loop counter by a
scrip given increment each time through the loop.
tion
Para Description
meter
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.
incre Amount added to counter each time through the loop. If end is greater than start, then
ment 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 ef
fect.
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 op
timized 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 outer
most 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 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.
ple 'This example constructs a truth table for the OR statement 'using nested For...Next loops.
For x = -1 To 0
For y = -1 To 0
z = x Or y
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 438
Next y
Next x
MsgBox msg1
End Sub
See Do...Loop (on page 366) (statement); While...Wend (on page 693) (statement).
Also
Notes Due to errors in program logic, you can inadvertently create infinite loops in your code. You can
use Ctrl+Break to break out of infinite loops.
Com Format$ returns a String , whereas Format returns a String variant. The Format$/Format
ments functions take the following parameters:
Para Description
meter
User Format expression that can be either one of the built-in Basic Control Engine formats
for or a user-defined format consisting of characters that specify how the expression
mat$ should be displayed. String, numeric, and date/time formats cannot be mixed in a sin
gle Userformat$ expression.
If Userformat$ is omitted and the expression is numeric, then these functions perform the same
function as the Str$ or Str statements, except that they do not preserve a leading space for
positive values. If expression is Null , then a zero-length string is returned.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 439
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 oth
er with date/time values. The following tables list the built-in numeric and date/time format
strings, followed by an explanation of what each does.
Numeric Formats
Format Description
Curren Displays the numeric expression as currency, with thousands separator if necessary.
cy
Fixed Displays at least one digit to the left of the decimal separator and two digits to the
right.
Stan Displays the numeric expression with thousands separator if necessary. Displays at
dard least one digit to the left of the decimal separator and two digits to the right.
Per Displays the numeric expression multiplied by 100. A percent sign (%) will appear at
cent the right of the formatted output. Two digits are displayed to the right of the decimal
separator.
Scien Displays the number using scientific notation. One digit appears before the decimal
tific separator and two after.
Yes/No Displays No if the numeric expression is 0. Displays Yes for all other values.
True/ Displays False if the numeric expression is 0. Displays True for all other values.
False
On/Off Displays Off if the numeric expression is 0. Displays On for all other values.
Date/Time Formats
Format Description
Gener Displays the date and time. If there is no fractional part in the numeric expression, then
al date 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.
Medi Displays a medium date—prints out only the abbreviated name of the month.
um
date
Medi Displays the time using a 12-hour clock. Hours and minutes are displayed, and the
um AM/PM designator is at the end.
time
Short Displays the time using a 24-hour clock. Hours and minutes are displayed.
time
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 follow
ing tables list the characters you can use for numeric, string, and date/time formats and explain
their functions.
Numeric Formats
Char Meaning
acter
Displays a number or nothing. If a number exists in the numeric expression in the posi
tion where the number sign appears, the number will be displayed. Otherwise, nothing
will be displayed. Leading and trailing 0s are not displayed.
Designates the number of digits to the left of the decimal and the number of digits to
the right. The character used in the formatted string depends on the decimal place
holder, as specified by your locale.
The numeric expression is multiplied by 100, and the percent character is inserted in
the same position as it appears in the user-defined format string.
The common use for the thousands separator is to separate thousands from hun
dreds. To specify this use, the thousands separator must be surrounded by digit place
holders. Commas appearing before any digit placeholders are specified are just dis
played. Adjacent commas with no digit placeholders specified between them and the
decimal mean that the number should be divided by 1,000 for each adjacent comma in
the format string. A comma immediately to the left of the decimal has the same func
tion. The actual thousands separator character used depends on the character speci
fied by your locale.
:E- E+ These are the scientific notation operators, which display the number in scientific no
e- e+ tation. At least one digit placeholder must exist to the left of E- , E+ , e- , or e+ . Any
digit placeholders displayed to the left of E- , E+ , e- , or e+ determine the number
of digits displayed in the exponent. Using E+ or e+ places a + in front of positive ex
ponents and a – in front of negative exponents. Using E- or e- places a – in front of
negative exponents and nothing in front of positive exponents.
Separates hours, minutes, and seconds when time values are being formatted. The ac
tual character used depends on the character specified by your locale.
Separates months, days, and years when date values are being formatted. The actual
character used depends on the character specified by your locale.
:- + $ ( ) These are the literal characters you can display. To display any other character, you
space should precede it with a backslash or enclose it in quotes.
To display characters, precede them with a backslash. To display a backslash, use two
backslashes. Double quotation marks can also be used to display characters. Numeric
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 442
:"ABC" Displays the text between the quotation marks, but not the quotation marks. To desig
nate a double quotation mark within a format string, use two adjacent double quota
tion marks.
Any empty space in a field will be filled with the specified fill character.
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 posi
tive 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
Char Meaning
acter
& This is a character placeholder. Displays a character if one exists in the expression in
the same position; otherwise, displays nothing. Placeholders are filled from right to left
unless the format string specifies left to right.
< This character forces lowercase. Displays all characters in the expression in lower
case.
> This character forces uppercase. Displays all characters in the expression in upper
case.
! This character forces placeholders to be filled from left to right. The default is right to
left.
Date/Time Formats
Char Meaning
acter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 443
c Displays the date as ddddd and the time as ttttt . Only the date is displayed if no frac
tional part exists in the numeric expression. Only the time is displayed if no integral
portion exists in the numeric expression.
w Displays the number of the day of the week (1–7). Sunday is 1; Saturday is 7.
AM/ Displays the time using a 12-hour clock. Displays an uppercase AM for time values
PM before 12 noon. Displays an uppercase PM for time values after 12 noon and before
12 midnight.
am/pm Displays the time using a 12-hour clock. Displays a lowercase am or pm at the end.
A/P Displays the time using a 12-hour clock. Displays an uppercase A or P at the end.
a/p Displays the time using a 12-hour clock. Displays a lowercase a or p at the end.
AMPM Displays the time using a 12-hour clock. Displays the string s1159 for values before
12 noon and s2359 for values after 12 noon and before 12 midnight.
a# = 1199.234
msg1 = "Some general formats for '" & a# & "' are:" & crlf & crlf
MsgBox msg1
da$ = Date$
msg1 = "Some date formats for '" & da$ & "' are:" & crlf & crlf
MsgBox msg1
ti$ = Time$
msg1 = "Some time formats for '" & ti$ & "' are:" & crlf & crlf
MsgBox msg1
End Sub
See Str, Str$ (on page 656) (functions); CStr (on page 307) (function).
Also
Note The default date/time formats are read from the [Intl] section of the win.ini file.
FreeFile (function)
Syntax FreeFile[()]
Com The number returned is suitable for use in the Open statement and will always be between 1
ments and 255 inclusive.
Example This example assigns A to the next free file number and displays it in a dialog box.
Sub Main()
a = FreeFile
End Sub
See Also FileAttr (on page 424) (function); Open (on page 554) (statement).
a = Test(1,,)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 446
5. 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:
Fv (function)
De Calculates the future value of an annuity based on periodic fixed payments and a constant rate
scrip of interest.
tion
Com An annuity is a series of fixed payments made to an insurance company or other investment
ments company over a period of time. Examples of annuities are mortgages and monthly savings
plans. The Fv function requires the following parameters:
Pa Description
ra
me
ter
Rate Double representing the interest rate per period. Make sure that annual rates are normal
ized for monthly periods (divided by 12).
NPer Double representing the total number of payments (periods) in the annuity.
Pmt Double representing the amount of each payment per period. Payments are entered as
negative values, whereas receipts are entered as positive values.
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, whereas in the case of a retirement annuity, the
present value would be the amount of the fund.
Due Integer indicating when payments are due for each payment period. A 0 specifies pay
ment at the end of each period, whereas a 1 indicates payment at the start of each peri
od.
Rate and NPer values must be expressed in the same units. If Rate is expressed as a percent
age per month, then NPer must also be expressed in months. If Rate is an annual rate, then the
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 447
NPer must also be given in years. Positive numbers represent cash received, whereas negative
numbers represent cash paid out.
Exam This example calculates the future value of 100 dollars paid periodically for a period of 10 years
ple (120 months) at a rate of 10% per year (or .10/12 per month) with payments made on the first of
the month. The value is displayed in a dialog box. Note that payments are negative values.
Sub Main()
a# = Fv((.10/12),120,-100.00,0,1)
End Sub
See IRR (on page 481) (function); MIRR (on page 519) (function); Npv (on page 543) (function);
Also Pv (on page 588) (function).
G
G
Get (statement)
GetAllSettings (function)
GetAttr (function)
GetObject (function)
GetSetting (function)
Global (statement)
GoSub (statement)
Goto (statement)
GroupBox (statement)
Get (statement)
De Retrieves data from a random or binary file and stores that data into the specified variable.
scrip
tion
Para Description
meter
filenum Integer used by the Basic Control Engine to identify the file. This is the same number
ber passed to the Open statement.
record Long specifying which record is to be read from the file. For binary files, this number
num represents the first byte to be read starting with the beginning of the file (the first byte
ber 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 parame
ter is omitted, the commas must still appear, as in the following example:
Get #1,,recvar
vari Variable into which data will be read. The type of the variable determines how the data
able 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 re
clen 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 contiguous¾ the 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:
String (vari In binary files, variable-length strings are read by first determining the specified
able-length) string variable's length and then reading that many bytes from the file. For exam
ple, to read a string of eight characters:
In random files, variable-length strings are read by first reading a 2-byte length
and then reading that many characters from the file.
String (fixed- Fixed-length strings are read by reading a fixed number of characters from the
length) file equal to the string's declared length.
Date 8 bytes are read from the file (IEEE double format).
Boolean 2 bytes are read from the file. Nonzero values are True, and zero values are
False .
Variant A 2-byte VarType is read from the file, which determines the format of the da
ta that follows. Once the VarType is known, the data is read individually, as de
scribed above. With user-defined errors, after the 2-byte VarType , a 2-byte un
signed integer is read and assigned as the value of the user-defined error, fol
lowed by 2 additional bytes of information about the error. The exception is with
strings, which are always preceded by a 2-byte string length.
User-defined Each member of a user-defined data type is read individually In binary files,
types variable-length strings within user-defined types are read by first reading a 2-
byte length followed by the string's content. This storage is different from vari
able-length strings outside of user-defined types. When reading 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 read from a file using the Get statement.
Objects Object variables cannot be read from a file using the Get statement.
Exam This example opens a file for random write, then writes ten records into the file with the values
ple 10...50. Then the file is closed and reopened in random mode for read, and the records are read
with the Get statement. The result is displayed in a message box.
Sub Main()
For x = 1 to 10
y = x * 10
Put #1,x,y
Next x
Close
msg1 = ""
For y = 1 to 5
Get #1,y,x
msg1 = msg1 & "Record " & y & ": " & x & Basic.Eoln$
Next y
Close
MsgBox msg1
End Sub
See Open (on page 554) (statement); Put (on page 585) (statement); Input# (on page 471)
Also (statement); Line Input# (on page 500) (statement); Input, Input$ (on page 473) (functions)
GetAllSettings (function)
De Returns all of the keys within the specified section, or all of the sections within the specified ap
scrip plication from the system registry.
tion
Para Description
me
ter
app A String expression specifying the name of the application from which settings or keys
name will be returned.
sec A String expression specifying the name of the section from which keys will be returned.
tion If omitted, then all of the section names within appname will be returned.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 451
Exam
ple Sub Main()
Next i
End Sub
See GetSetting (on page 454) (function), DeleteSetting (on page 335) (statement), SaveSetting
Also (on page 613) (statement)
Notes Under Win32, this statement operates on the system registry. All settings are read from the
following entry in the system registry: HKEY_CURRENT_USER\Software\BasicScript Program Set-
tings\appname\section
GetAttr (function)
Com The attribute value returned is the sum of the attributes set for the file. The value of each at
ments tribute is as follows:
EbNormal 0 Read-only files, archive files, subdirectories, and files with no attributes.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 452
To determine whether a particular attribute is set, you can And the values shown above with
the value returned by GetAttr . If the result is True , the attribute is set, as shown below:
Sub Main()
Dim w As Integer
w = GetAttr("sample.txt")
End Sub
Exam This example tests to see whether the file test.dat exists. If it does not, then it creates the file.
ple The file attributes are then retrieved with the GetAttr function, and the result is displayed.
Sub Main()
Dim a()
FileList a,"*.*"
Again:
msg1 = ""
If r = -1 Then
End
Else
y% = GetAttr(a(r))
End If
If y% = 0 Then msg1 = msg1 & "This file has no special attributes." & crlf
If y% And ebReadOnly Then msg1 = msg1 & "The read-only bit is set." & crlf
If y% And ebHidden Then msg1 = msg1 & "The hidden bit is set." & crlf
If y% And ebSystem Then msg1 = msg1 & "The system bit is set." & crlf
If y% And ebVolume Then msg1 = msg1 & "The volume bit is set." & crlf
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 453
If y% And ebDirectory Then msg1 = msg1 & "The directory bit is set." & crlf
If y% And ebArchive Then msg1 = msg1 & "The archive bit is set."
MsgBox msg1
Goto Again
End Sub
See SetAttr (on page 627) (statement); FileAttr (on page 424) (function).
Also
GetObject (function)
De Returns the object specified by filename$ or returns a previously instantiated object of the given
scrip class$.
tion
Com This function is used to retrieve an existing OLE automation object, either one that comes from
ments a file or one that has previously been instantiated.
The filename$ argument specifies the full pathname of the file containing the object to be ac
tivated. The application associated with the file is determined by OLE at runtime. For example,
suppose that a file called c:\docs\resume.doc was created by a word processor called word
proc.exe . The following statement would invoke wordproc.exe , load the file called c:\docs\re
sume.doc , and assign that object to a variable:
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:
The GetObject function behaves differently depending on whether the first parameter is omit
ted. The following table summarizes the different behaviors of GetObject :
Omit Spec Reference to an existing instance of the specified object. A runtime error results if
ted ified the object is not already loaded.
"" Spec Reference to a new object (as specified by class$). A runtime error occurs if an
ified object of the specified class cannot be found. This is the same as CreateObject .
Spec Omit Default object from filename$. The application to activate is determined by OLE
ified ted based on the given filename.
Spec Spec Object given by class$ from the file given by filename$. A runtime error occurs if
ified ified an object of the given class cannot be found in the given file.
This second example loads the OLE server associated with a document.
End Sub
See CreateObject (on page 289) (function); Object (on page 546) (data type).
Also
GetSetting (function)
Para Description
me
ter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 455
app String expression specifying the name of the application from which the setting will be
name read.
sec String expression specifying the name of the section within appname to be read.
tion
key String expression specifying the name of the key within section to be read.
de An optional String expression specifying the default value to be returned if the desired
fault key does not exist in the system registry. If omitted, then an empty string is returned if
the key doesn’t exist.
Exam
ple Sub Main()
End Sub
See GetAllSettings (on page 450) (function), DeleteSetting (on page 335) (statement), SaveSet
Also ting (on page 613) (statement)
Note Under Win32, this statement operates on the system registry. All settings are read from the
following entry in the system registry: HKEY_CURRENT_USER\Software\BasicScript Program Set-
Global (statement)
GoSub (statement)
Com Execution can later be returned to the statement following the GoSub by using the Return
ments statement. The label parameter must be a label within the current function or subroutine.
GoSub outside the context of the current function or subroutine is not allowed.
Exam This example gets a name from the user and then branches to a subroutine to check the input.
ple If the user clicks Cancel or enters a blank name, the program terminates; otherwise, the name is
set to MICHAEL, and a message is displayed.
Sub Main()
GoSub CheckName
Exit Sub
CheckName:
GoSub BlankName
GoSub RightName
Else
GoSub OtherName
End If
Return
BlankName:
Exit Sub
RightName:
End
OtherName:
Return
End Sub
See Goto (on page 457) (statement); Return (on page 604) (statement).
Also
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 457
Goto (statement)
The compiler will produce an error if label does not exist.The label must appear within the same
subroutine or function as the Goto .Labels are identifiers that follow these rules:
GroupBox (statement)
Com This statement can only appear within a dialog box template (that is., between the Begin Dia
ments log and End Dialog statements). The group box control is used for static display only¾the user
cannot interact with a group box control. Separator lines can be created using group box con
trols. This is accomplished by creating a group box that is wider than the width of the dialog box
and extends below the bottom of the dialog box; three sides of the group box are not visible.
If title$ is a zero-length string, then the group box is drawn as a solid rectangle with no title. The
GroupBox statement requires the following parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
title$ String containing the label of the group box. If title$ is a zero-length string, then no title
will appear.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 458
.Iden Optional parameter that specifies the name by which this control can be referenced by
tifier statements in a dialog function (such as DlgFocus and DlgEnable ). If omitted, then
the first two words of title$ are used.
Exam This example shows the GroupBox statement being used both for grouping and as a separator
ple line.
Sub Main()
OKButton 16,64,40,14,.OK
CancelButton 68,64,40,14,.Cancel
End Dialog
Dialog OptionsDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); ListBox (on page 504) (statement); OKButton
(on page 551) (statement); OptionButton (on page 564) (statement); OptionGroup (on page
566) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
H
H
HelpButton (state
ment)
HLine (statement)
Hour (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 459
HPage (statement)
HScroll (statement)
HWND (object)
HWND.Value (property)
HelpButton (statement)
Com This statement can only appear within a dialog box template (i.e., between the Begin Dialog and
ments End Dialog statements). The HelpButton statement takes the following parameters:
Parameter Description
x,y Integer position of the control (in dialog units) static to the upper left corner of the
dialog box.
HelpFile String expression specifying the name of the help file to be invoked when the but
Name$ ton is selected.
HelpCon Long expression specifying the ID of the topic within HelpFileName$ containing
text 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).
Exam
ple Sub Main()
OKButton 132,8,40,14
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 460
CancelButton 132,28,40,14
HelpButton 132,48,40,14,"", 10
End Dialog
Dialog HelpDialog
End Sub
See CancelButton (on page 286) (statement), CheckBox (on page 281) (statement), ComboBox
Also (on page 294) (statement), Dialog (on page 336) (function), Dialog (on page 338) (state
ment), DropListBox (on page 371) (statement), GroupBox (on page 457) (statement), List
Box (on page 504) (statement), OKButton (on page 551) (statement), OptionButton (on page
564) (statement), OptionGroup (on page 566) (statement), Picture (on page 570) (state
ment), PushButton (on page 584) (statement), Text (on page 664) (statement), Begin Dialog
(on page 269) (statement), PictureButton (on page 572) (statement)
Com Hex$ returns a String , whereas Hex returns a String variant. The returned string contains
ments only the number of hexadecimal digits necessary to represent the number, up to a maximum of
eight.
The number parameter can be any type but is rounded to the nearest whole number before con
verting to hex. If the passed number is an integer, then a maximum of four digits are returned;
otherwise, up to eight digits can be returned. The number parameter can be any expression con
vertible to a number. If number is Null , then Null is returned. Empty is treated as 0.
Exam This example accepts a number and displays the decimal and hexadecimal equivalent until the
ple input number is 0 or invalid.
Sub Main()
Do
x = Val(xs$)
If x <> 0 Then
MsgBox "Decimal: " & x & " Hex: " & Hex(x)
Else
MsgBox "Goodbye."
End If
End Sub
HLine (statement)
De Scrolls the window with the focus left or right by the specified number of lines.
scrip
tion
Com The lines parameter is an Integer specifying the number of lines to scroll. If this parameter is
ments omitted, then the window is scrolled right by one line.
Exam This example scrolls the Notepad window to the left by three "amounts." Each "amount" is equiv
ple alent to clicking the right arrow of the horizontal scroll bar once.
Sub Main()
AppActivate "Notepad"
End Sub
See HPage (on page 462) (statement); HScroll (on page 462) (statement).
Also
Hour (function)
De Returns the hour of the day encoded in the specified time parameter.
scrip
tion
Com The value returned is as an Integer between 0 and 23 inclusive. The time parameter is any ex
ments pression that converts to a Date .
Exam This example takes the current time; extracts the hour, minute, and second; and displays them
ple as the current time.
Sub Main()
Msgbox "It is now hour " & Hour(Time) & " of today."
End Sub
See Day (on page 322) (function); Minute (on page 519) (function); Second (on page 617)
Also (function); Month (on page 522) (function); Year (on page 710) (function); Weekday (on
page 692) (function); DatePart (on page 319) (function).
HPage (statement)
De Scrolls the window with the focus left or right by the specified number of pages.
scrip
tion
Com The pages parameter is an Integer specifying the number of pages to scroll. If this parameter is
ments omitted, then the window is scrolled right by one page.
Exam This example scrolls the Notepad window to the left by three "amounts." Each "amount" is equiv
ple alent to clicking within the horizontal scroll bar on the right side of the thumb mark.
Sub Main()
AppActivate "Notepad"
End Sub
See HLine (on page 461) (statement); HScroll (on page 462) (statement).
Also
HScroll (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 463
De Sets the thumb mark on the horizontal scroll bar attached to the current window.
scrip
tion
Com The position is given as a percentage of the total range associated with that scroll bar. For ex
ments ample, if the percentage parameter is 50, then the thumb mark is positioned in the middle of the
scroll bar.
Exam This example centers the thumb mark on the horizontal scroll bar of the Notepad window.
ple Sub Main()
AppActivate "Notepad"
End Sub
See HLine (on page 461) (statement); HPage (on page 462) (statement).
Also
HWND (object)
Com This data type is used to hold references to physical windows in the operating environment.
ments The following commands operate on HWND objects:
WinSize
The above language elements support both string and HWND window specifications.
Exam This example activates the "Main" MDI window within Program Manager.
ple Sub Main()
WinActivate ProgramManager
WinMaximize ProgramManager
WinActivate ProgramManagerMain
WinRestore ProgramManagerMain
Else
End If
Else
End If
End Sub
See Al HWND.Value (on page 464) (property); WinFind (on page 697) (function); WinActivate (on
so page 695) (statement).
HWND.Value (property)
De The default property of an HWND object that returns a Variant containing a HANDLE to the
scrip physical window of an HWND object variable.
tion
Com The .Value property is used to retrieve the operating environment–specific value of a given
ments 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-on
ly.
Exam This example displays a dialog box containing the class name of Program Manager's Main win
ple dow. It does so using the .Value property, passing it directly to a Windows external routine.
ByVal ClsNameLen%)
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 465
ClassName$ = Space(40)
GetClassName ProgramManager.Value,ClassName$,Len(ClassName$)
End Sub
I
I
If...Then...Else (statement)
IIf (function)
IMEStatus (function)
Imp (operator)
Input# (statement)
Int (function)
IPmt (function)
IRR (function)
Is (operator)
IsDate (function)
IsEmpty (function)
IsError (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 466
IsMissing (function)
IsNull (function)
IsNumeric (function)
IsObject (function)
IsWebSpaceSession (function)
Item$ (function)
ItemCount (function)
If...Then...Else (statement)
Syn If condition Then [statements] [ElseIf else_condition Then [elseif_statements]] [Else [else_
tax 2 statements]] End If
Com The single-line conditional statement (syntax 1) has the following parameters:
ments
Parameter Description
statements One or more statements separated with colons. This group of statements is exe
cuted when condition is TRUE.
else_state One or more statements separated with colons. This group of statements is exe
ments cuted when condition is FALSE.
Parameter Description
elseif_state One or more statements to be executed when condition is False and else_condi
ments tion is True .
else_state One or more statements to be executed when both condition and else_condition
ments are False .
Exam This example inputs a name from the user and checks to see whether it is MICHAEL or MIKE us
ple ing 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()
GoSub MikeName
Exit Sub
End If
MsgBox "Since you don't have a name, I'll call you MIKE!"
uname$ = "MIKE"
GoSub MikeName
GoSub MikeName
Else
GoSub OtherName
End If
Exit Sub
MikeName:
Return
OtherName:
Return
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 468
See Choose (on page 283) (function); Switch (on page 657) (function); IIf (on page 468) (func
Also tion); Select...Case (on page 620) (statement).
IIf (function)
Com Both expressions are calculated before IIf returns. The IIf function is shorthand for the fol
ments lowing construct:
If condition Then
variable = TrueExpression
Else
variable = FalseExpression
End If
s$ = "Car"
End Sub
See Also Choose (on page 283) (function); Switch (on page 657) (function); If...Then...Else (on
page 466) (statement); Select...Case (on page 620) (statement).
IMEStatus (function)
Syn IMEStatus[()]
tax
Com The IMEStatus function returns one of the following constants for Japanese locales:
ments
ebIMEDisabled 3 disabled
For Korean locales, this function returns a value with the first 5 bits having the following mean
ing:
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
Exam
ple 'This example retrieves the IMEStatus and displays the results.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 470
Sub Main()
a = IMEStatus()
Select case a
Case 0
Case 1
Case 2
End Select
End Sub
Imp (operator)
Com If both expressions are either Boolean, Boolean variants, or Null variants, then a logical implica
ments tion is performed as follows:
If the first expres and the second ex then the result is
sion is pression 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 ex
pressions, according to the following table:
1 Imp 1 = 1 Example
0 Imp 1 = 1 5 01101001
1 Imp 0 = 0 6 10101010
Exam This example compares the result of two expressions to determine whether one implies the oth
ple er.
Sub Main()
a = 10 : b = 20 : c = 30 : d = 40
Else
MsgBox "a is less than b does not imply that c is less than d."
End If
Else
MsgBox "a is less than b does not imply that c is greater than d."
End If
End Sub
See Operator Precedence (on page 560) (topic); Or (on page 567) (operator); Xor (on page 708)
Also (operator); Eqv (on page 402) (operator); And (operator). (on page 230)
Input# (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 472
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:
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:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 473
7. 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 The Basic Control Engine to refer to the open
file, the 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.
De Returns a specified number of characters or bytes read from a given sequential file.
scrip
tion
Functions Return
Parameter Description
numchars Integer containing the number of characters to be read from the file.
numbytes Integer containing the number of bytes to be read from the file.
filenumber Integer referencing a file opened in either Input or Binary mode. This is the same
number passed to the Open statement.
Input and In All characters, including spaces and end-of-lines. Null characters are ignored.
put$
Exam
ple 'This example opens the autoexec.bat file and displays it in a
'dialog box.
Sub Main()
x& = FileLen("c:\autoexec.bat")
Else
Exit Sub
End If
ins = Input(80,#1)
Else
ins = Input(x,#1)
End If
Close
MsgBox "File length: " & x& & crlf & ins
End Sub
See Al Open (on page 554) (statement); Get (on page 447) (statement); Input# (on page 471)
so (statement); Line Input# (on page 500) (statement).
De Displays a dialog box with a text box into which the user can type.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 475
Com The content of the text box is returned as a String (in the case of InputBox$) or as a String vari
ments ant (in the case of InputBox). A zero-length string is returned if the user selects Cancel. The In
putBox/InputBox$ functions take the following named parameters:
Parameter Description
You can type a maximum of 255 characters into InputBox. If both the helpfile and context pa
rameters 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. When Cancel is selected, an empty string
is returned. An empty string is also returned when the user selects the OK button with no text
in the input box. Thus, it is not possible to determine the difference between these two situa
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 476
tions. If you need to determine the difference, you should create a user-defined dialog or use the
AskBox function.
Exam
ple Sub Main()
s$ = InputBox$("File to copy:","Copy","sample.txt")
End Sub
See MsgBox (on page 530) (statement), AskBox, AskBox$ (on page 254) (functions), AskPass
Also word, AskPassword$ (on page 256) (functions), OpenFileName$ (on page 558) (function),
SaveFileName$ (on page 611) (function), SelectBox (on page 622) (function), AnswerBox
(on page 231) (function)
De Returns the first character position of string find within string search.
scrip
tion
Para Description
meter
start Integer specifying the character position 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).
find Text for which to search. This can be any expression convertible to a String.
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 char
acter position of the first character.
The InStr and InStrB functions observe the following additional rules:
The InStr and InStrB functions operate on character and byte data respectively. The Instr func
tion 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.
Exam This example checks to see whether one string is in another and, if it is, then it copies the string
ple to a variable and displays the result.
Sub Main()
x% = InStr(1, a$,"Stuart",1)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 478
If x% <> 0 Then
b$ = Mid(a$,x%,6)
Exit Sub
Else
End If
End Sub
See Mid, Mid$ (on page 516) (functions); Option Compare (on page 562) (statement); Item$ (on
Also page 489) (function); Word$ (on page 705) (function); Line$ (on page 501) (function).
Int (function)
Com This function returns the integer part of a given value by returning the first integer less than the
ments number. The sign is preserved. The Int function returns the same type as number, with the fol
lowing exceptions:
a# = -1234.5224
b% = Int(a#)
End Sub
See Fix (on page 434) (function); CInt (on page 285) (function).
Also
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 479
Syn Integer
tax
De A data type used to declare whole numbers with up to four digits of precision.
scrip
tion
Com Integer variables are used to hold numbers within the following range:
ments –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 re
quired. When passed to external routines, Integer values are sign-extended to the size of an in
teger on that platform (either 16 or 32 bits) before pushing onto the stack. The type-declaration
character for Integer is % .
See Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Long (on page 511) (data type), Object (on page 546) (data type), Single (on
page 631) (data type), String (on page 654) (data type), Variant (on page 684) (data type),
Boolean (on page 272) (data type), DefType (on page 333) (statement), CInt (on page 285)
(function).
IPmt (function)
De Returns the interest payment for a given period of an annuity based on periodic, fixed payments
scrip and a fixed interest rate.
tion
Com An annuity is a series of fixed payments made to an insurance company or other investment
ments company over a period of time. Examples of annuities are mortgages, monthly savings plans,
and retirement plans. The following table describes the different parameters:
Pa Description
ra
me
ter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 480
Rate Double representing the interest rate per period. If the payment periods are monthly, be
sure to divide the annual interest rate by 12 to get the monthly rate.
Per Double representing the payment period for which you are calculating the interest pay
ment. If you want to know the interest paid or received during period 20 of an annuity, this
value would be 20.
Nper Double representing the total number of payments in the annuity. This is usually ex
pressed in months, and you should be sure that the interest rate given above is for the
same period that you enter here.
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 because that is the amount of cash you have in the
present. In the case of a retirement plan, this value would be the current value of the fund
because you have a set amount of principal in the plan.
Fv Double representing the future value of your annuity. In the case of a loan, the future val
ue would be zero because you will have paid it off. In the case of a savings plan, the fu
ture value would be the balance of the account after all payments are made.
Due Integer indicating when payments are due. If this parameter is 0, then payments are due
at the end of each period (usually, the end of the month). If this value is 1, then payments
are due at the start of each period (the beginning of the month).
Rate and Nper must be in expressed in the same units. If Rate is expressed in percentage paid
per month, then Nper must also be expressed in months. If Rate is an annual rate, then the peri
od given in Nper should also be in years or the annual Rate should be divided by 12 to obtain a
monthly rate. If the function returns a negative value, it represents interest you are paying out,
whereas a positive value represents interest paid to you.
Exam This example calculates the amount of interest paid on a $1,000.00 loan financed over 36
ple months with an annual interest rate of 10%. Payments are due at the beginning of the month.
The interest paid during the first 10 months is displayed in a table.
Sub Main()
msg1 = ""
For x = 1 to 10
ipm# = IPmt((.10/12),x,36,1000,0,1)
msg1 = msg1 & Format(x,"00") & " : " & Format(ipm#," 0,0.00") & crlf
Next x
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 481
MsgBox msg1
End Sub
See NPer (on page 542) (function); Pmt (on page 574) (function); PPmt (on page 576) (func
Also tion); Rate (on page 592) (function).
IRR (function)
De Returns the internal rate of return for a series of periodic payments and receipts.
scrip
tion
Com The internal rate of return is the equivalent rate of interest for an investment consisting of a se
ments ries 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 parameters:
Para Description
meter
Val Array of Double numbers that represent payments and receipts. Positive values are
ueAr payments, and negative values are receipts. There must be at least one positive and one
ray() 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.
Exam This example illustrates the purchase of a lemonade stand for $800 and a series of incomes
ple from the sale of lemonade over 12 months. The projected incomes for this example are generat
ed in two For...Next Loops, and then the internal rate of return is calculated and displayed. (Not
a bad investment!)
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 482
Dim valu#(12)
For x = 2 To 5
valu(x) = 100 + (x * 2)
Next x
For x = 6 To 12
Next x
retrn# = IRR(valu,.1)
msg1 = "The values: " & crlf & msg1 & crlf & crlf
End Sub
See Fv (on page 446) (function); MIRR (on page 519) (function); Npv (on page 543) (function);
Also Pv (on page 588) (function).
Is (operator)
De Returns True if the two operands refer to the same object; returns False otherwise.
scrip
tion
Com This operator is used to determine whether two object variables refer to the same object. Both
ments 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:
Exam This function inserts the date into a Microsoft Word document.
ple Sub InsertDate(ByVal WinWord As Object)
Else
WinWord.Insert Date$
End If
End Sub
Sub Main()
WinWord = CreateObject("word.basic")
InsertDate WinWord
End Sub
See Operator Precedence (on page 560) (topic); Like (on page 499) (operator).
Also
Plat All.
for
m(s)
Notes When comparing OLE automation objects, the Is operator will only return True if the operands
reference the same OLE automation object. This is different from data objects. For example, the
following use of Is (using the object class called excel.application ) returns True :
Dim a As Object
Dim b As Object
a = CreateObject("excel.application")
b = a
If a Is b Then Beep
The following use of Is will return False , even though the actual objects may be the same:
Dim a As Object
Dim b As Object
a = CreateObject("excel.application")
b = GetObject(,"excel.application")
If a Is b Then Beep
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 484
The Is operator may return False in the above case because, even though a and b reference
the same object, they may be treated as different objects by OLE 2.0 (this is dependent on the
OLE 2.0 server application).
IsDate (function)
De Returns True if expression can be legally converted to a date; returns False otherwise.
scrip
tion
Retry:
If IsDate(a) Then
Else
Goto Retry
End If
End Sub
See Al Variant (on page 684) (data type); IsEmpty (on page 484) (function); IsError (on page
so 485) (function); IsObject (on page 488) (function); VarType (on page 686) (function); Is
Null (on page 487) (function).
IsEmpty (function)
De Returns True if expression is a Variant variable that has never been initialized; returns False
scrip otherwise.
tion
If IsEmpty(a) Then
Else
End If
End Sub
See Al Variant (on page 684) (data type); IsDate (on page 484) (function); IsError (on page 485)
so (function); IsObject (on page 488) (function); VarType (on page 686) (function); IsNull (on
page 487) (function).
IsError (function)
De Returns True if expression is a user-defined error value; returns False otherwise.
scrip
tion
Ex This example creates a function that divides two numbers. If there is an error dividing the num
am bers, then a variant of type "error" is returned. Otherwise, the function returns the result of the divi
ple sion. The IsError function is used to determine whether the function encountered an error.
If b = 0 Then
Else
End If
End Function
Sub Main()
Dim a As Variant
a = Div(10,12)
If IsError(a) Then
Else
End If
End Sub
See Variant (on page 684) (data type); IsEmpty (on page 484) (function); IsDate (on page 484)
Also (function); IsObject (on page 488) (function); VarType (on page 686) (function); IsNull (on
page 487) (function).
IsMissing (function)
De Returns True if variable was passed to the current subroutine or function; returns False if
scrip omitted.
tion
Com The IsMissing is used with variant variables passed as optional parameters (using the Op
ments tional keyword) to the current subroutine or function. For non-variant variables or variables that
were not declared with the Optional keyword, IsMissing will always return True .
Exam The following function runs an application and optionally minimizes it. If the optional isMinimize
ple parameter is not specified by the caller, then the application is not minimized.
app = Shell(AppName)
AppMinimize app
Else
AppMaximize app
End If
End Sub
Sub Main
End Sub
See Declare (on page 333) (statement), Sub...End Sub (on page 657) (statement), Function...End
Also Function (statement) (on page 445)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 487
IsNull (function)
De Returns True if expression is a Variant variable that contains no valid data; returns False
scrip otherwise.
tion
a = Empty * Null
End Sub
See Empty (on page 399) (constant); Variant (on page 684) (data type); IsEmpty (on page 484)
Also (function); IsDate (on page 484) (function); IsError (on page 485) (function); IsObject (on
page 488) (function); VarType (on page 686) (function).
IsNumeric (function)
De Returns True if expression can be converted to a number; returns False otherwise.
scrip
tion
Com If passed a number or a variant containing a number, then IsNumeric always returns True . If
ments 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 .
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 488
If IsNumeric(s$) Then
Else
End If
End Sub
See Variant (on page 684) (data type); IsEmpty (on page 484) (function); IsDate (on page 484)
Also (function); IsError (on page 485) (function); IsObject (on page 488) (function); VarType (on
page 686) (function); IsNull (on page 487) (function).
IsObject (function)
De Returns True if expression is a Variant variable containing an Object ; returns False other
scrip wise.
tion
Exam This example will attempt to find a running copy of Excel and create 'a Excel object that can be
ple referenced as any other object in the Basic Control Engine.
Sub Main()
Dim v As Variant
Set v = GetObject(,"Excel.Application")
If IsObject(v) Then
MsgBox "The default object value is: " & v = v.Value 'Access value property of the object.
Else
End If
End Sub
See Variant (on page 684) (data type); IsEmpty (on page 484) (function); IsDate (on page 484)
Also (function); IsError (on page 485) (function); VarType (on page 686) (function); IsNull (on
page 487) (function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 489
IsWebSpaceSession (function)
Syntax IsWebSpaceSession
End Sub
Item$ (function)
De Returns all the items between first and last within the specified formatted text list.
scrip
tion
Pa Description
ra
me
ter
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 num
ber 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.
de String containing different item delimiters. By default, items are separated by commas
lim and end-of-lines. This can be changed by specifying different delimiters in the delimiters$
iters$ parameter.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 490
Exam This example creates two delimited lists and extracts a range from each, then displays the re
ple sult in a dialog box.
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 ItemCount (on page 490) (function); Line$ (on page 501) (function); LineCount (on page
Also 502) (function); Word$ (on page 705) (function); WordCount (on page 706) (function).
ItemCount (function)
De Returns an Integer containing the number of items in the specified delimited text.
scrip
tion
Com Items are substrings of a delimited text string. Items, by default, are separated by commas and/
ments or end-of-lines. This can be changed by specifying different delimiters in the delimiters$ para
meter. For example, to parse items using a backslash:
n = ItemCount(text$,"\")
Exam This example creates two delimited lists and then counts the number of items in each. The
ple counts are displayed in a dialog box.
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$,"/")
msg1 = "The first lists contains: " & l1% & " items." & crlf
msg1 = msg1 & "The second list contains: " & l2% & " items."
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 491
MsgBox msg1
End Sub
See Item$ (on page 489) (function); Line$ (on page 501) (function); LineCount (on page 502)
Also (function); Word$ (on page 705) (function); WordCount (on page 706) (function).
K
K
Keywords (top
ic)
Kill (statement)
Keywords (topic)
A keyword is any word or symbol recognized by the Basic Control Engine as part of the language. All of
the following are keywords:
Restrictions All keywords are reserved by the Basic Control Engine , 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.
Kill (statement)
Com The filespec$ argument can include wildcards, such as * and ? . The * character matches any
ments sequence of zero or more characters, whereas the ? character matches any single character.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 492
Multiple * 's and ? 's can appear within the expression to form complex searching patterns. The
following table shows some examples.
* (All files)
Exam This example looks to see whether file test1.dat exists. If it does not, then it creates both
ple test1.dat and test2.dat. The existence of the files is tested again; if they exist, a message is gen
erated, and then they are deleted. The final test looks to see whether they are still there and dis
plays the result.
Sub Main()
Close
End If
Kill "test?.dat"
End If
Else
End If
End Sub
L
L
LBound (function)
Len (function)
Let (statement)
Like (operator)
Line$ (function)
LineCount (function)
ListBox (statement)
Literals (topic)
Loc (function)
Lock (statement)
Lof (function)
Log (function)
LSet (statement)
LBound (function)
De Returns an Integer containing the lower bound of the specified dimension of the specified ar
scrip ray variable.
tion
Com The dimension parameter is an integer specifying the desired dimension. If this parameter is not
ments 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(object.property [,dimension])
LBound(object.method [,dimension])
ples 'This example dimensions two arrays and displays their lower bounds.
lba = LBound(a)
lbb = LBound(b,2)
MsgBox "The lower bound of a is: " & lba & " The lower bound of b is: " & lbb
Dim fl$()
FileList fl$,"*.*"
count = UBound(fl$)
If ArrayDims(a) Then
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
See UBound (on page 677) (function); ArrayDims (on page 249) (function); Arrays (on page
Also 250) (topic).
Com LCase$ returns a String , whereas LCase returns a String variant. Null is returned if text is
ments Null .
Example This example shows the LCase 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$))
End Sub
See Also UCase (on page 678), UCase$ (on page 678) (functions).
Function Returns
Left$ String
The length parameter is an Integer value specifying the number of characters to re
turn as follows.
Length is Returns
0 Zero-length string
Functions Return
Length is Returns
Com Left$ returns a String , whereas Left returns a String variant. NumChars is an Integer value
ments specifying the number of character to return. If NumChars is 0, then a zero-length string is re
turned. If NumChars is greater than or equal to the number of characters in the specified string,
then the entire string is returned. NULL is returned if text is NULL.
Exam This example shows the Left$ function used to change uppercase names to lowercase with an
ple uppercase first letter.
Sub Main()
lname$ = "WILLIAMS"
fl$ = Left(lname$,1)
rest$ = Mid(lname$,2,Len(lname$))
End Sub
Len (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 497
De Returns the number of characters in expression or the number of bytes required to store the
scrip specified variable.
tion
Com If expression evaluates to a string, then Len returns the number of characters in a given string
ments 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. If
used with a non-String or non- Variant variable, the function returns the number of bytes oc
cupied by that data element. When used with user-defined data types, the function returns 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 ta
ble describes the sizes of the individual data elements:
Data Size
Ele
ment
Integer 2 bytes
Long 4 bytes
Float 4 bytes
Dou 8 bytes.
ble
Cur 8 bytes
rency
Ob 0 bytes. Both data object variables and variables of type Object are always returned as
jects 0 size.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 498
User- Combined size of each structure member. Variable-length strings within structures re
de quire 2 bytes of storage. Arrays within structures are fixed in their dimensions. The ele
fined ments for fixed arrays are stored within the structure and therefore require the number
type of bytes for each array element multiplied by the size of each array dimension: elemen
t_size * dimension1 * dimension2...
The Len function always returns 0 with object variables or any data object variable.
lname$ = "WILLIAMS"
fl$ = Left(lname$,1)
ln% = Len(lname$)
rest$ = Mid(lname$,2,ln%)
MsgBox "The proper case for " & lname$ & " is " & nname$ & "."
Dim lns(4)
lns(1) = Len(a%)
lns(2) = Len(b&)
lns(3) = Len(c!)
lns(4) = Len(d#)
msg1 = "Lengths (in bytes) of standard types:" & crlf & crlf
MsgBox msg1
End Sub
Let (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 499
Com The use of the word Let is supported for compatibility with other implementations of the Ba
ments sic Control Engine. Normally, this word is dropped. 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 hap
pens when the larger type contains a numeric quantity that cannot be represented by the small
er type. For example, the following code will produce a runtime error:
im quantity As Integer
Let b% = 100
Let c# = 1213.3443
End Sub
See = (on page 226) (keyword); Expression Evaluation (on page 421) (topic).
Also
Like (operator)
De Compares two strings and returns TRUE if the expression matches the given pattern; returns
scrip FALSE otherwise.
tion
Com Case sensitivity is controlled by the Option Compare setting. The pattern expression can con
ments tain special characters that allow more flexible matching:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 500
Character Evaluates to
[!range] Matches if the character in question is not within the specified range.
b$ = "123.45"
End Sub
See Operator Precedence (on page 560) (topic); Is (on page 482) (operator); Option Compare (on
Also page 562) (statement).
Com The filenumber parameter is a number that is used to refer to the open file¾the number passed
ments to the Open statement. The filenumber must reference a file opened in Input mode. The file is
read up to the next end-of-line, but the end-of-line character(s) is (are) not returned in the string.
The file pointer is positioned after the terminating end-of-line.
The variable parameter is any string or variant variable reference. This statement will automat
ically declare the variable if the specified variable has not yet been used or dimensioned. This
statement recognizes either a single line feed or a carriage-return/line-feed pair as the end-of-
line delimiter.
Exam This example reads five lines of the autoexec.bat file and displays them in a dialog box.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
file$ = "c:\autoexec.bat"
msg1 = ""
For x = 1 To 5
Next x
MsgBox "The first 5 lines of '" & file$ & "' are:" & crlf & crlf & msg1
End Sub
See Open (on page 554) (statement); Get (on page 447) (statement); Input# (on page 471)
Also (statement); Input, Input$ (on page 473) (functions).
Line$ (function)
Syn Line$(text$,first[,last])
tax
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 502
De Returns a String containing a single line or a group of lines between first and last.
scrip
tion
Com Lines are delimited by carriage return, line feed, or carriage-return/line-feed pairs. The Line$
ments function takes the following parameters:
Pa Description
ra
me
ter
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.
Exam This example reads five lines of the autoexec.bat file, extracts the third and fourth lines with the
ple Line$ function, and displays them in a dialog box.
Sub Main()
file$ = "c:\autoexec.bat"
txt = ""
For x = 1 To 5
Next x
lines$ = Line$(txt,3,4)
MsgBox "The 3rd and 4th lines of '" & file$ & "' are:" & crlf_
End Sub
See Item$ (on page 489) (function); ItemCount (on page 490) (function); LineCount (on page
Also 502) (function); Word$ (on page 705) (function); WordCount (on page 706) (function).
LineCount (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 503
Example This example reads your autoexec.bat file into a variable and then determines how many
lines it is comprised of.
Sub Main()
file$ = "c:\autoexec.bat"
txt = ""
Do Until Eof(1)
Loop
lines! = LineCount(txt)
MsgBox "'" & file$ & "' is " & lines! & " lines long!" & crlf_
End Sub
See Also Item$ (on page 489) (function); ItemCount (on page 490) (function); Line$ (on page
501) (function); Word$ (on page 705) (function); WordCount (on page 706) (function).
Line numbers are not supported by the Basic Control Engine. As an alternative to line numbers, you can
use meaningful labels as targets for absolute jumps, as shown below:
Sub Main()
Dim i As Integer
i = 0
LoopTop:
i = i + 1
MyErrorTrap:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 504
End Sub
ListBox (statement)
Com When the dialog box is invoked, the list box will be filled with the elements contained in Array
ments Variable. This statement can only appear within a dialog box template (that is, between the Be
gin Dialog and End Dialog statements). The ListBox statement requires the following para
meters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Array Specifies a single-dimensioned array of strings used to initialize the elements of the list
Vari box. If this array has no dimensions, then the list box will be initialized with no elements.
able A runtime error results if the specified array contains more than one dimension. Array
Variable can specify an array of any fundamental data type (structures are not allowed).
Null and Empty values are treated as zero-length strings.
Identi Name by which this control can be referenced by statements in a dialog function (such
fier as DlgFocus and DlgEnable ). This parameter also creates an integer variable whose
value corresponds to the index of the list box's selection (0 is the first item, 1 is the sec
ond, and so on). This variable can be accessed using the following syntax: DialogVari
able . Identifier
Exam This example creates a dialog box with two list boxes, one containing files and the other con
ple taining directories.
Sub Main()
Text 8,4,24,8,"&Files:"
ListBox 8,16,60,72,files$,.Files
Text 76,4,21,8,"&Dirs:"
ListBox 76,16,56,72,dirs$,.Dirs
OKButton 140,4,40,14
CancelButton 140,24,40,14
End Dialog
FileList files
FileDirs dirs
rc% = Dialog(ListBoxDialog)
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); OK
Button (on page 551) (statement); OptionButton (on page 564) (statement); OptionGroup
(on page 566) (statement); Picture (on page 570) (statement); PushButton (on page 572)
(statement); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on
page 269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
Literals (topic)
Literals are values of a specific type. The following table shows the different types of literals supported by
the Basic Control Engine:
Literal Description
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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 506
# Double
! Single
5.5 Dou Value is 5.5. Any number with decimal point is considered a double.
ble
"""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 envi
ronment. To ensure that date literals are correctly interpreted for all locales, use the inter
national date format: #YYYY-MM-DD HH:MM:SS# Constant Folding The Basic Control En
gine supports constant folding where constant expressions are calculated by the compiler
at compile time. For example, the expression i% = 10 + 12 is the same as: i% = 22 Simi
larly, with strings, the expression s$ = "Hello," + " there" + (46) is the same as: s$ = "Hel
lo, there."
Loc (function)
De Returns a Long representing the position of the file pointer in the given file.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 507
Com The filenumber parameter is an Integer used by the Basic Control Engine to refer to the number
ments passed by the Open statement to the Basic Control Engine . The Loc function returns different
values depending on the mode in which the file was opened:
Exam This example reads 5 lines of the autoexec.bat file, determines the current location of the file
ple pointer, and displays it in a dialog box.
Sub Main()
file$ = "c:\autoexec.bat"
For x = 1 To 5
Next x
lc% = Loc(1)
Close
End Sub
See Seek (on page 618) (function); Seek (on page 619) (statement); FileLen (on page 429)
Also (function).
Lock (statement)
De Locks a section of the specified file, preventing other processes from accessing that section of
scrip the file until the Unlock statement is issued.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 508
Parameter Description
filenumber Integer used by the Basic Control Engine to refer to the open file—the number
passed to the Open statement.
For sequential files, the record, start, and end parameters are ignored. The entire file is locked.
The section of the file is specified using one of the following:
Syntax Description
record Locks the specified record number (for Random files) or byte (for Binary files).
to end Locks from the beginning of the file to the specified record (for Random files) or
byte (for Binary files).
start to Locks the specified range of records (for Random files) or bytes (for Binary files).
end
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 the Basic Control Engine when your script terminates, which can cause file
access problems for other processes. It is a good idea to group the Lock and Unlock state
ments 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.
Exam This example creates test.dat and fills it with ten string variable records. These are displayed in
ple a dialog box. The file is then reopened for read/write, and each record is locked, modified, rewrit
ten, and unlocked. The new records are then displayed in a dialog box.
Sub Main()
b$ = "0"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 509
rec$ = ""
msg1 = ""
For x = 1 To 10
rec$ = a$ & x
Lock #1,x
Put #1,,rec$
Unlock #1,x
Next x
Close
msg1 = ""
For x = 1 To 10
Lock #1,x
Put #1,x,rec$
Unlock #1,x
Next x
Close
Kill "test.dat"
End Sub
See Unlock (on page 679) (statement); Open (on page 554) (statement).
Also
Lof (function)
De Returns a Long representing the number of bytes in the given file.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 510
Com The filenumber parameter is an Integer used by the Basic Control Engine to refer to the open
ments file, the number passed to the Open statement. The file must currently be open.
Exam This example creates a test file, writes ten records into it, then finds the length of the file and
ple displays it in a message box.
Sub Main()
msg1 = ""
For x = 1 To 10
rec$ = a$ & x
put #1,,rec$
Next x
Close
r% = Lof(1)
Close
End Sub
See Loc (on page 506) (function); Open (on page 554) (statement); FileLen (on page 429)
Also (function).
Log (function)
Comments The value of number must be a Double greater than 0. The value of e is
2.71828.
Example This example calculates the natural log of 100 and displays it in a message box.
Sub Main()
x# = Log(100)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 511
End Sub
Syn Long
tax
De Long variables are used to hold numbers (with up to ten digits of precision) within the following
scrip range:
tion –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-dec
laration character for Long is & .
See Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Integer (on page 479) (data type); Object (on page 546) (data type); Single (on
page 631) (data type); String (on page 654) (data type); Variant (on page 684) (data type);
Boolean (on page 272) (data type); DefType (on page 333) (statement); CLng (on page 293)
(function).
LSet (statement)
tax 1
tax 2
De Left-aligns the source string in the destination string or copies one user-defined type to another.
scrip
tion
Com Syntax 1 The LSet statement copies the source string source into the destination string dest.
ments The dest parameter must be the name of either a String or Variant variable. The source para
meter 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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 512
characters that will fit in dest. 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 . 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.
Exam This example replaces a 40-character string of asterisks (*) with an RSet and LSet string and
ple then displays the result.
Sub Main()
Dim msg,tmpstr$
tmpstr$ = String(40,"*")
msg1 = "Here are two strings that have been right-" + crlf
MsgBox msg1
End Sub
Syntax LTrim[$](text)
Com LTrim$ returns a String , whereas LTrim returns a String variant. Null is returned if text
ments is Null .
Example This example displays a right-justified string and its LTrim result. Const crlf = Chr$(13) + Chr
$(10)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 513
Sub Main()
tr$ = LTrim(txt$)
MsgBox "Original ->" & txt$ & "<-" & crlf & "Left Trimmed ->" & tr$ & "<-"
End Sub
See Also RTrim, RTrim$ (on page 609) (functions); Trim, Trim$ (on page 671) (functions).
M
M
Main (statement)
MCI (function)
Minute (function)
MIRR (function)
MkDir (statement)
Mod (operator)
Month (function)
Msg.Close (method)
Msg.Open (method)
Msg.Text (property)
Msg.Thermometer (property)
MsgBox (function)
MsgBox (statement)
Main (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 514
End Sub
End Sub
MCI (function)
De Executes an Mci command, returning an Integer indicating whether the command was suc
scrip cessful.
tion
Para Description
me
ter
re String variable into which the result is placed. If the command doesn't return anything,
sult$ then a zero-length string is returned. To ignore the returned string, pass a zero-length
string, such as. r% = Mci("open chimes.wav type waveaudio","")
er Optional String variable into which an error string will be placed. A zero-length string will
ror$ be returned if the function is successful.
Exam This first example plays a wave file. The wave file is played to completion before execution can
ple 1 continue.
Sub Main()
Dim rc As Integer
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 515
rc = Mci("open " & Filename & " type waveaudio alias CoolSound","",ErrorMessage)
If (rc) Then
MsgBox ErrorMessage
Exit Sub
End If
End Sub
Exam This next example shows how to query an Mci device and play an MIDI file in the background.
ple 2 Sub Main()
Dim rc As Integer
If rc Then
MsgBox ErrorMessage
Exit Sub
End If
'Can it play?
Exit Sub
End If
rc = Mci("open " & Filename & " type sequencer alias song",result$,ErrMsg)
If rc Then
MsgBox ErrMsg
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 516
xit Sub
End If
rc = Mci("close song","","")
End Sub
De Returns a sub-string of the specified string, beginning with start, for length characters (for Mid
scrip and Mid$) or bytes (for MidB and MidB$).
tion
Mid and Sub-string starting at character position start and will be length characters long
Mid$
MidB Sub-string starting at byte position start and will be length bytes long.
and
MidB$
Func Return
tions
Mid$ String
and
MidB
The returned sub-string starts at character position start and will be length characters long. Mid
$ returns a String , whereas Mid returns a String variant. The Mid/Mid$ functions take the
following parameters:
Parame Description
ter
string Any String expression containing the text from which data is returned.
start Integer specifying the position where the sub-string 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 text is Null . The MidB and MidB$ functions are used to re
turn a sub-string of bytes from a string containing byte data.
Exam
ple 'This example displays a substring from the middle of a
'first four characters with "NEW " using the Mid$ statement.
Sub Main()
b$ = Mid$(a$,13,Len(a$))
End Sub
See InStr, InStrB (on page 476) (functions), Option Compare (on page 562) (statement), Mid, Mid
Also $, MidB, MidB$ (on page 517) (statements)
Parame Description
ter
start Integer specifying the character position (for Mid and Mid$) or byte position (for MidB
and MidB$) within variable where replacement begins. If start is greater than the
length of variable, then variable remains unchanged.
length Integer specifying the number of characters or bytes to change. If this parameter is
omitted, then the entire string is changed, starting at start.
newval Expression used as the replacement. This expression must be convertible to a String.
ue
The resultant string is never longer than the original length of variable. With Mid and MidB, vari
able must be a Variant variable convertible to a String, and newvalue is any expression convert
ible to a string. A runtime error is generated if either variant is NULL. Statements are used to re
place the following.
Statement Replaces
Exam
ple 'This example displays a substring from the middle of a
'first four characters with "NEW " using the Mid$ statement.
Sub Main()
b$ = Mid$(a$,13,Len(a$))
See Mid, Mid$, MidB, MidB$ (on page 516) (functions), Option Compare (on page 562) (state
Also ment)
Minute (function)
De Returns the minute of the day encoded in the specified time parameter.
scrip
tion
Com The value returned is as an Integer between 0 and 59 inclusive. The time parameter is any ex
ments pression that converts to a Date .
Exam This example takes the current time; extracts the hour, minute, and second; and displays them
ple as the current time.
Sub Main()
Msgbox "It is now minute " & Minute(Time) & " of the hour."
End Sub
See Day (on page 322) (function); Second (on page 617) (function); Month (on page 522)
Also (function); Year (on page 710) (function); Hour (on page 461) (function); Weekday (on page
692) (function); DatePart (on page 319) (function).
MIRR (function)
De Returns a Double representing the modified internal rate of return for a series of periodic pay
scrip ments and receipts.
tion
Com The modified internal rate of return is the equivalent rate of return on an investment in which
ments 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. The
MIRR function requires the following parameters:
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 520
Val Array of Double numbers representing the payments and receipts. Positive values are
ueAr payments (invested capital), and negative values are receipts (returns on investment).
ray() There must be at least one positive (investment) value and one negative (return) value.
Fi Double representing the interest rate paid on invested monies (paid out).
nance
Rate
Rein Double representing the rate of interest received on incomes from the investment (re
vest ceipts).
Rate
Exam This example illustrates the purchase of a lemonade stand for $800 financed with money bor
ple rowed at 10%. The returns are estimated to accelerate as the stand gains popularity. The pro
ceeds are placed in a bank at 9 percent interest. The incomes are estimated (generated) over 12
months. This program first generates the income stream array in two For...Next loops, and then
the modified internal rate of return is calculated and displayed. Notice that the annual rates are
normalized to monthly rates by dividing them by 12.
Sub Main()
Dim valu#(12)
For x = 2 To 5
Next x
For x = 6 To 12
Next x
msg1 = "The values: " & crlf & msg1 & crlf & crlf
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 521
End Sub
See Fv (on page 446) (function); IRR (on page 481) (function); Npv (on page 543) (function); Pv
Also (on page 588) (function).
MkDir (statement)
Ex This example creates a new directory on the default drive. If this causes an error, then the error is
am displayed and the program terminates. If no error is generated, the directory is removed with the
ple RmDir statement.
Sub Main()
MkDir "testdir"
Else
RmDir "testdir"
End If
End Sub
See ChDir (on page 280) (statement); ChDrive (on page 280) (statement); CurDir, CurDir$ (on page
Also 308) (functions); Dir, Dir$ (on page 339) (functions); RmDir (on page 606) (statement).
Mod (operator)
Com If both expressions are integers, then the result is an integer. Otherwise, each expression is con
ments verted 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.
Exam This example uses the Mod operator to determine the value of a randomly selected card where
ple card 1 is the ace (1) of clubs and card 52 is the king (13) of spades. Since the values recur in a
sequence of 13 cards within 4 suits, we can use the Mod function to determine the value of any
given card number.
Sub Main()
cval$ = "Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King"
Randomize
card% = Random(1,52)
CardNum$ = Item$(cval,value)
msg1 = "Card number " & card% & " is the "
MsgBox msg1
End Sub
Month (function)
De Returns the month of the date encoded in the specified date parameter.
scrip
tion
Com The value returned is as an Integer between 1 and 12 inclusive. The date parameter is any ex
ments pression that converts to a Date .
mons$ = "Jan.,Feb.,Mar.,Apr.,May,Jun.,Jul.,Aug.,Sep.,Oct.,Nov.,Dec."
tdate$ = Date$
tmonth! = Month(DateValue(tdate$))
End Sub
See Day (on page 322) (function) Minute (on page 519) (function); Second (on page 617)
Also (function); Year (on page 710) (function); Hour (on page 461) (function); Weekday (on page
692) (function); DatePart (on page 319) (function).
Msg.Close (method)
Syntax Msg.Close
Sleep 3000
Msg.Close
End Sub
See Also Msg.Open (on page 523) (method); Msg.Thermometer (on page
526) (property); Msg.Text (on page 525) (property).
Msg.Open (method)
De Displays a message in a dialog box with an optional Cancel button and thermometer.
scrip
tion
Para Description
meter
prompt String containing the text to be displayed. The text can be changed using the Msg.Text
property.
time Integer specifying the number of seconds before the dialog box is automatically re
out moved. The timeout parameter has no effect if its value is 0.
cancel Boolean controlling whether or not a Cancel button appears within the dialog box be
neath the displayed message. If this parameter is True, then a Cancel button appears.
If it is not specified or False, then no Cancel button is created. If a user chooses the
Cancel button at runtime, a trappable runtime error is generated (error number 18). In
this manner, a message dialog box can be displayed and processing can continue as
normal, aborting only when the user cancels the process by choosing the Cancel but
ton.
ther Boolean controlling whether the dialog box contains a thermometer. If this parameter
mome is True, then a thermometer is created between the text and the optional Cancel button.
ter The thermometer initially indicates 0% complete and can be changed using the Ms
g.Thermometer property.
XPos, Integer coordinates specifying the location of the upper left corner of the message box,
YPos in twips (twentieths of a point). If these parameters are not specified, then the window
is centered on top of the application.
Unlike other dialog boxes, a message dialog box remains open until the user selects Cancel, the
timeout has expired, or the Msg.Close method is executed (this is sometimes referred to as
modeless). Only a single message window can be opened at any one time. The message win
dow is removed automatically when a script terminates. The Cancel button, if present, can be
selected using either the mouse or keyboard. However, these events will never reach the mes
sage dialog unless you periodically call DoEvents from within your script.
Sub Main()
Sleep 3000
Msg.Close
For x = 1 to 100
Msg.Thermometer = x
Next x
Sleep 1000
Msg.Close
End Sub
See Msg.Close (on page 523) (method); Msg.Thermometer (on page 526) (property); Msg.Text
Also (on page 525) (property).
Msg.Text (property)
De Changes the text within an open message dialog box (one that was previously opened with the
scrip Msg.Open method).
tion
Com The message dialog box is not resized to accommodate the new text. A runtime error will result
ments if a message dialog box is not currently open (using Msg.Open ).
Exam This example creates a modeless message box, leaving room in the message text for the record
ple number. This box contains a Cancel button.
Sub Main()
For i = 1 To 100
Sleep 100
Next i
Msg.Close
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 526
See Msg.Close (on page 523) (method); Msg.Open (on page 523) (method); Msg.Thermometer
Also (on page 526) (property).
Msg.Thermometer (property)
De Changes the percentage filled indicated within the thermometer of a message dialog box (one
scrip that was previously opened with the Msg.Open method).
tion
Com A runtime error will result if a message box is not currently open (using Msg.Open ) or if the val
ments ue of percentage is not between 0 and 100 inclusive.
Exam This example create a modeless message box with a thermometer and a Cancel button. This
ple example also shows how to process the clicking of the Cancel button.
Sub Main()
Msg.Thermometer =i
DoEvents
Sleep 50
Next i
Msg.Close
Exit Sub
ErrorTrap:
End If
End Sub
See Msg.Close (on page 523) (method); Msg.Open (on page 523) (method); Msg.Text (on page
Also 525) (property).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 527
MsgBox (function)
De Displays a message in a dialog box with a set of predefined buttons, returning an Integer repre
scrip senting which button was selected.
tion
Com
Important:
ments
The message box has an approximate maximum allowed number of characters.
The:
It is estimated that on a 1280x800 resolution approximately 128 characters fit in the message
box. The estimation is based on the fact that some letters/numbers/symbols require more than
one character space (e.g. M); some less (e.g. i). Therefore the exact allowed number of charac
ters depends on what numbers/letters/symbols are used in the message.
Parameter Description
title Caption of the dialog box. This parameter is any expression convertible to a
String. If it is omitted, then the script is used. A runtime error is generated if title
is Null .
ebOK 1 OK
ebCancel 2 Cancel
ebAbort 3 Abort
ebRetry 4 Retry
ebIgnore 5 Ignore
ebYes 6 Yes
ebNo 7 No
ebOKOnly 0 OK button
The default value for type is 0 (display only the OK button, making it the default). Breaking Text
across Lines The msg parameter can contain end-of-line characters, forcing the text that fol
lows to start on a new line. The following example shows how to display a string on two lines:
r = MsgBox("Hello, World")
ebExclamation,"Simple"
ebOkCancel,"MsgBox"
MsgBox "This message box has Abort, Retry, and Ignore buttons.",_
ebAbortRetryIgnore,"MsgBox"
MsgBox "This message box has Yes, No, and Cancel buttons.",_
ebYesNoCancel Or ebDefaultButton2,"MsgBox"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 530
ebRetryCancel,"MsgBox"
End Sub
See AskBox$ (on page 254) (function); AskPassword$ (on page 256) (function); InputBox, Input
Also Box$ (on page 474) (functions); OpenFilename$ (on page 558) (function); SaveFilename$
(on page 611) (function); SelectBox (on page 622) (function); AnswerBox (on page 231)
(function).
Note MsgBox displays all text in its dialog box in 8-point MS Sans Serif.
MsgBox (statement)
De This command is the same as the MsgBox function, except that the statement form does not re
scrip turn a value. See MsgBox (function).
tion
ple MsgBox "The result is: " & (10 * 45) 'Display a number.
End Sub
See AskBox$ (on page 254) (function); AskPassword$ (on page 256) (function); Input, Input$, In
Also putB, InputB$ (on page 473) (functions); OpenFilename$ (on page 558) (function); SaveFile
name$ (on page 611) (function); SelectBox (on page 622) (function); AnswerBox (on page
231) (function).
N
N
Name (statement)
Net.AddCon (method)
Net.Browse$ (method)
Net.CancelCon (method)
Net.GetCaps (method)
Net.GetCon$ (method)
Net.User$ (property)
New (keyword)
Not (operator)
Nothing (constant)
Now (function)
NPer (function)
Npv (function)
Null (constant)
Name (statement)
Com Each parameter must specify a single filename. Wildcard characters such as * and ? are not
ments allowed. Some platforms allow naming of files to different directories on the same physical disk
volume. For example, the following rename will work under Windows:
You cannot rename files across physical disk volumes. For example, the following will error un
der Windows:
To rename a file to a different physical disk, you must first copy the file, then erase the original:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 532
Exam This example creates a file called test.dat and then renames it to test2.dat.
ple Sub Main()
oldfile$ = "test.dat"
newfile$ = "test2.dat"
If FileExists(oldfile$) Then
Else
msg1 = "'" & oldfile$ & "' was renamed to '" & newfile$ & "'"
End If
Else
Close
msg1 = "'" & oldfile$ & "' not created. The following error occurred: " & Error(Err)
Else
msg1 = "'" & oldfile$ & "' was created and renamed to '" & newfile$ & "'"
End If
End If
MsgBox msg1
End Sub
See Kill (on page 491) (statement), FileCopy (on page 426) (statement).
Also
Many language elements in BasicScript support named parameters. Named parameters allow you to
specify parameters to a function or subroutine by name rather than in adherence to a predetermined
order. The following table contains examples showing various calls to MsgBox both using parameter by
both name and position.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 533
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:
Net.AddCon (method)
De Redirects a local device (a disk drive or printer queue) to the specified shared device or remote
scrip server. The new syntax does not affect previously compiled code. If Password is not speci
tion fied, then the default password is used. If empty, then no password is used. If LocalName is
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 534
not specified, then the a connection is made to the network resource without redirecting the lo
cal device. The UserName parameter specifies the name of the user making the connection. If
UserName is not specified, then the default user for that process is used. The isPermanent pa
rameter specifies whether the connection should be restored during subsequent logon opera
tions. Only a successful connection will persist in this manner.
Para Description
me
ter
net String containing the name of the shared device or the name of a remote server. This
path$ parameter can contain the name of a shared printer queue (such as that returned by
Net.Browse[1] ) or the name of a network path (such as that returned by Net.Browse[0]
).
pass String containing the password for the given device or server. This parameter is mainly
word$ used to specify the password on a remote server.
local String containing the name of the local device being redirected, such as "LPT1" or "D:".
name$
Exam This example sets N: so that it refers to the network path SYS:\PUBLIC.
ple Sub Main()
Net.AddCon "SYS:\PUBLIC","","N:"
End Sub
See Net.CancelCon (on page 535) (method); Net.GetCon$ (on page 538) (method)
Also
Net.Browse$ (method)
De Calls the currently installed network's browse dialog box, requesting a particular type of informa
scrip tion.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 535
Com The type parameter is an Integer specifying the type of dialog box to display:
ments
Type Description
0 If type is 0, then this method displays a dialog box that allows the user to browse network
volumes and directories. Choosing OK returns the completed pathname as a String.
1 If type is 1, then this function displays a dialog box that allows the user to browse the net
work'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 Net.AddCon method.
This dialog box differs depending on the type of network installed. A runtime error will result if
no network is present.
s$ = Net.Browse$(0)
Else
End If
End Sub
Net.CancelCon (method)
De The isForce parameter is True if missing or omitted. The isPermanent parameter indicates if the
scrip disconnection should persist to subsequent logon operations. On all platforms, the Connection
tion parameter specifies what is to be disconnected. If Connection specifies a local device, then on
ly that device is disconnected. If Connection specifies a remote device, then all local devices at
tached to that remote device are disconnected. Cancels a network connection.
Para Description
meter
connec String containing the name of the device to cancel, such as "LPT1" or "D:".
tion$
isForce Boolean specifying whether to force the cancellation of the connection if there are
open files or open print jobs.
• If this parameter is True, then this method will close all open files and open
print jobs before the connection is closed.
• If this parameter is False, this the method will issue a runtime error if there are
any open files or open print jobs.
Exam This example deletes the drive mapping associated with drive N:.
ple Sub Main()
Net.CancelCon "N:"
End Sub
See Net.AddCon (on page 533) (method); Net.GetCon$ (on page 538) (method).
Also
Net.GetCaps (method)
De Returns an Integer specifying information about the network and its capabilities.
scrip
tion
Para Description
meter
type Integer specifying what type of information to retrieve. This parameter is different from
platform to platform.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 537
local String specifying the name of the local device to which is attached to the network de
name$ vice to be queried. If this parameter is missing, then information about the first network
device is returned.
Val Description
ue
1 Always returns 0.
2 Network type:
0 No network is installed.
1 Microsoft Network
3 Novell NetWare.
4 Banyan Vines
5 10Net
6 Locus
7 SunSoft PC NFS.
8 LanStep
9 9 Titles.
10 Articom Lantastic
11 IBM AS/400
13 DEC Pathworks
Version of the network with the major version in the high byte and the minor version in the low
byte: Major = Net.GetCaps(2) \ 256 Minor = Net.GetCaps(2) And &H00FF
Exam
ple Sub Main()
'user name.
'boxes.
End Sub
Net.GetCon$ (method)
De Returns the name of the network resource associated with the specified redirected local device.
scrip
tion
Com The localname$ parameter specifies the name of the local device, such as "LPT1" or "D:". The
ments function returns a zero-length string if the specified local device is not redirected. A runtime er
ror will result if no network is present.
NetPath$ = Net.GetCon$("Z:")
End Sub
See Net.CancelCon (on page 535) (method); Net.AddCon (on page 533) (method).
Also
Net.User$ (property)
Com A runtime error is generated if the network is not installed. The LocalName parameter is the
ments name of the local device that the user has made a connection to. If this parameter is omitted,
then the name of the current user of the process is used. If Localname is a network name and
the user is connected to that resource using different names, the network provider may not
be able to resolve which user name to return. In this case, the provider may make an arbitrary
choice from the possible user names.
Net.User$
End Sub
New (keyword)
De Creates a new instance of the specified object type, assigning it to the specified object variable.
scrip
tion
Com The New keyword is used to declare a new instance of the specified data object. This keyword
ments 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 cre
ating a new physical object (within the appropriate context) and returning a reference to that ob
ject, which is immediately assigned to the variable being declared. When that variable goes out
of scope (that is, 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 destroy
ing the physical object.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 540
See Dim (on page 338) (statement); Set (on page 626) (statement).
Also
Not (operator)
TRUE FALSE
FALSE TRUE
NULL NULL
Any nu A binary negation of the number. If the number is an Integer, then an Integer is re
meric turned. Otherwise, the expression is first converted to a Long, then a binary negation is
type performed, returning a Long.
Exam This example demonstrates the use of the Not operator in comparing logical expressions and
ple for switching a True/False toggle variable.
Sub Main()
a = False
b = True
toggle% = True
msg1 = msg1 & "toggle% is now " & CBool(toggle%) & crlf
msg1 = msg1 & "toggle% is now " & CBool(toggle%) & crlf
MsgBox msg1
End Sub
See Boolean (on page 272) (data type); Comparison Operators (on page 297) (topic).
Also
Nothing (constant)
Description A value indicating that an object variable no longer references a valid ob
ject.
Dim a As Object
If a Is Nothing Then
Else
End If
End Sub
See Also Set (on page 626) (statement); Object (on page 546) (data type).
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
t2# = Now
MsgBox "Elapsed time was: " & t3# & " seconds."
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 542
See Also Date, Date$ (on page 314) (functions); Time, Time$ (on page 668) (functions).
NPer (function)
De Returns the number of periods for an annuity based on periodic fixed payments and a constant
scrip rate of interest.
tion
Com An annuity is a series of fixed payments paid to or received from an investment over a period of
ments time. Examples of annuities are mortgages, retirement plans, monthly savings plans, and term
loans. The NPer function requires the following parameters:
Pa Description
ra
me
ter
Rate Double representing the interest rate per period. If the periods are monthly, be sure to nor
malize annual rates by dividing them by 12.
Pmt Double representing the amount of each payment or income. Income is represented by
positive values, whereas payments are represented by negative values.
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, and the future value (see below) would be zero.
Fv Double representing the future value of your annuity. In the case of a loan, the future value
would be zero, and the present value would be the amount of the loan.
Due Integer indicating when payments are due for each payment period. A 0 specifies pay
ment at the end of each period, whereas a 1 indicates payment at the start of each peri
od.
Positive numbers represent cash received, whereas negative numbers represent cash paid out.
Exam This example calculates the number of $100.00 monthly payments necessary to accumulate
ple $10,000.00 at an annual rate of 10%. Payments are made at the beginning of the month.
Sub Main()
ag# = NPer((.10/12),100,0,10000,1)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 543
End Sub
See IPmt (on page 479) (function); Pmt (on page 574) (function); PPmt (on page 576) (func
Also tion); Rate (on page 592) (function).
Npv (function)
De Returns the net present value of an annuity based on periodic payments and receipts, and a dis
scrip count rate.
tion
Pa Description
ra
me
ter
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.
Val Array of Double numbers representing the payments and receipts. Positive values are
ue payments, and negative values are receipts. There must be at least one positive and one
Ar negative value.
ray()
Positive numbers represent cash received, whereas negative numbers represent cash paid out.
For accurate results, be sure to enter your payments and receipts in the correct order because
Npv uses the order of the array values to interpret the order of the payments and receipts. If
your first cash flow occurs at the beginning of the first period, that value must be added to the
return value of the Npv function. It should not be included in the array of cash flows. Npv dif
fers from the Pv function in that the payments are due at the end of the period and the cash
flows are variable. Pv 's cash flows are constant, and payment may be made at either the begin
ning or end of the period.
Exam This example illustrates the purchase of a lemonade stand for $800 financed with money bor
ple rowed at 10%. The returns are estimated to accelerate as the stand gains popularity. The in
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 544
comes are estimated (generated) over 12 months. This program first generates the income
stream array in two For...Next loops, and then the net present value (Npv) is calculated and dis
played. Note normalization of the annual 10% rate.
Sub Main()
Dim valu#(12)
valu(x) = 100 + (x * 2)
Next x
Next x
NetVal# = NPV((.10/12),valu)
msg1 = "The values:" & crlf & msg1 & crlf & crlf
End Sub
See Fv (on page 446) (function); IRR (on page 481) (function); MIRR (on page 519) (function);
Also Pv (on page 588) (function).
Null (constant)
Com The Null value has special meaning indicating that a variable contains no data. Most numeric
ments operators return Null when either of the arguments is Null . This "propagation" of Null makes
it especially useful for returning error values through a complex expression. For example, you
can write functions that return Null when an error occurs, then call this function within an ex
pression. You can then use the IsNull function to test the final result to see whether an error
occurred during calculation. Since variants are Empty by default, the only way for Null to ap
pear within a variant is for you to explicitly place it there. Only a few functions return this value.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 545
a = Null
End Sub
O
O
Objects (topic)
OKButton (statement)
On Error (statement)
Open (statement)
OpenFilename$ (function)
Operator Precision(topic)
OptionButton (statement)
OptionGroup (statement)
Or (operator)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 546
Syn Object
tax
Com The Object type is used to declare variables that reference objects within an application using
ments OLE automation. Each object is a 4-byte (32-bit) value that references the object internally. The
value 0 (or Nothing ) indicates that the variable does not reference a valid object, as is the case
when the object has not yet been given a value. Accessing properties or methods of such Ob
ject variables generates a runtime error.
Using Objects Object variables are declared using the Dim, Public, or Private statement:
Object variables can be assigned values (thereby referencing a real physical object) using the
Set statement:
MyApp.Color = 10
i% = MyApp.Color
Methods of an Object are also accessed using the dot (.) separator:
MyApp.Open "sample.txt"
isSuccess = MyApp.Save("new.txt",15)
Automatic Destruction The Basic Control Engine keeps track of the number of variables that ref
erence a given object so that the object can be destroyed when there are no longer any refer
ences to it:
Set b = a '2
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 547
Note An OLE automation object is instructed by the Basic Control Engine to destroy itself when
no variables reference that object. However, it is the responsibility of the OLE automation server
to destroy it. Some servers do not destroy their objects—usually when the objects have a visual
component and can be destroyed manually by the user.
See Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Integer (on page 479) (data type); Long (on page 511) (data type); Single (on
page 631) (data type); String (on page 654) (data type); Variant (on page 684) (data type);
Boolean (on page 272) (data type); DefType (on page 333) (statement).
Objects (topic)
The Basic Control Engine defines two types of objects: data objects and OLE automation objects.
What Is an Object
An object in the Basic Control Engine is an encapsulation of data and routines into a single unit. The use
of objects in the Basic Control Engine 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 the Basic Control Engine,
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:
MyApp.Open "c:\files\sample.txt"
In order to gain access to an object, you must first declare an object variable using either Dim, Public, or
Private:
Initially, objects are given the value 0 (or Nothing). Before an object can be accessed, it must be
associated with a physical object.
An object variable must reference a real physical object before accessing any properties or methods of
that object. To instantiate an object, use the Set statement.
Once an object variable has been declared and associated with a physical object, it can be modified
using the Basic Control Engine code. Properties are syntactically accessible using the dot operator, which
separates an object name from the property being accessed:
MyApp.BackgroundColor = 10
i% = MyApp.DocumentCount
Properties are set using the Basic Control Engine normal assignment statement:
MyApp.BackgroundColor = 10
i% = MyApp.DocumentCount + 10
Like properties, methods are accessed via the dot operator. Object methods that do not return values
behave like subroutines in the Basic Control Engine (that is, the arguments are not enclosed within
parentheses):
MyApp.Open "c:\files\sample.txt",True,15
Object methods that return a value behave like function calls in the Basic Control Engine. Any arguments
must be enclosed in parentheses:
NumDocs = app.count(4,5)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 549
There is no syntactic difference between calling a method function and retrieving a property value, as
shown below:
The values used to represent objects are meaningless to the script in which they are used, with the
following exceptions:
• Objects can be compared to each other to determine whether they refer to the same object.
• Objects can be compared with Nothing to determine whether the object variable refers to a valid
object.
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:
MyApp.Toolbar.Buttons(0)
MyApp.Toolbar.Buttons("Tuesday")
yAppp.Toolbar.Buttons(1).Caption = "Open"
The collection itself contains properties that provide you with information about the collection and
methods that allow navigation within that collection:
NumButtons% = MyApp.Toolbar.Buttons.Count
MyApp.Toolbar.Buttons.MoveNext
MyApp.Toolbar.Buttons.FindNext "Save"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 550
For i = 1 To MyApp.Toolbar.Buttons.Count
MyToolbarButton.Caption = "Copy"
Next i
Predefined Objects
The Basic Control Engine predefines a few objects for use in all scripts. These are:
De Returns a String containing the octal equivalent of the specified number.
scrip
tion
Com Oct$ returns a String , whereas Oct returns a String variant. The returned string contains only
ments the number of octal digits necessary to represent the number. The number parameter is any nu
meric expression. If this parameter is Null , then Null is returned. Empty is treated as 0. The
number parameter is rounded to the nearest whole number before converting to the octal equiv
alent.
Exam This example accepts a number and displays the decimal and octal 'equivalent until the input
ple number is 0 or invalid.
Sub Main()
Do
x = Val(xs$)
If x <> 0 Then
MsgBox "Decimal: " & x & " Octal: " & Oct(x)
Else
MsgBox "Goodbye."
End If
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 551
End Sub
OKButton (statement)
Com This statement can only appear within a dialog box template (that is, between the Begin Dialog
ments and End Dialog statements). The OKButton statement accepts the following parameters:
Parame Description
ter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Identifi Name by which this control can be referenced by statements in a dialog function
er (such as DlgFocus and DlgEnable ).
If the DefaultButton parameter is not specified in the Dialog statement, the OK button will be
used as the default button. In this case, the OK button can be selected by pressing Enter on a
nonbutton control. A dialog box template must contain at least one OKButton , CancelButton ,
or PushButton statement (otherwise, the dialog box cannot be dismissed).
Exam This example shows how to use the OK and Cancel buttons within a dialog box template and
ple how to detect which one closed the dialog box.
Sub Main()
OKButton 12,40,40,14
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 552
CancelButton 60,40,40,14
End Dialog
rc% = Dialog(QuitDialog)
Case -1
Case 1
End Select
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); ListBox
(on page 504) (statement); OptionButton (on page 564) (statement); OptionGroup (on page
566) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
On Error (statement)
De Defines the action taken when a trappable runtime error occurs.
scrip
tion
Com The form O n Error Goto label causes execution to transfer to the specified label when a run
ments time 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 gener
ated. 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 gener
ated. (The Exit Sub or E xit Function statement also resets the error handler, allowing a proce
dure to end without displaying an error message.)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 553
Errors within an Error Handler If an error occurs within the error handler, then the error handler
of the caller (or any procedure in the call stack) will be invoked. If there is no such error handler,
then the error is fatal, causing the script to stop executing. The following statements reset the
error state (that is, these statements turn off the fact that an error occurred):
Resume
Err=-1
The Resume statement forces execution to continue either on the same line or on the line fol
lowing the line that generated the error. The Err=-1 statement allows explicit resetting of the
error state so that the script can continue normal execution without resuming at the statement
that caused the error condition. The On Error statement will not reset the error. Thus, if an On
Error statement occurs within an error handler, it has the effect of changing the location of a
new error handler for any new errors that may occur once the error has been reset.
Exam This example will demonstrate three types of error handling. The first case simply by-passes an
ple expected error and continues with program operation. The second case creates an error branch
that jumps to a common error handling routine that processes incoming errors, clears the error
(with the Resume statement) and resumes program execution. The third case clears all internal
error handling so that execution will stop when the next error is encountered.
Sub Main()
Dim x%
a = 10000
b = 10000
Do
x% = a * b
Loop
Pass:
x% = a * b
x% = a / 0
x% = a * b 'encountered.
If Err = 6 then
Else
MsgBox Error(Err)
End If
Resume Next
End Sub
See Error Handling (on page 408) (topic); Error (on page 407) (statement); Resume (on page
Also 603) (statement).
Open (statement)
Syn Open filename$ [For mode] [Access accessmode] [lock] As [#] filenumber _
tax
[Len = reclen]
De Opens a file for a given mode, assigning the open file to the supplied filenumber.
scrip
tion
Com The filename$ parameter is a string expression that contains a valid filename.
ments
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:
The accessmode parameter determines what type of I/O operations can be performed on the
file:
Access Description
Read Write Opens the file for both reading and writing.
This value is valid only for files opened in Bi
nary, Random, or Append mode.
If the accessmode parameter is not specified, the following defaults are used:
Input Read
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 556
Output Write
• Read Write
• Write
• Read
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 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.)
If the file does not exist and the lock parameter is specified, the file is opened twice¾once 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
the Basic Control Engine when performing I/O. Larger buffers mean faster file access. For Bina
ry files, the reclen parameter is ignored.
Sub Main()
Close
Close
Close
Close
Close
Close
Kill "test.dat"
End Sub
See Close (on page 294) (statement); Reset (on page 603) (statement); FreeFile (on page
Also 445)(function).
De Sets the default data type of variables and function return values when not otherwise specified.
scrip
tion
Com By default, the type of implicitly defined variables and function return values is Variant. This
ments statement is used for backward compatibility with earlier versions of BasicScript where the de
fault data type was Integer. This statement must appear outside the scope of all functions and
subroutines. Currently, type can only be set to Integer.
Exam
ple 'This script sets the default data type to Integer. This fact
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
tax
Com By default, BasicScript implicitly declares variables that are used but have not been explicitly de
ments clared with Dim, Public, or Private. To avoid typing errors, you may want to use Option Explicit
to prevent this behavior. The Option Explicit statement also enforces explicit declaration of all
externally called procedures. Once specified, all externally called procedures must be explicitly
declared with the Declare statement.
See Const (on page 299) (statement), Dim (on page 338) (statement), Public (on page 582)
Also (statement), Private (on page 581) (statement), ReDim (on page 601) (statement), Declare
(on page 333) (statement)
OpenFilename$ (function)
De Displays a dialog box that prompts the user to select from a list of files, returning the full path
scrip name of the file the user selects or a zero-length string if the user selects Cancel.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 559
Com This function displays the standard file open dialog box, which allows the user to select a file. It
ments takes the following parameters:
Parameter Description
e$ = "All Files:*.BMP,*.WMF;Bitmaps:*.BMP;Metafiles:*.WMF"
f$ = OpenFilename$("Open Picture",e$)
Exam This example asks the user for the name of a file, then proceeds to read the first line from that
ple file.
Sub Main
Close #1
MsgBox "First line from " & f$ & " is " & s$
End If
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 560
See MsgBox (on page 530) (statement); AskBox$ (on page 254) (function); AskPassword$ (on
Also page 256) (function); InputBox, InputBox$ (on page 474) (functions); SaveFilename$ (on
page 611) (function); SelectBox (on page 622) (function); AnswerBox (on page 231) (func
tion).
type:ext[,ext][;type:ext[,ext]]...
Placeholder Description
"All Files:*.*"
"Documents:*.TXT,*.DOC"
"All Files:*.*;Documents:*.TXT,*.DOC"
The following table shows the precedence of the operators supported by the Basic Control Engine.
Operations involving operators of higher precedence occur before operations involving operators of lower
precedence. When operators of equal precedence occur together, they are evaluated from left to right.
() Parentheses Highest
^ Exponentiation
- Unary minus
\ Integer division
Mod Modulo
When numeric, binary, logical or comparison operators are used, the data type of the result is generally
the same as the data type of the more precise operand. For example, adding an Integer and a Long first
converts the Integer operand to a Long, then performs a long addition, overflowing only if the result can
not be contained with a Long. The order of precision is shown in the following table: Empty Least pre
cise BooleanIntegerLongSingleDateDoubleCurrency Most precise
There are exceptions noted in the descriptions of each operator. The rules for operand conversion are
further complicated when an operator is used with variant data. In many cases, an overflow causes au
tomatic promotion of the result to the next highest precise data type. For example, adding two Integer
variants results in an Integer variant unless it overflows, in which case the result is automatically pro
moted to a Long variant.
Com By default, the lower bound used for all array declarations is 0. This statement must appear
ments outside of any functions or subroutines.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 562
a(1) = "Hello"
MsgBox "The first element of the array is: " & a(1)
End Sub
See Al Dim (on page 338) (statement); Public (on page 582) (statement); Private (on page 581)
so (statement).
Com When Option Compare is set to Binary, then string comparisons are case-sensitive (for exam
ments ple, "A" does not equal "a"). When it is set to Text, string comparisons are case-insensitive (for
example, "A" is equal to "a"). The default value for Option Compare is Binary. The Option Com
pare statement affects all string comparisons in any statements that follow the Option Com
pare statement. Additionally, the setting affects the default behavior of Instr, StrComp, and the
Like operator. The following table shows the types of string comparisons affected by this set
ting: > < <> <= >= Instr 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.
Sub CompareBinary
If a$ = b$ Then
Else
End If
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 563
End Sub
Sub CompareText
If a$ = b$ Then
Else
End If
End Sub
Sub Main()
End Sub
See Like (on page 499) (operator); InStr (on page 476) (function); StrComp (on page 651) (func
Also tion); Comparison Operators (on page 297) (topic).
De Turns on or off the ability to use C-style escape sequences within strings.
scrip
tion
Com When Option CStrings On is in effect, the compiler treats the backslash character as an escape
ments character when it appears within strings. An escape character is simply a special character that
cannot otherwise be ordinarily typed by the computer keyboard.
\a Bell Chr$(7)
\b Backspace Chr$(8)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 564
\t Tab Chr$(9)
\0 Null Chr$(0)
\\ Backslash Chr$(92)
\? Question mark ?
With hexadecimal values, the Basic Control Engine stops scanning for digits when it encounters
a nonhexadecimal digit or two digits, whichever comes first. Similarly, with octal values, the Ba
sic Control Engine 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.
End Sub
OptionButton (statement)
Com This statement can only appear within a dialog box template (that is, between the Begin Dialog
ments and End Dialog statements). The OptionButton statement accepts the following parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
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.
.Iden Name by which this control can be referenced by statements in a dialog function (such
tifier as DlgFocus and DlgEnable ).
OptionGroup .Orientation
OKButton 80,8,40,14
End Dialog
Dialog PowerDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionGroup (on page
566) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 566
Note Accelerators are underlined, and the accelerator combination Alt+letter is used.
OptionGroup (statement)
De Specifies the start of a group of option buttons within a dialog box template.
scrip
tion
Com The .Identifier parameter specifies the name by which the group of option buttons can be ref
ments erenced by statements in a dialog function (such as DlgFocus and DlgEnable ). This parame
ter 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: DialogVariable.Identifier. This state
ment can only appear within a dialog box template (that is, 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.
OptionGroup .Orientation
OKButton 80,8,40,14
End Dialog
Dialog PowerDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 567
564) (statement); Picture (on page 570) (statement); PushButton (on page 584) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin Dialog (on
page 269) (statement), PictureButton (on page 572) (statement).
Or (operator)
Com If both expressions are either Boolean , Boolean variants, or Null variants, then a logical dis
ments junction is performed as follows:
If the first expre and the second ex then: the result is
sionn is pression is
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 ex
pressions according to the following table:
1 Or 1 = 1 Example
0 Or 1 = 1 5 10101001
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 568
1 Or 0 = 1 6 01101010
0 Or 0 = 0 Or 11101011
temperature_alert = True
pressure_alert = False
End If
End Sub
Dim w As Integer
TryAgain:
s$ = "&H" & s$
End If
w = Cint(s$)
w = w Or &H8000
MsgBox "Your number with the high bit set is &H" & Hex(w)
End Sub
See Operator Precedence (on page 560) (topic); Xor (on page 708) (operator); Eqv (on page
Also 402) (operator); Imp (on page 470) (operator); And (on page 230) (operator).
P
P
Pi (constant)
Picture (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 569
PictureButton (statement)
Pmt (function)
PointSetMultiple (function)
PointSetMultipleEX (func
tion)
PopupMenu (function)
PPmt (function)
Print (statement)
Print# (statement)
Private (statement)
Public (statement)
PushButton (statement)
Put (statement)
Pv (function)
Pi (constant)
Syntax Pi
4 * Atn(1)
Sub Main()
circ# = Pi * dia
area# = Pi * ((dia / 2) ^ 2)
MsgBox msg1
End Sub
See Also Tan (on page 664) (function); Atn (on page 258) (function); Cos (on page 306)
(function); Sin (on page 631) (function).
Picture (statement)
Com Picture controls are used for the display of graphics images only. The user cannot interact with
ments these controls. The Picture statement accepts the following parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Pic String containing the name of the picture. If PictureType is 0, then this name specifies
ture the name of the file containing the image. If PictureType is 10, then PictureName$ spec
Name$ ifies the name of the image within the resource of the picture library. If PictureName$ is
empty, then no picture will be associated with the control. A picture can later be placed
into the picture control using the DlgSetPicture statement.
Pic Integer specifying the source for the image. The following sources are supported:
ture
Type
.Iden Name by which this control can be referenced by statements in a dialog function (such
tifier as DlgFocus and DlgEnable ). If omitted, then the first two words of PictureName$ are
used.
style Specifies whether the picture is drawn within a 3D frame. It can be any of the following
values:
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, the Ba
sic Control Engine 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.
Exam This first example shows how to use a picture from a file.
ple 1 Sub Main()
OKButton 240,8,40,14
Picture 8,8,224,64,"c:\bitmaps\logo.bmp",0,.Logo
End Dialog
Dialog LogoDialog
End Sub
Exam This second example shows how to use a picture from a picture library with a 3D frame.
ple 2 Sub Main()
OKButton 240,8,40,14
Picture 8,8,224,64,"CompanyLogo",10,.Logo,1
End Dialog
Dialog LogoDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 572
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); ListBox
(on page 504) (statement); OptionButton (on page 564) (statement); OptionGroup (on page
566) (statement); PushButton (on page 584) (statement); Text (on page 664) (statement);
TextBox (on page 666) (statement); Begin (on page 269) Dialog (on page 269) (statement),
PictureButton (on page 572) (statement); DlgSetPicture (on page 355) (statement).
Notes Picture controls can contain either a bitmap or a WMF (Windows metafile). When extracting
images from a picture library, the Basic Control Engine assumes that the resource type for
metafiles is 256. Picture libraries are implemented as DLLs on the Windows and Win32 plat
forms.
PictureButton (statement)
Com Picture button controls behave very much like a push button controls. Visually, picture buttons
ments are different than push buttons in that they contain a graphic image imported either from a file
or from a picture library. The PictureButton statement accepts the following parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Pic String containing the name of the picture. If PictureType is 0, then this name specifies
ture the name of the file containing the image. If PictureType is 10, then PictureName$ spec
Name$ ifies the name of the image within the resource of the picture library. If PictureName$ is
empty, then no picture will be associated with the control. A picture can later be placed
into the picture control using the DlgSetPicture statement.
Pic Integer specifying the source for the image. The following sources are supported:
ture
Type
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 573
.Iden Name by which this control can be referenced by statements in a dialog function (such
tifier as DlgFocus and DlgEnable ).
The picture button control extracts the actual image from either a disk file or a picture library,
depending on the value of PictureType. The supported picture formats vary from platform to
platform. If PictureName$ is a zero-length string, then the picture is removed from the picture
button control, freeing any memory associated with that picture.
Exam This first example shows how to use a picture from a file.
ple 1 Sub Main()
OKButton 240,8,40,14
PictureButton 8,4,224,64,"c:\bitmaps\logo.bmp",0,.Logo
End Dialog
Dialog LogoDialog
End Sub
Exam This second example shows how to use a picture from a picture library.
ple 2 Sub Main()
OKButton 240,8,40,14
PictureButton 8,4,224,64,"CompanyLogo",10,.Logo
End Dialog
Dialog LogoDialog
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
564) (statement); OptionGroup (on page 566) (statement); PushButton (on page 584)
(statement); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 574
page 269) Dialog (on page 269) (statement), Picture (on page 570) (statement); DlgSetPic
ture (on page 355) (statement).
Notes Picture controls can contain either a bitmap or a WMF (Windows metafile). When extracting
images from a picture library, the Basic Control Engine assumes that the resource type for
metafiles is 256. Picture libraries are implemented as DLLs on the Win32 platforms. Picture con
trols can contain either bitmaps or Windows metafiles.
Pmt (function)
De Returns the payment for an annuity based on periodic fixed payments and a constant rate of in
scrip terest.
tion
Com An annuity is a series of fixed payments made to an insurance company or other investment
ments company over a period of time. Examples of annuities are mortgages and monthly savings
plans. The Pmt function requires the following parameters:
Pa Description
ra
me
ter
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.
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 val
ue would be 0.
Due Integer indicating when payments are due for each payment period. A 0 specifies pay
ment at the end of each period, whereas a 1 specifies payment at the start of each peri
od.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 575
Rate and NPer 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.
Exam This example calculates the payment necessary to repay a $1,000.00 loan over 36 months at an
ple annual rate of 10%. Payments are due at the beginning of the period.
Sub Main()
x = Pmt((.1/12),36,1000.00,0,1)
msg1 = "The payment to amortize $1,000 over 36 months @ 10% is: "
End Sub
See IPmt (on page 479) (function); NPer (on page 542) (function); PPmt (on page 576) (func
Also tion); Rate (on page 592) (function).
PopupMenu (function)
De Displays a pop-up menu containing the specified items, returning an Integer representing the
scrip index of the selected item.
tion
Com If no item is selected (that is, the pop-up menu is canceled), then a value of 1 less than the lower
ments bound is returned (normally, –1). 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 func
tion while a pop-up menu is visible.
AppList a$
w% = PopupMenu(a$)
End Sub
PPmt (function)
De Calculates the principal payment for a given period of an annuity based on periodic, fixed pay
scrip ments and a fixed interest rate.
tion
Com An annuity is a series of fixed payments made to an insurance company or other investment
ments company over a period of time. Examples of annuities are mortgages and monthly savings
plans. The PPmt function requires the following parameters:
Pa Description
ra
me
ter
Per Double representing the number of payment periods. Per can be no less than 1 and no
greater than NPer.
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 val
ue would be 0 .
Due Integer indicating when payments are due. If this parameter is 0 , then payments are due
at the end of each period; if it is 1 , then payments are due at the start of each period.
Rate and NPer must be in the same units to calculate correctly. If Rate is expressed in months,
then NPer must also be expressed in months. Negative values represent payments paid out,
whereas positive values represent payments received.
Exam This example calculates the principal paid during each year on a loan of $1,000.00 with an annu
ple al rate of 10% for a period of 10 years. The result is displayed as a table containing the following
information: payment, principal payment, principal balance.
pay = Pmt(.1,10,1000.00,0,1)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 577
msg1 = "Amortization table for 1,000" & crlf & "at 10% annually for"
msg1 = msg1 & " 10 years: " & crlf & crlf
bal = 1000.00
For per = 1 to 10
prn = PPmt(.1,per,10,1000,0,0)
Next per
MsgBox msg1
End Sub
See IPmt (on page 479) (function); NPer (on page 542) (function); PPmt (on page 576) (func
Also tion); Rate (on page 592) (function).
Print (statement)
Com The actual output device depends on the platform on which the Basic Control Engine is running.
ments The following table describes how data of different types is written:
Data Description
Type
Any nu Printed with an initial space reserved for the sign (space = positive). Additionally, there
meric is a space following each number.
type
Date Printed using the short date format. If either the date or time component is missing,
only the provided portion is printed (this is consistent with the "general date" format
understood by the Format/Format$ functions).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 578
User- Printed as "Error code", where code is the value of the user-defined error. The word "Er
defined ror" is not translated.
errors
Each expression in expressionlist is separated with either a comma (,) or a semicolon (;). A com
ma means that the next expression is output in the next print zone. A semicolon means that
the next expression is output immediately after the current expression. Print zones are defined
every 14 spaces. If the last expression in the list is not followed by a comma or a semicolon,
then a carriage return is printed to the file. If the last expression ends with a semicolon, no car
riage return is printed¾the next Print statement will output information immediately following
the expression. If the last expression in the list ends with a comma, the file pointer is positioned
at the start of the next print zone on the current line. The Tab and Spc functions provide addi
tional control over the column position. The Tab function moves the file position to the speci
fied column, whereas the Spc function outputs the specified number of spaces.
ple i% = 10
s$ = "This is a test."
'zone 3.
Print i%,,s$
Print i%;Spc(10);s$
Print i%;Tab(30);s$
Print i%;s$,
Print 67
End Sub
Print# (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 579
Com The filenumber parameter is a number that is used by the Basic Control Engine to refer to the
ments open file, the number passed to the Open statement. The following table describes how data of
different types is written:
Data Description
Type
Any nu Printed with an initial space reserved for the sign (space = positive). Additionally, there
meric is a space following each number.
type
Date Printed using the short date format. If either the date or time component is missing,
only the provided portion is printed (this is consistent with the "general date" format
understood by the Format/Format$ functions).
User- Printed to files as "Error code", where code is the value of the user-defined error. The
defined word "Error" is not translated.
errors
Each expression in expressionlist is separated with either a comma (,) or a semicolon (;). A com
ma means that the next expression is output in the next print zone. A semicolon means that
the next expression is output immediately after the current expression. Print zones are defined
every 14 spaces. If the last expression in the list is not followed by a comma or a semicolon,
then an end-of-line is printed to the file. If the last expression ends with a semicolon, no end-of-
line is printed¾the next Print statement will output information immediately following the ex
pression. If the last expression in the list ends with a comma, the file pointer is positioned at the
start of the next print zone on the current line.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 580
The Write statement always outputs information ending with an end-of-line. Thus, if a Print
statement is followed by a Write statement, the file pointer is positioned on a new line. The
Print statement can only be used with files that are opened in Output or Append mode. The
Tab and Spc functions provide additional control over the file position. The Tab function
moves the file position to the specified column, whereas the Spc function outputs the specified
number of spaces. In order to correctly read the data using the Input# statement, you should
write the data using the Write statement.
i% = 10
s$ = "This is a test."
'print zone 3.
Print #1,i%,,s$
Print #1,i%;Spc(10);s$
Print #1,i%;Tab(30);s$
Print #1,i%;s$,
Print #1,67
Close #1
Kill "test.dat"
End Sub
See Open (on page 554) (statement); Put (on page 585) (statement); Write# (on page 706)
Also (statement).
Note The end-of-line character can be either the carriage-return/line-feed pair, or the line-feed charac
ter.
If you want it to go to a file you need the # otherwise it goes to standard out and uses the first variable (in
thise case f) as the first item to output to standard out. So that print line should be
Private (statement)
De Declares a list of private variables and their corresponding types and sizes.
scrip
tion
Com Private variables are global to every Sub and Function within the currently executing script. If
ments 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 pa
rameter 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 spec
ified, then the lower bound as specified by Option Base is used (or 1 if no Option Base state
ment 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, Sin
gle, 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 Val
ues All declared variables are given initial values, as described in the following table:
Integer 0
Long 0
Double 0.0
Single 0.0
Currency 0.0
Object Nothing
Boolean False
Variant Empty
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.
Exam This example sets the value of variable x# in two separate routines to show the behavior of pri
ple vate variables.
Private x#
Sub Area()
MsgBox x#
End Sub
Sub Main()
x# = 100 'Set this copy of x# to 100 and display after calling the Area subroutine
Area
MsgBox x#
End Sub
See Dim (on page 338) (statement); Redim (on page 601) (statement); Public (on page 582)
Also (statement); Option Base (on page 561) (statement).
Public (statement)
De Declares a list of public variables and their corresponding types and sizes.
scrip
tion
Com Public variables are global to all Sub s and Function s in all scripts. If a type-declaration char
ments acter is used when specifying name (such as % , @ , & , $ , or ! ), the optional [ As type ] ex
pression 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 fol
lowing syntax: [lower To] upper [,[lower To] upper]... The lower and upper parameters are inte
gers specifying the lower and upper bounds of the array. If lower is not specified, then the lower
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 583
bound as specified by Option Base is used (or 1 if no Option Base statement has been encoun
tered). 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, Sin
gle, 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 key
word 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. Initial Val
ues All declared variables are given initial values, as described in the following table:
Parameter Description
Integer 0
Long 0
Double 0.0
Single 0.0
Currency 0.0
Object Nothing
Boolean False
Variant Empty
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.
Exam This example uses a subroutine to calculate the area of ten circles and displays the result in a
ple dialog box. The variables R and Ar are declared as Public variables so that they can be used in
both Main and Area.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 584
Public x#,ar#
Sub Area()
ar# = (x# ^ 2) * Pi
End Sub
Sub Main()
msg1 = "The area of the ten circles are:" & crlf & crlf
For x# = 1 To 10
Area
msg1 = msg1 & x# & ": " & Format(ar#,"fixed") & Basic.Eoln$
Next x#
MsgBox msg1
End Sub
See Dim (on page 338) (statement); Redim (on page 601) (statement); Option Base (on page
Also 561) (statement).
PushButton (statement)
Com Choosing a push button causes the dialog box to close (unless the dialog function redefines
ments this behavior). This statement can only appear within a dialog box template (that is, between the
Begin Dialog and End Dialog statements). The PushButton statement accepts the following
parameters:
Para Description
meter
X, Y Integer coordinates specifying the position of the control (in dialog units) static to the
upper left corner of the dialog box.
width, Integer coordinates specifying the dimensions of the control in dialog units.
height
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 585
title$ String containing the text that appears within the push button. This text may contain an
ampersand character to denote an accelerator letter, such as " &Save " for Save .
.Iden Name by which this control can be referenced by statements in a dialog function (such
tifier as DlgFocus and DlgEnable ).
If a push button is the default button, it can be selected by pressing Enter on a nonbutton con
trol. A dialog box template must contain at least one OKButton , CancelButton , or PushButton
statement (otherwise, the dialog box cannot be dismissed).
Exam This example creates a bunch of push buttons and displays which button was pushed.
ple Sub Main()
OKButton 8,4,40,14,.OK
CancelButton 8,24,40,14,.Cancel
PushButton 8,44,40,14,"1",.Button1
PushButton 8,64,40,14,"2",.Button2
PushButton 56,4,40,14,"3",.Button3
PushButton 56,24,40,14,"4",.Button4
PushButton 56,44,40,14,"5",.Button5
PushButton 56,64,40,14,"6",.Button6
End Dialog
WhichButton% = Dialog(ButtonDialog)
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
564) (statement); OptionGroup (on page 566) (statement); Picture (on page 570) (state
ment); Text (on page 664) (statement); TextBox (on page 666) (statement); Begin (on page
269) Dialog (on page 269) (statement), PictureButton (on page 572) (statement); DlgSet
Picture (on page 355) (statement).
Note Accelerators are underlined, and the accelerator combination Alt+ letter is used.
Put (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 586
De Writes data from the specified variable to a Random or Binary file.
scrip
tion
Para Description
meter
filenum Integer representing the file to be written to. This is the same value as returned by the
ber Open statement.
record Long specifying which record is to be written to the file. For Binary files, this number
num represents the first byte to be written starting with the beginning of the file (the first
ber 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 record
number 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:
String (vari In Binary files, variable-length strings are written by first determining the speci
able-length fied string variable's length, then writing that many bytes to the file. In Random
files, variable-length strings are written by first writing a 2-byte length, then writ
ing that many characters to the file.
String (fixed- Fixed-length strings are written to Random and Binary files in the same way:
length) the number of characters equal to the string's declared length are written.
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 2-byte unsigned integer (the error value), which is then followed by 2 addition
al bytes of information. The exception is with strings, which are always preceded
by a 2-byte string length.
User-defined Each member of a user-defined data type is written individually. In Binary files,
types 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 vari
able-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.
Objects Object variables cannot be written to a file using the Put statement.
With Random files, a runtime error will occur if the length of the data being written exceeds
the record length (specified as the reclen parameter with the Open statement). If the length
of the data being written is less than the record length, the entire record is written along with
padding (whatever data happens to be in the I/O buffer at that time). With Binary files, the data
elements are written contiguously: they are never separated with padding.
Exam This example opens a file for random write, then writes ten records into the file with the values
ple 10-50. Then the file is closed and reopened in random mode for read, and the records are read
with the Get statement. The result is displayed in a dialog box.
Sub Main()
For x = 1 To 10
r% = x * 10
Put #1,x,r%
Next x
Close
For x = 1 To 10
Get #1,x,r%
msg1 = "Record " & x & " is: " & r% & Basic.Eoln$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 588
Next x
MsgBox msg1
Close
Kill "test.dat"
End Sub
See Open (on page 554) (statement); Put (on page 585) (statement); Write# (on page 706)
Also (statement); Print# (on page 578) (statement).
Pv (function)
Syn Pv (Rate,NPer,Pmt,Fv,Due)
tax
De Calculates the present value of an annuity based on future periodic fixed payments and a con
scrip stant rate of interest.
tion
Pa Description
ra
me
ter
Rate Double representing the interest rate per period. When used with monthly payments, be
sure to normalize annual percentage rates by dividing them by 12.
Fv Double representing the future value of the annuity after the last payment has been
made. In the case of a loan, the future value would be 0.
Due Integer indicating when the 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.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 589
Rate and NPer 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.
Exam This example demonstrates the present value (the amount you'd have to pay now) for a
ple $100,000 annuity that pays an annual income of $5,000 over 20 years at an annual interest rate
of 10%.
Sub Main()
pval = Pv(.1,20,-5000,100000,1)
End Sub
See Fv (on page 446) (function); IRR (on page 481) (function); MIRR (on page 519) (function);
Also Npv (on page 543) (function).
Q
QueEmpty (statement)
Syntax QueEmpty
Example
'This code begins a new queue, then drags a selection over a
Sub Main()
AppActivate "Notepad"
QueMouseDn ebLeftButton,1440,1393
QueMouseUp ebLeftButton,4147,2363
QueFlush True
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 590
R
R
Random (function)
Randomize (statement)
Rate (function)
RCPDownload (statement)
RCPDownloadEx (function
RCPGroupExport (statement)
RCPGroupExportEx (function)
RCPGroupImport (statement)
RCPGroupImportEx (function)
RCPUpload (statement)
RCPUploadEx (function)
ReadIn$ (function)
ReadInSection (statement)
Redim (statement)
Rem (statement)
Reset (statement)
Resume (statement)
Return (statement)
RmDir (statement)
Rnd (function)
RSet (statement)
Random (function)
Descrip Returns a Long value greater than or equal to min and less than or equal to max.
tion
Com Both the min and max parameters are rounded to Long . A runtime error is generated if min
ments is greater than max.
Example This example sets the randomize seed then generates six random numbers between 1 and
54 for the lottery.
Sub Main()
Dim a%(5)
Randomize
For x = 0 To 5
temp = Random(1,54)
For y = 0 To 5
Next
found = false
Next
ArraySort a
msg1 = ""
For x = 0 To 5
Next x
MsgBox "Today's winning lottery numbers are: " & crlf & crlf & msg1
End Sub
See Also Randomize (on page 591) (statement); Rnd (on page 607) (function).
Randomize (statement)
Com If seed is not specified, then the current value of the system clock is used.
ments
Example This example sets the randomize seed then generates six random numbers between 1 and
54 for the lottery.
Sub Main()
Dim a%(5)
For x = 0 To 5
temp = Rnd(1) * 54 + 1
For y = 0 To 5
Next
found = false
Next
ArraySort a
msg1 = ""
For x = 0 To 5
Next x
MsgBox "Today's winning lottery numbers are: " & crlf & crlf & msg1
End Sub
See Also Random (on page 591) (function); Rnd (on page 607) (function).
Rate (function)
Com An annuity is a series of fixed payments made to an insurance company or other investment
ments company over a period of time. Examples of annuities are mortgages and monthly savings
plans. The Rate function requires the following parameters:
Parameter Description
Pv Double representing the present value of your annuity. In a loan situation, the
present value would be the amount of the loan.
Fv Double representing the future value of the annuity after the last payment has
been made. In the case of a loan, the future value would be zero.
Due Integer specifying when the payments are due for each payment period. A 0 in
dicates payment at the end of each period, whereas a 1 indicates payment at
the start of each period.
Guess Double specifying a guess as to the value the Rate function will return. The
most common guess is .1 (10 percent).
Positive numbers represent cash received, whereas negative values represent cash paid out.
The value of Rate 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, Rate fails, and the user must pick a better guess.
Exam This example calculates the rate of interest necessary to save $8,000 by paying $200 each year
ple for 48 years. The guess rate is 10%.
Sub Main()
r# = Rate(48,-200,8000,0,1,.1)
End Sub
See IPmt (on page 479) (function); NPer (on page 542) (function); Pmt (on page 574) (func
Also tion); PPmt (on page 576) (function).
RCPDownload (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 594
De Downloads the specified Recipe from the specified Recipe Group using the specified Map.
scrip
tion
Parameter Description
filename$ Required string containing the name of the Recipe Group file where the Recipe is
located. The Recipe Group file must exist
mapname$ Optional string containing the name of the Map to be used when Downloading the
Recipe.
pointorval$ Optional string containing the Batch Point or Batch ID to be used when Download
ing the Recipe.
ple
RCPDownloadEx (function)
De Downloads the specified Recipe from the specified Recipe Group using the specified Map.
scrip
tion
Parameter Description
filename$ Required string containing the name of the Recipe Group file where the
Recipe is located. The Recipe Group file must exist
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 595
mapname$ Optional string containing the name of the Map to be used when Download
ing the Recipe.
pointorval$ Optional string containing the Batch Point or Batch ID to be used when
Downloading the Recipe.
ple
RCPGroupExport (statement)
Parameter Description
group Required string containing the name of the Recipe Group file. The Recipe Group
name$ file must exist.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 596
RCPGroupExportEx (function)
Parameter Description
groupname$ Required string containing the name of the Recipe Group file. The
Recipe Group file must exist.
ple
RCPGroupImport (statement)
Parameter Description
RCPGroupImportEx (function)
Parameter Description
groupname$ Required string containing the name of the Recipe Group file.
RCPUpload (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 598
De Uploads the specified Recipe to the specified Recipe Group using the specified Map.
scrip
tion
Parameter Description
filename$ Required string containing the name of the Recipe Group file where the Recipe is
located. The Recipe Group file must exist.
mapname$ Optional string containing the name of the Map to be used when Uploading the
Recipe.
newname$ Optional string containing the name of the Recipe to be uploaded. You may use a
new or existing Recipe name.
ple
RCPUploadEx (function)
De Uploads the specified Recipe to the specified Recipe Group using the specified Map.
scrip
tion
Parameter Description
filename$ Required string containing the name of the Recipe Group file where the
Recipe is located. The Recipe Group file must exist.
mapname$ Optional string containing the name of the Map to be used when Uploading
the Recipe.
newname$ Optional string containing the name of the Recipe to be uploaded. You may
use a new or existing Recipe name.
ple
ReadIni$ (function)
De Returns a String containing the specified item from an ini file.
scrip
tion
Para Description
meter
Sec String specifying the section that contains the desired variable, such as "windows". Sec
tion$ tion names are specified without the enclosing brackets.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 600
See WriteIni (on page 707) (statement); ReadIniSection (on page 600) (statement)
Also
Notes If the name of the ini file is not specified, then win.ini is assumed. If the filename$ parameter
does not include a path, then this statement looks for ini files in the Windows directory.
ReadIniSection (statement)
De Fills an array with the item names from a given section of the specified ini file.
scrip
tion
Para Description
meter
Sec String specifying the section that contains the desired variables, such as "windows".
tion$ Section names are specified without the enclosing brackets.
Array Specifies either a zero- or a one-dimensioned array of strings or variants. The array can
Of be either dynamic or fixed. If ArrayOfItems() is dynamic, then it will be redimensioned
Items() 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 Ar-
rayDims 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 el
ements 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.
On return, the ArrayOfItems() parameter will contain one array element for each variable in the
specified ini section.
ReadIniSection "Windows",items$
r% = SelectBox("INI Items",,items$)
End Sub
See ReadIni$ (on page 599) (function); WriteIni (on page 707) (statement)
Also
Note If the name of the ini file is not specified, then win.ini is assumed. If the filename$ parameter
does not include a path, then this statement looks for .ini files in the Windows directory.
Redim (statement)
De Redimensions an array, specifying a new upper and lower bound for each dimension of the ar
scrip ray.
tion
Com The variablename parameter specifies the name of an existing array (previously declared us
ments ing the Dim statement) or the name of a new array variable. If the array variable already ex
ists, then it must previously have been declared with the Dim statement with no dimensions, as
shown in the following example:
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:
If lower is not specified, then 0 is used (or the value set using the Option Base statement). A
runtime error is generated if lower is less than upper. Array dimensions must be within the fol
lowing range:
The type parameter can be used to specify the array element type. Arrays can be declared using
any fundamental data type, user-defined data types, and objects. Re-dimensioning an array eras
es all elements of that array unless the Preserve keyword is specified. When this keyword is
specified, existing data in the array is preserved where possible. If the number of elements in an
array dimension is increased, the new elements are initialized to 0 (or empty string). If the num
ber of elements in an array dimension is decreased, then the extra elements will be deleted. If
the Preserve keyword is specified, then the number of dimensions of the array being re-dimen
sioned must either be zero or the same as the new number of dimensions.
Exam This example uses the FileList statement to re-dim an array and fill it with filename strings. A
ple new array is then re-dimmed to hold the number of elements found by FileList, and the FileList
array is copied into it and partially displayed.
Sub Main()
Dim fl$()
FileList fl$,"*.*"
count = 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 Sub
See Dim (on page 338) (statement); Public (on page 582) (statement); Private (on page 581)
Also (statement); ArrayDims (on page 249) (function); LBound (on page 493) (function); UBound
(on page 677) (function).
Rem (statement)
Rem workings of the code. You can insert comments to make it more
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 603
See Also ' (on page 212) (keyword); Comments (on page 311)
(topic).
Reset (statement)
Syntax Reset
Descrip Closes all open files, writing out all I/O buffers.
tion
Example This example opens a file for output, closes it with the Reset statement, then deletes it with
the Kill statement.
Sub Main()
Reset
Kill "test.dat"
If FileExists("test.dat") Then
Else
End If
End Sub
See Also Close (on page 294) (statement); Open (on page 554) (statement).
Resume (statement)
Com The form Resume 0 (or simply Resume by itself) causes execution to continue with the state
ments ment that caused the error. The form Resume Next causes execution to continue with the
statement following the statement that caused the error.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 604
The form Resume label causes execution to continue at the specified label. The Resume
statement resets the error state. This means that, after executing this statement, new errors can
be generated and trapped as normal.
Exam This example accepts two integers from the user and attempts to multiply the numbers togeth
ple er. If either number is larger than an integer, the program processes an error routine and then
continues program execution at a specific section using 'Resume <label>'. Another error trap is
then set using 'Resume Next'. The new error trap will clear any previous error branching and also
'tell' the program to continue execution of the program even if an error is encountered.
Sub Main()
Dim a%,b%,x%
Again:
If err = 0 Then
Else
Msgbox a% & " * " & b% & " cause an integer overflow!"
End If
Exit Sub
Resume Again
End Sub
See Error Handling (on page 408) (topic); On Error (on page 552) (statement).
Also
Return (statement)
Syntax Return
Descrip Transfers execution control to the statement following the most recent GoSub .
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 605
Example This example calls a subroutine and then returns execution to the Main routine by the Return
statement.
Sub Main()
GoSub SubTrue
Exit Sub
SubTrue:
Return
Exit Sub
End Sub
Functions Return
Parameter Description
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 606
string String from which characters are returned. A runtime error is generated if
string is NULL.
Length is Returns
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
'letter.
Sub Main()
lname$ = "WILLIAMS"
x = Len(lname$)
rest$ = Right$(lname$,x - 1)
fl$ = Left$(lname$,1)
End Sub
See Also Left, Left$, LeftB, LeftB$ (on page 495) (functions)
RmDir (statement)
Exam This routine creates a directory and then deletes it with RmDir.
ple Sub Main()
MkDir("test01")
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 607
RmDir("test01")
ErrMake:
Exit Sub
ErrRemove:
Exit Sub
End Sub
See Al ChDir (on page 280) (statement); ChDrive (on page 280) (statement); CurDir, CurDir$ (on
so page 308) (functions); Dir, Dir$ (on page 339) (functions); MkDir (on page 521) (state
ment).
Rnd (function)
Com If number is omitted, the next random number is returned. Otherwise, the number parameter
ments has the following meaning:
If Then
Example This example sets the randomize seed then generates six random numbers between 1 and 54
for the lottery.
Sub Main()
Dim a%(5)
Randomize
For x = 0 To 5
temp = Rnd(1) * 54 + 1
or y = 0 To 5
Next
found = false
Next
ArraySort a
msg1 = ""
For x = 0 To 5
Next x
MsgBox "Today's winning lottery numbers are: " & crlf & crlf & msg1
End Sub
See Al Randomize (on page 591) (statement); Random (on page 591) (function)
so
RSet (statement)
De Copies the source string source into the destination string destvariable.
scrip
tion
Com If source is shorter in length than destvariable, then the string is right-aligned within destvariable
ments and the remaining characters are padded with spaces. If source is longer in length than dest
variable, 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 speci
fies a String or Variant variable. If destvariable is a Variant containing Empty , then no char
acters are copied. If destvariable is not convertible to a String , then a runtime error occurs. A
runtime error results if destvariable is Null .
Exam This example replaces a 40-character string of asterisks (*) with an RSet and LSet string and
ple then displays the result.
Sub Main()
Dim msg1,tmpstr$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 609
tmpstr$ = String(40,"*")
msg1 = "Here are two strings that have been right-" + crlf
MsgBox msg1
End Sub
Comments RTrim$ returns a String , whereas RTrim returns a String variant. Null is returned if text
is Null .
Example This example displays a left-justified string and its RTrim result.
Sub Main()
tr$ = RTrim(txt$)
MsgBox "Original ->" & txt$ & "<-" & crlf & "Right Trimmed ->" & tr$ & "<-"
End Sub
See Also LTrim, LTrim$ (on page 512) (functions); Trim, Trim$ (on page 671) (functions).
S
S
SaveFilename$ (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 610
SaveSetting (statement)
Screen.DlgBaseUnitsX (property)
Screen.DlgBaseUnitsY (property)
Screen.Height (property)
Screen.TwipsPerPixelX (property)
Screen.TwipsPerPixelY (property)
Screen.Width (property)
Second (function)
Seek (function)
Seek (statement)
Select...Case (statement)
SelectBox (function)
SendKeys (statement)
Set (statement)
SetAttr (statement)
Sgn (function)
Shell (function)
Sin (function)
Sleep (statement)
Sln (function)
Spc (function)
SQLBind (function)
SQLClose (function)
SQLError (function)
SQLExecQuery (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 611
SQLGetSchema (function)
SQLOpen (function)
SQLQueryTimeout (statement)
SQLRequest (function)
SQLRetrieve (function)
SQLRetrieveToFile (function)
Sqr (function)
Stop (statement)
StrComp (function)
StrConv (function)
Switch (function)
SYD (function)
System.Exit (method)
System.FreeMemory (property)
System.FreeResources (property)
System.MouseTrails (method)
System.Restart (method)
System.TotalMemory (property)
System.WindowsDirectory$ (property)
System.WindowsVersion$ (property)
SaveFilename$ (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 612
De Displays a dialog box that prompts the user to select from a list of files and returns a String con
scrip taining the full path of the selected file.
tion
Parameter Description
The SaveFilename$ function returns a full pathname of the file that the user selects. A ze
ro-length string is returned if the user selects Cancel. If the file already exists, then the user is
prompted to overwrite it.
e$ = "All Files:*.BMP,*.WMF;Bitmaps:*.BMP;Metafiles:*.WMF"
f$ = SaveFilename$("Save Picture",e$)
Exam This example creates a save dialog box, giving the user the ability to save to several different file
ple types.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 613
Sub Main()
e$ = "All Files:*.BMP,*.WMF;Bitmaps:*.BMP;Metafiles:*.WMF"
f$ = SaveFilename$("Save Picture",e$)
Else
End IF
End Sub
See MsgBox (on page 530) (statement); AskBox (on page 527) (function); AskPassword$ (on
Also page 256) (function); InputBox, InputBox$ (on page 474) (functions); OpenFilename$ (on
page 558) (function); SelectBox (on page 622) (function); AnswerBox (on page 231) (func
tion).
description:ext[,ext][;description:ext[,ext]]...
Placeholder Description
"All Files:*"
"Documents:*.TXT,*.DOC"
"All Files:*;Documents:*.TXT,*.DOC"
SaveSetting (statement)
De Saves the value of the specified key in the system registry. The following table describes the
scrip named parameters to the SaveSetting statement:
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 614
Parame Description
ter
appname String expression indicating the name of the application whose setting will be modi
fied.
section String expression indicating the name of the section whose setting will be modified.
Ex
am 'The following example adds two entries to the Windows registry
Sub Main()
End Sub
See GetAllSettings (on page 450) (function), DeleteSetting (on page 335) (statement), GetSetting
Also (on page 454) (function)
Note Under Win32, this statement operates on the system registry. All settings are saved to the follow
ing entry in the system registry: HKEY_CURRENT_USER\Software\BasicScript Program Settings\app-
Screen.DlgBaseUnitsX (property)
Syn Screen.DlgBaseUnitsX
tax
De Returns an Integer used to convert horizontal pixels to and from dialog units.
scrip
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 615
Com The number returned depends on the name and size of the font used to display dialog boxes.
ments To convert from pixels to dialog units in the horizontal direction: ((XPixels * 4) + (Screen.Dlg
BaseUnitsX - 1)) / Screen.DlgBaseUnitsX To convert from dialog units to pixels in the horizon
tal direction: (XDlgUnits * Screen.DlgBaseUnitsX) / 4
Exam This example converts the screen width from pixels to dialog units.
ple Sub Main()
XPixels = Screen.Width
conv% = Screen.DlgBaseUnitsX
MsgBox "The screen width is " & XDlgUnits & " dialog units."
End Sub
Screen.DlgBaseUnitsY (property)
Syn Screen.DlgBaseUnitsY
tax
De Returns an Integer used to convert vertical pixels to and from dialog units.
scrip
tion
Com The number returned depends on the name and size of the font used to display dialog boxes. To
ments convert from pixels to dialog units in the vertical direction: (YPixels * 8) + (Screen.DlgBase
UnitsY - 1) / Screen.DlgBaseUnitsY To convert from dialog units to pixels in the vertical direc
tion: (YDlgUnits * Screen.DlgBaseUnitsY) / 8
Exam This example converts the screen width from pixels to dialog units.
ple Sub Main()
YPixels = Screen.Height
conv% = Screen.DlgBaseUnitsY
MsgBox "The screen width is " & YDlgUnits & " dialog units."
End Sub
Screen.Height (property)
Syntax Screen.Height
Com This property is used to retrieve the height of the screen in pixels. This value will differ depend
ments ing on the display resolution. This property is read-only.
MsgBox "The Screen height is " & Screen.Height & " pixels."
End Sub
Screen.TwipsPerPixelX (property)
Syntax Screen.TwipsPerPixelX
Descrip Returns an Integer representing the number of twips per pixel in the horizontal direction of
tion the installed display driver.
Example This example displays the number of twips across the screen horizontally.
Sub Main()
End Sub
Screen.TwipsPerPixelY (property)
Syntax Screen.TwipsPerPixelY
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 617
Descrip Returns an Integer representing the number of twips per pixel in the vertical direction of the
tion installed display driver.
Example This example displays the number of twips across the screen vertically.
Sub Main()
End Sub
Screen.Width (property)
Syntax Screen.Width
Com This property is used to retrieve the width of the screen in pixels. This value will differ depend
ments ing on the display resolution. This property is read-only.
MsgBox "The screen width is " & Screen.Width & " pixels."
End Sub
Second (function)
De Returns the second of the day encoded in the specified time parameter.
scrip
tion
Com The value returned is an Integer between 0 and 59 inclusive. The time parameter is any expres
ments sion that converts to a Date .
Exam This example fires an event every 10 seconds based on the system clock.
ple Sub Main()
trigger = 10
Do
xs% = Second(Now)
Beep
Sleep 1000
End If
DoEvents
Loop
End Sub
See Day (on page 322) (function); M (on page 519) inute (on page 519) (function); Month (on
Also page 522) (function); Year (on page 710) (function); Hour (on page 461) (function); Week
day (on page 692) (function); DatePart (on page 319) (function).
Seek (function)
De Returns the position of the file pointer in a file static to the beginning of the file.
scrip
tion
Com The filenumber parameter is a number that the Basic Control Engine uses to refer to the open
ments file—the number passed to the Open statement. The value returned depends on the mode in
which the file was opened:
The value returned is a Long between 1 and 2147483647, where the first byte (or first record) in
the file is 1.
Exam This example opens a file for random write, then writes ten records into the file using the PUT
ple statement. The file position is displayed using the Seek Function, and the file is closed.
Sub Main()
For x = 1 To 10
r% = x * 10
Put #1,x,r%
Next x
y = Seek(1)
Close
End Sub
See Seek (on page 619) (statement); Loc (on page 506) (function).
Also
Seek (statement)
De Sets the position of the file pointer within a given file such that the next read or write operation
scrip will occur at the specified position.
tion
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 620
filenum Integer used by the Basic Control Engine to refer to the open file—the number passed
ber to the Open statement.
posi Long that specifies the location within the file at which to position the file pointer. The
tion value must be between 1 and 2147483647, where the first byte (or record number) in
the file is 1. For files opened in either Binary, Output, Input, or Append mode, position is
the byte position within the file. For Random files, position is the record number.
A file can be extended by seeking beyond the end of the file and writing data there.
Exam This example opens a file for random write, then writes ten records into the file using the PUT
ple statement. The file is then reopened for read, and the ninth record is read using the Seek and
Get functions.
Sub Main()
For x = 1 To 10
Put #1,x,rec$
Next x
Close
Seek #1,9
Get #1,,rec$
Close
Kill "test.dat"
End Sub
See Seek (on page 618) (function); Loc (on page 506) (function)
Also
Select...Case (statement)
[statement_block]]
[Case expressionlist
[statement_block]]
.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 621
[Case Else
[statement_block]]
End Select
De Used to execute a block of the Basic Control Engine statements depending on the value of a giv
scrip en expression.
tion
Part Description
state Any group of the Basic Control Engine statements. If the testexpression matches any of
men the expressions contained in expressionlist, then this statement block will be executed.
t_
block
ex A comma separated list of expressions to be compared against testexpression using any
pres of the following syntaxes: expression [, expression ]... expression to expression is re
sion lational_operator expression The resultant type of expression in expressionlist must be
list the same as that of testexpression.
Multiple expression ranges can be used within a single Case clause. For example:
Only the statement_block associated with the first matching expression will be executed. If no
matching statement_block is found, then the statements following the Case Else will be exe
cuted. A Select...End Select expression can also be represented with the If...Then expression.
The use of the Select statement, however, may be more readable.
Exam This example uses the Select...Case statement to output the current operating system.
ple Sub Main()
OpSystem% = Basic.OS
Case 0,2
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 622
s = "Microsoft Windows"
Case 1
s = "DOS"
Case 3 to 8,12
s = "UNIX"
Case 10
s = "IBM OS/2"
Case Else
s = "Other"
End Select
MsgBox "This version of the Basic Control Engine is running on: " & s
End Sub
See Choose (on page 283) (function); Switch (on page 657) (function); IIf (on page 468) (func
Also tion); If...Then...Else (on page 466) (statement)
SelectBox (function)
Syn SelectBox(title,prompt,ArrayOfItems)
tax
De Displays a dialog box that allows the user to select from a list of choices and returns an Integer
scrip containing the index of the item that was selected.
tion
Para Description
meter
title Title of the dialog box. This can be an expression convertible to a String. A runtime er
ror is generated if title is Null.
prompt Text to appear immediately above the list box containing the items. This can be an ex
pression convertible to a String. A runtime error is generated if prompt is Null.
Array Single-dimensioned array. Each item from the array will occupy a single entry in the list
Of box. A runtime error is generated if ArrayOfItems is not a single-dimensioned array. Ar
Items rayOfItems can specify an array of any fundamental data type (structures are not al
lowed). Null and Empty values are treated as zero-length strings.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 623
The value returned is an Integer representing the index of the item in the list box that was se
lected, with 0 being the first item. If the user selects Cancel, –1 is returned.
Exam This example gets the current apps running, puts them in to an array and then asks the user to
ple select one from a list.
Sub Main()
Dim a$()
AppList a$
Else
End If
End Sub
See MsgBox (on page 530) (statement); AskBox$ (on page 254) (function); AskPassword$ (on
Also page 256) (function); InputBox, InputBox$ (on page 474) (functions); OpenFilename$ (on
page 558) (function); SaveFilename$ (on page 611) (function); AnswerBox (on page 231)
(function)
Note The SelectBox displays all text in its dialog box in 8-point MS Sans Serif.
SendKeys (statement)
De Sends the specified keys to the active application, optionally waiting for the keys to be
scrip processed before continuing.
tion
Parameter Description
KeyString$ String containing the keys to be sent. The format for KeyString$ is described below.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 624
isWait Boolean value. If TRUE, then the Basic Control Engine waits for the keys to be
completely processed before continuing. If you are using SendKeys in a CimEd
it/CimView script, you must set this flag to TRUE. If you do not, when a user tries to
execute the SendKeys statement, the CimView screen freezes and processing will
not continue. If FALSE (or not specified), then the BasicScript continues script exe
cution before the active application receives all keys from 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:
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.
Specifying Keys To specify any key on the keyboard, simply use that key, such as "a" for lower
case 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 follow
ing table shows the special keys:
cut for
Enter
spe
cial
mean
ing
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 625
to en
close
spe
cial
keys
to
spec
ify
group
ing
Keys that are not displayed when you press them are also specified within braces, such as {En
ter} or {Up}. A list of these keys follows:
Keys can be combined with Shift, Ctrl, and Alt using the reserved keys " + ", " ^ ", and " % " respec
tively: 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})"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 626
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 "Hel
lo" ""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}"
Ex This example runs Notepad, writes to Notepad, and saves the new file using the SendKeys state
am ment.
ple Sub Main()
Dim id As Variant
Sleep 2000
Sleep 2000
AppClose
End Sub
Set (statement)
Com Syntax 1 The first syntax assigns the result of an expression to an object variable. This state
ments ment does not duplicate the object being assigned but rather copies a reference of an existing
object to an object variable. The object_expression is any expression that evaluates to an object
of the same type as the object_var. With data objects, Set performs additional processing. When
the Set is performed, the object is notified that a reference to it is being made and destroyed.
For example, the following statement deletes a reference to object A , then adds a new refer
ence to B .
Set a = b
Syntax 2 In the second syntax, the object variable is being assigned to a new instance of an ex
isting object type. This syntax is valid only for data objects. When an object created using the
New keyword goes out of scope (that is, 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 vari
able has been instantiated:
Set a = Nothing
Exam This example creates two objects and sets their values.
ple Sub Main()
MsgBox page.name
End Sub
See = (on page 227) (statement); Let (on page 498) (statement); CreateObject (on page 289)
Also (function); GetObject (on page 453) (function); Nothing (on page 541) (constant).
SetAttr (statement)
Descrip Changes the attribute filename$ to the given attribute. A runtime error results if the file can
tion not be found.
Parameter Description
The attribute parameter can contain any combination of the following values:
The attributes can be combined using the + operator or the binary Or operator.
Example This example creates a file and sets its attributes to Read-Only and System.
Sub Main()
Close #1
MsgBox "The file attribute was set to: " & GetAttr("test.dat")
SetAttr "test.dat",ebNormal
Kill "test.dat"
End Sub
See Also GetAttr (on page 451) (function); FileAttr (on page 424) (function).
Sgn (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 629
De Returns an Integer indicating whether a number is less than, greater than, or equal to 0.
scrip
tion
Com Returns 1 if number is greater than 0. Returns 0 if number is equal to 0. Returns –1 if number is
ments 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.
Exam This example tests the product of two numbers and displays a message based on the sign of
ple the result.
Sub Main()
a% = -100
b% = 100
c% = a% * b%
Case -1
Case 0
Case 1
End Select
End Sub
Shell (function)
Parameter Description
command$ String containing the name of the application and any parameters.
Window Optional Integer specifying the state of the application window after execution. It
Style can be any of the following values:
An error is generated if unsuccessful running command$. The Shell command runs programs
asynchronously: the statement following the Shell statement will execute before the child ap
plication has exited. On some platforms, the next statement will run before the child application
has finished loading. The Shell function returns a value suitable for activating the application
using the AppActivate statement. It is important that this value be placed into a Variant , as its
type depends on the platform.
Exam This example displays the Windows Clock, delays awhile, then closes it.
ple Sub Main()
id = Shell("clock.exe",1)
AppActivate "Clock"
Sleep(2000)
AppClose "Clock"
End Sub
See SendKeys (on page 623) (statement); AppActivate (on page 234) (statement)
Also
Note This function returns a global process ID that can be used to identify the new process.
Im CIMPLICITY runs as a service. Programs started from the Event Manager run as part of the ser
por vice. Services, by default, do not interact with the desktop. Therefore, shelling of a program such
tant as CimView, will cause the program to run, but with no interface.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 631
Sin (function)
Example This example displays the sine of pi/4 radians (45 degrees).
Sub Main()
c# = Sin(Pi / 4)
End Sub
See Also Tan (on page 664) (function); Cos (on page 306) (function);
Atn (on page 258) (function).
Syn Single
tax
De A data type used to declare variables capable of holding real numbers with up to seven digits of
scrip precision.
tion
Com Single variables are used to hold numbers within the following ranges: Sign Range Neg
ments ative -3.402823E38 <= single <= -1.401298E-45 Positive 1.401298E-45 <= single <=
3.402823E38 The type-declaration character for Single is ! .
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 Currency (on page 308) (data type); Date (on page 313) (data type); Double (on page 370)
Also (data type); Integer (on page 479) (data type); Long (on page 511) (data type); Object (on
page 546) (data type); String (on page 654) (data type); Variant (on page 684) (data type);
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 632
Boolean (on page 272) (data type); DefType (on page 333) (statement); CSng (on page
306) (function).
Sleep (statement)
Sub Main()
Sleep 2000
MsgClose
End Sub
Sln (function)
De Returns the straight-line depreciation of an asset assuming constant benefit from the asset.
scrip
tion
Com The Sln of an asset is found by taking an estimate of its useful life in years, assigning values to
ments each year, and adding up all the numbers. The formula used to find the Sln of an asset is as fol
lows:
Parameter Description
Salvage Double representing the estimated value of the asset at the end of its useful life.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 633
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.
Exam This example calculates the straight-line depreciation of an asset that cost $10,000.00 and has
ple a salvage value of $500.00 as scrap after 10 years of service life.
Sub Main()
dep# = Sln(10000.00,500.00,10)
End Sub
See SYD (on page 658) (function); DDB (on page 323) (function).
Also
Com Space$ returns a String , whereas Space returns a String variant. NumSpaces is an Inte
ments ger between 0 and 32767.
Example This example returns a string of ten spaces and displays it.
Sub Main()
ln$ = Space(10)
End Sub
See Also String, String$ (on page 656) (functions); Spc (on page 633) (function).
Spc (function)
De Prints out the specified number of spaces. This function can only be used with the Print and
scrip Print# statements.
tion
Com The numspaces parameter is an Integer specifying the number of spaces to be printed. It can
ments be any value between 0 and 32767. If a line width has been specified (using the Width state
ment), then the number of spaces is adjusted as follows:
If the resultant number of spaces is greater than width - print_position , then the number of
spaces is recalculated as follows:
These calculations have the effect of never allowing the spaces to overflow the line length. Fur
thermore, with a large value for column and a small line width, the file pointer will never ad
vance more than one line.
End Sub
See Tab (on page 663) (function); Print (on page 577) (statement); Print# (on page 578) (state
Also ment).
SQLBind (function)
De Specifies which fields are returned when results are requested using the SQLRetrieve or SQLRe-
scrip trieveToFile function.
tion
Com The following table describes the parameters to the SQLBind function:
ments
Pa Description
ra
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 635
me
ter
ar Any array of variants. Each call to SQLBind adds a new column number (an Integer) in the
ray 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.
col Optional Long parameter that specifies the column to which to bind data. If this parameter
umn 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 num
bers can be returned by binding column 0. The Basic Control Engine generates a runtime error
that can be trapped if SQLBind fails. Additional error information can then be retrieved using
the SQLError function.
id& = SQLOpen("dsn=SAMPLE",,3)
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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 636
See SQLRetrieve (on page 646) (function); SQLRetrieveToFile (on page 648) (function).
Also
SQLClose (function)
Com The unique connection ID (connectionID) is a Long value representing a valid connection as
ments returned by SQLOpen . After SQLClose is called, any subsequent calls made with the connec
tionID will generate runtime errors. The SQLClose function returns 0 if successful; otherwise, it
returns the passed connection ID and generates a trappable runtime error. Additional error infor
mation can then be retrieved using the SQLError function.
The Basic Control Engine automatically closes all open SQL connections when either the script
or the application terminates. You should use the SQLClose function rather than relying on
the application to automatically close connections in order to ensure that your connections are
closed at the proper time.
Dim s As String
id& = SQLOpen("dsn=SAMPLE",s$,3)
MsgBox "There are " & qry & " records in the result set."
id& = SQLClose(id&)
End Sub
SQLError (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 637
De Retrieves driver-specific error information for the most recent SQL functions that failed.
scrip
tion
Com This function is called after any other SQL function fails. Error information is returned in a two-
ments dimensional array (ErrArray). The following table describes the parameters to the SQLError
function:
Pa Description
ra
me
ter
Err Two-dimensional Variant array, which can be dynamic or fixed. If the array is fixed, it
Ar must be (x,3), where x is the number of errors you want returned. If x is too small to hold
ray 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.
ID Optional Long parameter specifying a connection ID. If this parameter is omitted, error in
formation is returned for the most recent SQL function call.
Each array entry in the ErrArray parameter describes one error. The three elements in each array
entry contain the following information:
Ele Value
ment
( en The ODBC error state, indicated by a Long containing the error class and subclass.
try
,0)
( en The text error message returned by the driver. This field is String type.
try
,2)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 638
For example, to retrieve the ODBC text error message of the first returned error, the array is ref
erenced as:
ErrArray(0,2)
The SQLError function returns the number of errors found. The Basic Control Engine generates
a runtime error if SQLError fails. (You cannot use the SQLError function to gather additional er
ror information in this case.)
Exam This example forces a connection error and traps it for use with the SQLError function.
ple Sub Main()
id& = SQLOpen("",,4)
id& = SQLClose(id&)
Exit Sub
Trap:
rc% = SQLError(a)
If (rc%) Then
For x = 0 To (rc% - 1)
MsgBox "The native error code returned was: " & a(x,1)
MsgBox a(x,2)
Next x
End If
End Sub
SQLExecQuery (function)
Com This function is called after a connection to a data source is established using the SQLOpen
ments function. The SQLExecQuery function may be called multiple times with the same connection
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 639
ID, each time replacing all results. The following table describes the parameters to the SQLEx
ecQuery function:
Parameter Description
ID Long identifying a valid connected data source. This parameter is returned by the
SQLOpen function.
query$ String specifying an SQL query statement. The SQL syntax of the string must
strictly follow that of the driver.
The return value of this function depends on the result returned by the SQL statement:
SELECT...FROM The value returned is the number of columns returned by the SQL state
ment.
DELETE,INSERT,UP The value returned is the number of rows affected by the SQL statement.
DATE
The Basic Control Engine generates a runtime error if SQLExecQuery fails. Additional error in
formation can then be retrieved using the SQLError function.
Dim s As String
id& = SQLOpen("dsn=SAMPLE",s$,3)
MsgBox "There are " & qry & " columns in the result set."
id& = SQLClose(id&)
End Sub
See SQLOpen (on page 642) (function); SQLClose (on page 636) (function); SQLRetrieve (on page
Also 646) (function); SQLRetrieveToFil (on page 648) (function)
SQLGetSchema (function)
De Returns information about the data source associated with the specified connection.
scrip
tion
Com The following table describes the parameters to the SQLGetSchema function:
ments
Pa Description
ra
me
ter
ID Long parameter identifying a valid connected data source. This parameter is returned by
the SQLOpen function.
ac Integer parameter specifying the results to be returned. The following table lists values for
tion this parameter:
Val Meaning
ue
4 Returns a one-dimensional array of table names for a specified owner and database
associated with the current connection. The array is returned in the array parameter.
(0,0) Zeroth column name (0,1) ODBC SQL data type ( Integer ) (1,0) First col
umn name (1,1) ODBC SQL data type ( Integer ) : : (n-1,0) Nth column name
(n-1,1) ODBC SQL data type ( Integer )
7 Returns a string containing the name (either the directory name or the database
name, depending on the driver) of the current database.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 641
8 Returns a string containing the name of the data source on the current connection.
9 Returns a string containing the name of the DBMS of the data source on the current
connection (for example, "FoxPro 2.5" or "Excel Files").
10 Returns a string containing the name of the server for the data source.
11 Returns a string containing the owner qualifier used by the data source (for example,
"owner," "Authorization ID," "Schema").
12 Returns a string containing the table qualifier used by the data source (for example,
"table," "file").
13 Returns a string containing the database qualifier used by the data source (for exam
ple, "database," "directory").
14 Returns a string containing the procedure qualifier used by the data source (for ex
ample, "database procedure," "stored procedure," "procedure").
ar Optional Variant array parameter. This parameter is only required for action values 1, 2,
ray 3, 4, and 5. The returned information is put into this array. If array is fixed and it is not the
correct size necessary to hold the requested information, then SQLGetSchema will fail.
If the array is larger than required, then any additional elements are erased. If array is dy
namic, then it will be redimensioned to hold the exact number of elements requested.
qual Optional String parameter required for actions 3, 4, or 5. The values are listed in the fol
ifier lowing table:
Ac Qualifier
tion
3 The qualifier parameter must be the name of the database represented by ID.
4 The qualifier parameter specifies a database name and an owner name. The syntax
for this string is: DatabaseName.OwnerName
5 The qualifier parameter specifies the name of a table on the current connection.
The Basic Control Engine generates a runtime error if SQLGetSchema fails. Additional error in
formation can then be retrieved using the SQLError function. If you want to retrieve the avail
able data sources (where action = 1) before establishing a connection, you can pass 0 as the ID
parameter. This is the only action that will execute successfully without a valid connection.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 642
This function calls the ODBC functions SQLGetInfo and SQLTables in order to retrieve the re
quested information. Some database drivers do not support these calls and will therefore cause
the SQLGetSchema function to fail.
Sub Main()
numdims% = SQLGetSchema(0,1,dsn)
If (numdims%) Then
For x = 0 To numdims% - 1
Next x
Else
End If
MsgBox msg1
End Sub
SQLOpen (function)
De Establishes a connection to the specified data source, returning a Long representing the
scrip unique connection ID.
tion
Com This function connects to a data source using a login string (login$) and optionally sets the
ments completed login string (completed$) that was used by the driver. The following table describes
the parameters to the SQLOpen function:
Para Description
meter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 643
login$ String expression containing information required by the driver to connect to the re
quested data source. The syntax must strictly follow the driver's SQL syntax.
com Optional String variable that will receive a completed connection string returned by the
plet driver. If this parameter is missing, then no connection string will be returned.
ed$
Val Meaning
ue
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.
The SQLOpen function will never return an invalid connection ID. The following example estab
lishes a connection using the driver's login dialog box:
id& = SQLOpen("",,1)
The Basic Control Engine 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 odbcadm.exe program.
Exam This example connects the data source called "sample," returning the completed connection
ple string, and then displays it.
Sub Main()
Dim s As String
id& = SQLOpen("dsn=SAMPLE",s$,3)
id& = SQLClose(id&)
End Sub
SQLQueryTimeout (statement)
De Specifies the timeout, in seconds, for ODBC queries. If you do not set SQLQueryTimeout , the
scrip default timeout is 60 seconds (1 minute).
tion
Parameter Description
Exam The following example sets the timeout for ODBC queries to 120 seconds (2 minutes).
ple Sub Main()
SQLQueryTimeout 120
End Sub
SQLRequest (function)
De Opens a connection, runs a query, and returns the results as an array.
scrip
tion
Para Description
meter
con String specifying the connection information required to connect to the data source.
nection
query String specifying the query to execute. The syntax of this string must strictly follow the
syntax of the ODBC driver.
array Array of variants to be filled with the results of the query. The array parameter must be
dynamic: it will be resized to hold the exact number of records and fields.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 645
output Optional String to receive the completed connection string as returned by the driver.
prompt Optional Integer specifying the behavior of the driver's dialog box.
is Optional Boolean specifying whether the column names are returned as the first row of
Column results. The default is False .
Names
The Basic Control Engine generates a runtime error if SQLRequest fails. Additional error infor
mation can then be retrieved using the SQLError function. The SQLRequest function performs
one of the following actions, depending on the type of query being performed:
Type of Action
Query
SELECT The SQLRequest function fills array with the results of the query, returning a Long con
taining the number of results placed in the array. The array is filled as follows (as
suming an x by y query):
(record 1,field 1)
(record 1,field 2)
(record 1,field y)
(record 2,field 1)
(record 2,field 2)
(record 2,field y)
(record x,field 1)
(record x,field 2)
(record x,field y)
INSERT, The SQLRequest function erases array and returns a Long containing the number
DELETE, of affected rows.
UPDATE
Exam This example opens a data source, runs a select query on it, and then displays all the data found
ple in the result set.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 646
Sub Main()
For x = 0 To Ubound(a)
For y = 0 To l - 1
MsgBox a(x,y)
Next y
Next x
End Sub
SQLRetrieve (function)
Com This function is called after a connection to a data source is established, a query is executed,
ments and the desired columns are bound. The following table describes the parameters to the SQL
Retrieve function:
Parame Description
ter
ID Long identifying a valid connected data source with pending query results.
array 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.
max Optional Integer expression specifying the maximum number of columns to be re
columns turned. 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
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 647
is filled, and additional results are placed in memory for subsequent calls to SQLRe
trieve.
is Optional Boolean specifying whether column names should be returned as the first
Column row of results. The default is FALSE.
Names
isFetch Optional Boolean expression specifying whether results are retrieved from the begin
First ning 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. The Basic
Control Engine generates a runtime error if SQLRetrieve fails. Additional error information is
placed in memory.
Exam This example executes a query on the connected data source, binds columns, and retrieves
ple them.
Sub Main()
id& = SQLOpen("DSN=SAMPLE",,3)
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 Ubound(b)
MsgBox c(x,y)
Next y
Next x
id& = SQLClose(id&)
End Sub
See SQLOpen (on page 642) (function); SQLExecQuery (on page 638) (function); SQLClose (on
Also page 636) (function); SQLBind (on page 634) (function); SQLRetrieveToFile (on page 648)
(function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 648
SQLRetrieveToFile (function)
De Retrieves the results of a query and writes them to the specified file.
scrip
tion
Com The following table describes the parameters to the SQLRetrieveToFile function:
ments
Parame Description
ter
destina String specifying the file where the results are written.
tion
is Optional Boolean specifying whether the first row of results returned are the bound
Column column names. By default, the column names are not returned.
Names
delimiter Optional String specifying the column separator. A tab ( Chr$(9) ) is used as the de
fault.
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 the Basic Control Engine is unable to open the specified file. The Ba
sic Control Engine generates a runtime error if SQLRetrieveToFile fails. Additional error infor
mation may be placed in memory for later use with the SQLError function.
Exam This example opens a connection, runs a query, binds columns, and writes the results to a file.
ple Sub Main()
id& = SQLOpen("DSN=SAMPLE;UID=RICH",,4)
i% = SQLBind(id&,b,3)
i% = SQLBind(id&,b,1)
i% = SQLBind(id&,b,2)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 649
i% = SQLBind(id&,b,6)
l& = SQLRetrieveToFile(id&,"c:\results.txt",True,",")
id& = SQLClose(id&)
End Sub
See SQLOpen (on page 642) (function); SQLExecQuery (on page 638) (function); SQLClose (on
Also page 636) (function); SQLBind (on page 634) (function); SQLRetrieve (on page 646) (func
tion).
Sqr (function)
Example This example calculates the square root of the numbers from 1 to 10 and displays
them.
Sub Main()
msg1 = ""
For x = 1 To 10
sx# = Sqr(x)
msg1 = msg1 & "The square root of " & x & " is " &_
Next x
MsgBox msg1
End Sub
Stop (statement)
Syn Stop
tax
De Suspends execution of the current script, returning control to a debugger if one is present. If a
scrip debugger is not present, this command will have the same effect as End .
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 650
Ex The Stop statement can be used for debugging. In this example, it is used to stop execution
am when Z is randomly set to 0.
ple Sub Main()
For x = 1 To 10
z = Random(0,10)
If z = 0 Then Stop
y = x / z
Next x
End Sub
See Exit For (on page 419) (statement); Exit Do (on page 418) (statement); Exit Function (on page
Also 419) (statement); Exit Sub (on page 420) (statement); End (on page 399) (statement).
Com The number parameter is any numeric expression or expression convertible to a number. If
ments number is negative, then the returned string will contain a leading minus sign. If number is posi
tive, then the returned string will contain a leading space. Singles are printed using only 7 signif
icant digits. Doubles are printed using 15–16 significant digits. These functions recognize the
decimal separator and thousands separators as specified in the Regional Settings in the Control
Panel. If the regional settings are changed, these functions will recognize it and act according
ly. The CStr , Format , and Format$ functions also determine their separators based on the re
gional settings.
Exam In this example, the Str$ function is used to display the value of a numeric variable.
ple Sub Main()
x# = 100.22
End Sub
See Format, Format$ (on page 438) (functions); CStr (on page 307) (function).
Also
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 651
StrComp (function)
De Returns an Integer indicating the result of comparing the two string arguments.
scrip
tion
0 string1 = string2
Parameter Description
string1 First string to be compared, which can be any expression convertible to a String.
compare Optional Integer specifying how the comparison is to be performed. It can be either
of the following values:
0 Case-sensitive comparison
1 Case-insensitive comparison
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 (that is, string comparison is
case-sensitive).
Exam This example compares two strings and displays the results. It illustrates that the function com
ple pares two strings to the length of the shorter string in determining equivalency.
Sub Main()
c$ = "This string"
msg1 = msg1 & "d = " & d & crlf & crlf
abc = StrComp(a$,b$,1)
msg1 = msg1 & "a and c (insensitive) : " & abc & crlf
abi = StrComp(a$,b$,0)
msg1 = msg1 & "a and c (sensitive): " & abi & crlf
cdc = StrComp(c$,d$,1)
msg1 = msg1 & "c and d (insensitive): " & cdc & crlf
cdi = StrComp(c$,d$,0)
msg1 = msg1 & "c and d (sensitive) : " & cdi & crlf
MsgBox msg1
End Sub
See Comparison Operators (on page 297) (topic); Like (on page 499) (operator); Option Compare
Also (on page 562) (statement).
StrConv (function)
Parameter Description
ebProper 3 Capitalizes the first letter of each word and lower-cases all the letters. This
Case constant is supported on all platforms.
ebUnicode 64 Converts string from MBCS to UNICODE. (This constant can only be used on
platforms supporting UNICODE.)
ebFromUni 128 Converts string from UNICODE to MBCS. (This constant can only be used on
code platforms supporting UNICODE.)
A runtime error is generated when a conversion is requested that is not supported on the cur
rent platform. For example, the ebWide and ebNarrow constants can only be used on an MBCS
platform. (You can determine platform capabilities using the Basic.Capabilities method.) The
following groupings of constants are mutually exclusive and therefore cannot be specified at
the same time:
ebWide, ebNarrow
ebUnicode, ebFromUnicode
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 654
Many of the constants can be combined. For example, ebLowerCase Or ebNarrow. When convert
ing to proper case (i.e., the ebProperCase constant), the following are seen as word delimiters:
tab, linefeed, carriage-return, formfeed, vertical tab, space, null.
Exam
ple Sub Main()
End If
End Sub
See UCase, UCase$ (on page 678) (functions), LCase, LCase$ (on page 494) (functions), Ba
Also sic.Capability (on page 260) (method)
Syn String
tax
Com Strings are used to hold sequences of characters, each character having a value between 0 and
ments 255. Strings can be any length up to a maximum length of 32767 characters. Strings can con
tain embedded nulls, as shown in the following example: s$ = "Hello" + Chr$(0) + "there" 'String
with embedded null
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 655
The length of a string can be determined using the Len function. This function returns the num
ber of characters that have been stored in the string, including unprintable characters. The type-
declaration character for String is $ .
String variables that have not yet been assigned are set to zero-length by default.
Strings are normally declared as variable-length, meaning that the memory required for storage
of the string depends on the size of its content. The following script statements declare a vari
able-length string and assign it a value of length 5:
Dim s As String
Fixed-length strings are given a length in their declaration: Dim s As String * 20 s = "Hel
lo" 'String has length 20 (internally pads with spaces).
When a string expression is assigned to a fixed-length string, the following rules apply:
• If the string expression is less than the length of the fixed-length string, then the fixed-
length string is padded with spaces up to its declared length.
• If the string expression is greater than the length of the fixed-length string, then the string
expression is truncated to the length of the fixed-length string.
Fixed-length strings are useful within structures when a fixed size is required, such as when
passing structures to external routines.
The storage for a fixed-length string depends on where the string is declared, as described in the
following table:
In In the same data area as that of the structure. Local structures are on the stack; public
struc structures are stored in the public data space; and private structures are stored in the
tures private data space. Local structures should be used sparingly as stack space is limited.
In ar In the global string space along with all the other array elements.
rays
Local On the stack. The stack is limited in size, so local fixed-length strings should be used
rou sparingly.
tines
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 656
See Currency (on page 308) (data type);Date (on page 313) (data type); Double (on page 370)
Also (data type); Integer (on page 479) (data type); Long (on page 511) (data type); Object (on
page 546) (data type); Single (on page 631) (data type); Variant (on page 684) (data type);
Boolean (on page 272) (data type); DefType (on page 333) (statement); CStr (on page 307)
(function).
De Returns a string of length number consisting of a repetition of the specified filler character.
scrip
tion
Com String$ returns a String, whereas String returns a String variant. These functions take the fol
ments lowing parameters:
Pa Description
ra
me
ter
Char Integer specifying the character code to be used as the filler character. If CharCode is
Code greater than 255 (the largest character value), then the Basic Control Engine converts it to
a valid character using the following formula: CharCode Mod 256
text$ Any String expression, the first character of which is used as the filler character.
Exam This example uses the String function to create a line of "=" signs the length of another string
ple and then displays the character string underlined with the generated string.
Sub Main()
b$ = String(Len(a$),"_")
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 657
5. 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:
Switch (function)
Com The Switch function evaluates each condition and expression, returning the expression that
ments 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 num
ber of parameters (that is, there is a condition without a corresponding expression). The Switch
function returns Null if no condition evaluates to True .
Exam The following code fragment displays the current operating platform. If the platform is un
ple known, then the word "Unknown" is displayed.
Sub Main()
Dim a As Variant
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 658
See Choose (on page 283) (function); IIf (on page 468) (function); If...Then...Else (on page 466)
Also (statement); Select...Case (on page 620) (statement).
SYD (function)
De Returns the sum of years' digits depreciation of an asset over a specific period of time.
scrip
tion
Com The SYD of an asset is found by taking an estimate of its useful life in years, assigning values
ments to each year, and adding up all the numbers. The formula used to find the SYD of an asset is as
follows:
Para Description
meter
Sal Double representing the estimated value of the asset at the end of its useful life.
vage
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.
Exam In this example, an asset that cost $1,000.00 is depreciated over ten years. The salvage value is
ple $100.00, and the sum of the years' digits depreciation is shown for each year.
Sub Main()
msg1 = ""
For x = 1 To 10
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 659
dep# = SYD(1000,100,10,x)
msg1 = msg1 & "Year: " & x & " Dep: " & Format(dep#,"Currency") & crlf
Next x
MsgBox msg1
End Sub
See Sln (on page 632) (function); DDB (on page 323) (function)
Also
System.Exit (method)
Syntax System.Exit
Example This example asks whether the user would like to restart Windows after exiting.
Sub Main
End Sub
System.FreeMemory (property)
Syntax System.FreeMemory
Example The following example gets the free memory and converts it to kilobytes.
Sub Main()
FreeMem& = System.FreeMemory
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 660
See Also System.TotalMemory (on page 661) (property); System.FreeResources (on page 660)
(property); Basic.FreeMemory (on page 262) (property).
System.FreeResources (property)
Syntax System.FreeResources
Sub Main()
FreeRes% = System.FreeResources
End Sub
See Also System.TotalMemory (on page 661) (property); System.FreeMemory (on page 659)
(property); Basic.FreeMemory (on page 262) (property).
System.MouseTrails (method)
Com If isOn is True , then mouse trails are turned on; otherwise, mouse trails are turned off. A run
ments time error is generated if mouse trails is not supported on your system.
System.MouseTrails 1
End Sub
System.Restart (method)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 661
Syntax System.Restart
Example This example asks whether the user would like to restart Windows after exiting.
Sub Main
"Exit Windows")
End Sub
System.TotalMemory (property)
Syntax System.TotalMemory
Descrip Returns a Long representing the number of bytes of available free memory in Windows.
tion
Sub Main()
TotMem& = System.TotalMemory
End Sub
See Also System.FreeMemory (on page 659) (property); System.FreeResources (on page 660)
(property); Basic.FreeMemory (on page 262) (property).
System.WindowsDirectory$ (property)
Syntax System.WindowsDirectory$
Sub Main
End Sub
System.WindowsVersion$ (property)
Syn System.WindowsVersion$
tax
Com
ments
Exam This example sets the UseWin31 variable to True if the Windows version is greater than or equal
ple to 3.1; otherwise, it sets the UseWin31 variable to False.
Sub Main()
Else
End If
End Sub
T
T
Tab (function)
Tan (function)
Text (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 663
TextBox (statement)
Timer (function)
TimeSerial (function)
TimeValue (function)
True (constant)
Type (statement)
TypeName (function)
TypeOf (function)
Tab (function)
De Prints the number of spaces necessary to reach a given column position.
scrip
tion
Com This function can only be used with the Print and Print# statements. The column parameter is
ments an Integer specifying the desired column position to which to advance. It can be any value be
tween 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 posi
tion is adjusted as follows before applying the above two rules:
The Tab function is useful for making sure that output begins at a given column position, re
gardless of the length of the data already printed on that line.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 664
Exam This example prints three column headers and three numbers aligned below the column head
ple ers.
Sub Main()
Print "Column1";Tab(10);"Column2";Tab(20);"Column3"
Print Tab(3);"1";Tab(14);"2";Tab(24);"3"
End Sub
See Spc (on page 633) (function); Print (on page 577) (statement); Print# (on page 578) (state
Also ment).
Tan (function)
Example This example computes the tangent of pi/4 radians (45 de
grees).
Sub Main()
c# = Tan(Pi / 4)
End Sub
See Also Sin (on page 631) (function); Cos (on page 306) (function);
Atn (on page 258) (function).
Text (statement)
De Defines a text control within a dialog box template. The text control only displays text; the user
scrip cannot set the focus to a text control or otherwise interact with it.
tion
Com The text within a text control word-wraps. Text controls can be used to display up to 32K of text.
ments The Text statement accepts the following parameters:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 665
Para Description
meter
x, y Integer positions of the control (in dialog units) static to the upper left corner of the di
alog box.
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 state
ment in the dialog box template.
Identifi Name by which this control can be referenced by statements in a dialog function
er (such as DlgFocus and DlgEnable). If omitted, then the first two words from title$ are
used.
Font Name of the font used for display of the text within the text control. If omitted, then
Name$ the default font for the dialog is used.
size Size of the font used for display of the text within the text control. If omitted, then the
default size for the default font of the dialog is used.
style Style of the font used for display of the text within the text control. This can be any of
the following values:
CancelButton 80,32,40,14
OKButton 80,8,40,14
End Dialog
Dim d As UserDialog
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 666
Dialog d
End Sub
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
564) (statement); OptionGroup (on page 566) (statement); Picture (on page 570) (state
ment); PushButton (on page 584) (statement); TextBox (on page 666) (statement); Begin Di
alog (on page 269) (statement), PictureButton (on page 572) (statement).
Note Accelerators are underlined, and the Alt+letter accelerator combination is used. 8-point MS Sans
Serif is the default font used within user dialogs.
TextBox (statement)
De Defines a single or multiline text-entry field within a dialog box template.
scrip
tion
Com If isMultiline is 1, the TextBox statement creates a multiline text-entry field. When the user
ments types into a multiline field, pressing the Enter key creates a new line rather than selecting the de
fault button. This statement can only appear within a dialog box template (that is, between the
Begin Dialog and End Dialog statements). The TextBox statement requires the following pa
rameters:
Parameter Description
x, y Integer position of the control (in dialog units) static to the upper left corner
of the dialog box.
DialogVariable
Identifier
isMultiline Specifies whether the text box can contain more than a single line (0 = sin
gle-line; 1 = multiline).
FontName$ Name of the font used for display of the text within the text box control. If
omitted, then the default font for the dialog is used.
size Size of the font used for display of the text within the text box control. If
omitted, then the default size for the default font of the dialog is used.
style Style of the font used for display of the text within the text box control. This
can be any of the following values:
When the dialog box is created, the Identifier variable is used to set the initial content of the text
box. When the dialog box is dismissed, the variable will contain the new content of the text box.
A single-line text box can contain up to 256 characters. The length of text in a multiline text box
is not limited by the Basic Control Engine; the default memory limit specified by the given plat
form is used instead.
CancelButton 80,32,40,14
OKButton 80,8,40,14
TextBox 4,8,68,44,.TextBox1,1
End Dialog
Dim d As UserDialog
d.TextBox1 = "Enter text before invoking" 'Display text in the Textbox by setting the default value of the
Dialog d
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 668
See CancelButton (on page 286) (statement); CheckBox (on page 281) (statement); ComboBox
Also (on page 294) (statement); Dialog (on page 336) (function); Dialog (on page 338) (state
ment); DropListBox (on page 371) (statement); GroupBox (on page 457) (statement); List
Box (on page 504) (statement); OKButton (on page 551) (statement); OptionButton (on page
564) (statement); OptionGroup (on page 566) (statement); Picture (on page 570) (state
ment); PushButton (on page 584) (statement); Text (on page 664) (statement); Begin Dialog
(on page 269) (statement), PictureButton (on page 572) (statement).
Note 8-point MS Sans Serif is the default font used within user dialogs.
Syn Time[$][()]
tax
Com The Time$ function returns a String contains the time in 24-hour time format, whereas Time
ments returns a Date variant. To set the time, use the Time/Time$ statements.
Exam This example returns the system time and displays it in a dialog box.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
oldtime$ = Time
Time = "10:30:54"
msg1 = msg1 & "Time set to: " & Time & crlf
Time = oldtime$
MsgBox msg1
End Sub
See Time, Time$ (on page 668) (statements); Date, Date$ (on page 314) (functions); Date, Date$
Also (on page 315) (statements); Now (on page 541) (function).
De Sets the system time to the time contained in the specified string.
scrip
tion
Com The Time$ statement requires a string variable in one of the following formats: HH HH:MM
ments 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.
Exam This example returns the system time and displays it in a dialog box.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
oldtime$ = Time
Time = "10:30:54"
msg1 = msg1 & "Time set to: " & Time & crlf
Time = oldtime$
MsgBox msg1
End Sub
See Time, Time$ (on page 668) (statements); Date, Date$ (on page 314) (functions); Date, Date$
Also (on page 315) (statements); Now (on page 541) (function).
Note: If you do not have permission to change the time, a runtime error 70 will be generated.
Timer (function)
Syntax Timer
Descrip Returns a Single representing the number of seconds that have elapsed since midnight.
tion
Exam This example displays the elapsed time between execution start and the time you clicked the
ple OK button on the first message.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 670
Sub Main()
start& = Timer
MsgBox "The elapsed time was: " & total& & " seconds."
End Sub
See Al Time, Time$ (on page 668) (functions); Now (on page 541) (function).
so
TimeSerial (function)
Syntax TimeSerial(hour,minute,second)
Description Returns a Date variant representing the given time with a date of ze
ro.
Parameter Description
start# = TimeSerial(10,22,30)
finish# = TimeSerial(10,35,27)
End Sub
See Also DateValue (on page 322) (function); TimeValue (on page 670)
(function); DateSerial (on page 321) (function).
TimeValue (function)
De Returns a Date variant representing the time contained in the specified string argument.
scrip
tion
Com This function interprets the passed time_string$ parameter looking for a valid time specifica
ments tion. The time_string$ 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."
Exam This example calculates the TimeValue of the current time and displays it in a dialog box.
ple Sub Main()
t1$ = "10:15"
t2# = TimeValue(t1$)
MsgBox "The TimeValue of " & t1$ & " is: " & t2#
End Sub
See DateValue (on page 322) (function); TimeSerial (on page 670) (function); DateSerial (on page
Also 321) (function).
Function Returns
Trim Copy of the passed string expression (string) with both the leading and
trailing spaces removed.
Com Trim$ returns a String , whereas Trim returns a String variant. Null is returned if text is
ments Null .
Exam
ple 1 'This first example uses the Trim$ function to extract the
Sub Main()
tr$ = Trim$(text$)
MsgBox "Original =>" & text$ & "<=" & crlf & _
End Sub
Exam
ple 2 'This second example displays a right-justified string and its
'LTrim result.
Sub Main()
b$ = LTrim$(a$)
End Sub
Exam
ple 3 'This third example displays a left-justified string and its
'RTrim result.
Sub Main()
b$ = RTrim$(a$)
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 673
See Al LTrim, LTrim$ (on page 512) (functions); RTrim, RTrim$ (on page 609) (functions).
so
True (constant)
Exam This example sets variable a to True and then tests to see whether (1) A is True; (2) the True
ple constant = -1; and (3) A is equal to -1 (True).
Sub Main()
a = True
Else
End If
End Sub
See Al False (on page 424) (constant); Constants (topic); Boolean (on page 272) (data type).
so
Type (statement)
variable As type
variable As type
End Type
De The Type statement creates a structure definition that can then be used with the Dim state
scrip ment to declare variables of that type. The username field specifies the name of the structure
tion that is used later with the Dim statement.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 674
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 with
in structure definitions. The Type statement can only appear outside of subroutine and func
tion 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 ex
ample, 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.
Exam This example displays the use of the Type statement to create a structure representing the parts
ple of a circle and assign values to them.
Type Circ
msg As String
rad As Integer
dia As Integer
are As Double
cir As Double
End Type
Sub Main()
circle.rad = 5
circle.dia = circle.rad * 2
circle.are = (circle.rad ^ 2) * Pi
circle.cir = circle.dia * Pi
MsgBox circle.msg
End Sub
See Dim (on page 338) (statement); Public (on page 582) (statement); Private (on page 581)
Also (statement).
TypeOf (function)
Com This function is used within the If...Then statement to determine if a variable is of a particular
ments type. This function is particularily useful for determining the type of OLE automation objects.
Exam
ple Sub Main()
Dim a As Object
Set a = CreateObject("Excel.Application")
End If
End Sub
TypeName (function)
"String" A String.
object A data object variable. In this case, objecttype is the name of the specific object type.
type
"Integer" An integer.
"Long" A long.
"Single" A single.
"Double" A double
class A specific type of OLE automation object. In this case, class is the name of the ob
ject as known to OLE.
If Var then
name is
an
array 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.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 677
expres the expression is evaluated and a String representing the resultant data type is re
sion turned.
Exam
ple 'The following example defines a subroutine that only accepts
'the user that there was an error, displaying the actual type
MsgBox "Foo does not support " & TypeName(a) & " variables"
End If
End Sub
U
U
UBound (function)
Unlock (statement)
UBound (function)
De Returns an Integer containing the upper bound of the specified dimension of the specified ar
scrip ray variable.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 678
Com The dimension parameter is an integer that specifies the desired dimension. If not specified,
ments 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 prop
erty:
UBound(object.property [,dimension])
UBound(object.method [,dimension])
Exam This example dimensions two arrays and displays their upper bounds.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
uba = UBound(a)
ubb = UBound(b,2)
MsgBox "The upper bound of a is: " & uba & crlf & " 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
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
See LBound (on page 493) (function); ArrayDims (on page 249) (function); Arrays (on page
Also 250) (topic).
Com UCase$ returns a String , whereas UCase returns a String variant. Null is returned if
ments text is Null .
Example This example uses the UCase$ function to change a string from lowercase to uppercase.
Sub Main()
a2$ = UCase(a1$)
MsgBox a2$
End Sub
Unlock (statement)
De Unlocks a section of the specified file, allowing other processes access to that section of the
scrip file.
tion
Parameter Description
filenumber Integer used by the Basic Control Script to refer to the open file—the number
passed to the Open statement.
For sequential files, the record, start, and end parameters are ignored: the entire file is unlocked.
The section of the file is specified using one of the following:
Syntax Description
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 680
record Unlock the specified record number (for Random files) or byte (for Binary files).
to end Unlock from the beginning of the file to the specified record (for Random files)
or byte (for Binary files).
start to end Unlock the specified range of records (for Random files) or bytes (for Binary
files).
The unlock range must be the same as that used by the Lock statement.
Exam This example creates a file named test.dat and fills it with ten string variable records. These are
ple 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.
Sub Main()
b$ = "0"
rec$ = ""
msg1 = ""
For x = 1 To 10
rec$ = a$ & x
Lock #1,x
Put #1,,rec$
Unlock #1,x
Next x
Close
msg1 = ""
For x = 1 to 10
UnLock #1,x
Next x
Close
Kill "test.dat"
End Sub
See Lock (on page 507) (statement); Open (on page 554) (statement).
Also
User-defined types (UDTs) are structure definitions created using the Type statement. UDTs are equiva
lent to C language structures.
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
r.left = 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 oth
er standard operators can be applied to UDTs.
Dim r1 As Rect
Dim r2 As Rect
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 682
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 cannot be used with UDTs containing variable-length strings. The smaller of the two structures de
termines 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 refer
ence, 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 the Basic Control Engine'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.
V
V
Val (function)
VarType (function)
Viewport.Clear (method)
Viewport.Close (method)
Viewport.Open (method)
VLine (statement)
VPage (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 683
VScroll (statement)
Val (function)
Spaces, tabs, and line feeds are ignored. If number does not contain a number, then 0 is re
turned.
The Val function continues to read characters from the string up to the first nonnumeric char
acter. The Val function always returns a double-precision floating-point value. This value is
forced to the data type of the assigned variable.
Exam This example inputs a number string from an InputBox and converts it to a number variable.
ple Sub Main()
b# = Val(a$)
End Sub
'The following table shows valid strings and their numeric equivalents:
' "&HFFFF" -1
' "&O77" 63
See CDbl (on page 277) (function); Str, Str$ (on page 656) (functions).
Also
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 684
Assigning to VariantsBefore 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
VariantsNormally, 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:
a% = 32767
b% = 1
x = 32767
y = 1
In the above example, the addition involving Integer variables overflows because the result (32768)
overflows the legal range for integers. With Variant variables, on the other hand, the addition operator
recognizes the overflow and automatically promotes the result to a Long .Adding VariantsThe + 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.Variants That Contain No DataA
Variant can be set to a special value indicating that it contains no valid data by assigning the Variant to
Null:
Dim a As Variant
a = Null
The only way that a Variant becomes Null is if you assign it as shown above.The Null value can be
useful for catching errors since its value propagates through an expression.Variant StorageVariants
require 16 bytes of storage internally:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 685
• A 2-byte type
• A 2-byte extended type for data objects
• 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
VariantsThe following list describes some disadvantages of variants:
1. Using variants is slower than using the other fundamental data types (that is, 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.
Passing Nonvariant Data to Routines Taking VariantsPassing nonvariant data to a routine that
is declared to receive a variant by reference prevents that variant from changing type within that
routine. For example:
v = 50 'OK.
End Sub
Sub Main()
Dim i As Integer
End Sub
In the above example, since an Integer is passed by reference (meaning that the caller can
change the original value of the Integer ), the caller must ensure that no attempt is made to
change the variant's type.Passing Variants to Routines Taking NonvariantsVariant variables
cannot be passed to routines that accept nonvariant data by reference, as demonstrated in the
following example:
End Sub
Sub Main()
Dim a As Variant
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 686
End Sub
VarType (function)
Com The variable parameter is the name of any Variant . The following table shows the different val
ments ues that can be returned by VarType :
0 ebEmpty Uninitialized
2 ebInteger Integer
3 ebLong Long
4 ebSingle Single
5 ebDouble Double
6 ebCurrency Currency
7 ebDate Date
8 ebString String
11 ebBoolean Boolean
Com When passed an object, the VarType function returns the type of the default property of that
ments object. If the object has no default property, then either ebObject or ebDataObject is returned,
depending on the type of variable.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 687
End If
End Sub
See Empty (on page 399) (constant); Null (on page 544) (constant); Variant (on page 684) (da
Also ta type).
Viewport.Clear (method)
Syntax Viewport.Clear
Example
Sub Main()
Viewport.Open
Sleep 2000
Viewport.Clear
Sleep 2000
Viewport.Close
End Sub
See Also Viewport.Close (on page 687) (method), Viewport.Open (on page 688)
(method)
Viewport.Close (method)
Syntax Viewport.Close
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 688
Example
Sub Main()
Viewport.Open
Sleep 2000
Viewport.Close
End Sub
Viewport.Open (method)
De Opens a new viewport window or switches the focus to the existing viewport window.
scrip
tion
Parameter Description
title Specifies a String containing the text to appear in the viewport's caption.
XPos, YPos Specifies Integer coordinates given in twips indicating the initial position of the
upper left corner of the viewport.
width,height Specifies Integer values indicating the initial width and height of the viewport.
If a viewport window is already open, then it is given the focus. Otherwise, a new viewport win
dow is created. Combined with the Print statement, a viewport window is a convenient place to
output debugging information. The viewport window is closed when the BasicScript host appli
cation is terminated. The following keys work within a viewport window:
Key Scrolls
Up Up by one line.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 689
Only one viewport window can be open at any given time. Any scripts with Print statements will
output information into the same viewport window. When printing to viewports, the end-of-line
character can be any of the following: a carriage return, a line feed, or a carriage-return/line-feed
pair. Embedded null characters are printed as spaces.
Exam
ple Sub Main()
Sleep 2000
Viewport.Close
End Sub
VLine (statement)
De Scrolls the window with the focus up or down by the specified number of lines.
scrip
tion
Com The lines parameter is an Integer specifying the number of lines to scroll. If this parameter is
ments omitted, then the window is scrolled down by one line.
Exam This example prints a series of lines to the viewport, then scrolls back up the lines to the top us
ple ing VLine.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 690
Sub Main()
"BasicScript Viewport",100,100,500,200
For i = 1 to 50
Next i
VLine -40
End Sub
See Al VPage (on page 690) (statement); VScroll (on page 690) (statement).
so
VPage (statement)
De Scrolls the window with the focus up or down by the specified number of pages.
scrip
tion
Com The pages parameter is an Integer specifying the number of lines to scroll. If this parameter is
ments omitted, then the window is scrolled down by one page.
"BasicScript Viewport",100,100,500,200
For i = 1 to 500
Next i
VLine -5
End Sub
See VLine (on page 689) (statement); VScroll (on page 690) (statement).
Also
VScroll (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 691
De Sets the thumb mark on the vertical scroll bar attached to the current window.
scrip
tion
Com The position is given as a percentage of the total range associated with that scroll bar. For ex
ments ample, if the percentage parameter is 50, then the thumb mark is positioned in the middle of the
scroll bar.
Exam This example prints a bunch of lines to the viewport, then scrolls back to the top using VScroll .
ple Sub Main()
"BasicScript Viewport",100,100,500,200
For i = 1 to 50
Next i
MsgBox Message$
VScroll 0
VScroll 0
End Sub
See VLine (on page 689) (statement); VPage (on page 690) (statement).
Also
W
W
Weekday (function)
While...Wend (statement)
Width# (statement)
WinActivate (statement)
WinClose (statement)
WinFind (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 692
WinList (statement)
WinMaximize (state
ment)
WinMinimize (statement)
WinMove (statement)
WinRestore (statement)
WinSize (statement)
Word$ (function)
WordCount (function)
Write# (statement)
WriteIni (statement)
Weekday (function)
De Returns an Integer value representing the day of the week given by date. Sunday is 1, Monday is
scrip 2, and so on. The date parameter is any expression representing a valid date.
tion
Ex This example gets a date in an input box and displays the day of the week and its name for the
am date entered.
ple Sub Main()
Dim a$(7)
a$(1) = "Sunday"
a$(2) = "Monday"
a$(3) = "Tuesday"
a$(4) = "Wednesday"
a$(5) = "Thursday"
a$(6) = "Friday"
a$(7) = "Saturday"
Reprompt:
dt = DateValue(bd)
dw = WeekDay(dt)
Msgbox "You were born on day " & dw & ", which was a " & a$(dw)
End Sub
See Day (on page 322) (function);Minute (on page 519) (function); Second (on page 617) (func
Also tion); Month (on page 522) (function); Year (on page 710) (function); Hour (on page 461)
(function); DatePart (on page 319) (function).
While...Wend (statement)
Com The condition is initially and then checked at the top of each iteration through the loop.
ments
Exam This example executes a While loop until the random number generator returns a value of 1.
ple Sub Main()
x% = 0
count% = 0
x% = Rnd(1)
Exit Sub
Else
count% = count% + 1
End If
Wend
MsgBox "The loop executed " & count% & " times."
End Sub
See Al Do...Loop (on page 366) (statement); For...Next (on page 436) (statement).
so
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 694
Note: Due to errors in program logic, you can inadvertently create infinite loops in your code. You can
break out of infinite loops using Ctrl+Break.
Width# (statement)
De Specifies the line width for sequential files opened in either Output or Append mode.
scrip
tion
Parame Description
ter
filenum Integer used by the Basic Control Engine to refer to the open file—the number passed
ber to the Open statement.
newwidth Integer between 0 to 255 inclusive specifying the new width. If newwidth 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 subse
quent 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 cur
rent line width, then the data is written on the next line. The Width statement also affects out
put of the Print command when used with the Tab and Spc functions.
Exam This statement sets the maximum line width for file number 1 to 80 columns.
ple Const crlf$ = Chr$(13) + Chr$(10)
Sub Main()
Dim i,msg1,newline$
For i = 0 To 9
Print #1,Chr(48 + i); 'Print 0-9 to test file all on same line.
Next i
For i = 0 To 9 'Print 0-9 again. This time, five characters print before line wraps.
Next I
Close #1
msg1 = "The effect of the Width statement is as shown below: " & crlf
Input #1,newline$
Loop
Close #1
msg1 = msg1 & crlf$ & crlf$ & "Choose OK to remove the test file."
Kill "test.dat"
End Sub
See Print (on page 577) (statement); Print# (on page 578) (statement); Tab (on page 663)
Also (function); Spc (on page 633) (function)
WinActivate (statement)
De Activates the window with the given name or object value.
scrip
tion
Para Description
me
ter
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing example:
WinActivate "Notepad|Find"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 696
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 ."
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
time Integer specifying the number of milliseconds for which to attempt activation of the
out specified window. If not specified (or 0), then only one attempt will be made to activate
the window. This value is handy when you are not certain that the window you are at
tempting to activate has been created.
Exam This example runs the clock.exe program by activating the Run File dialog box from within Pro
ple gram Manager.
Sub Main()
Menu "File.Run"
SendKeys "clock.exe{ENTER}"
End Sub
WinClose (statement)
Para Description
me
ter
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing 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" .
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
If window_name$ and window_object are omitted, then the window with the focus is closed.
This command differs from the AppClose command in that this command operates on the cur
rent window rather than the current top-level window (or application).
Exam This example closes Microsoft Word if its object reference is found.
ple Sub Main()
End Sub
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
WinFind (function)
Descrip Returns an object variable referencing the window having the given name.
tion
Com The name$ parameter is specified using the same format as that used by the WinActivate
ments statement.
Example This example closes Microsoft Word if its object reference is found.
Sub Main()
End Sub
WinList (statement)
De Fills the passed array with references to all the top-level windows.
scrip
tion
Com The passed array must be declared as an array of HWND objects. The ArrayOfWindows para
ments meter 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 num
ber 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 ele
ments are unused. A runtime error results if the array is too small to hold the new elements. Af
ter calling this function, use the LBound and UBound functions to determine the new size of
the array.
WinList a
For i = 1 To UBound(a)
WinMinimize a(i)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 699
Next i
End Sub
WinMaximize (statement)
Para Description
me
ter
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing 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" .
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
If window_name$ and window_object are omitted, then the window with the focus is maxi
mized. This command differs from the AppMaximize command in that this command operates
on the current window rather than the current top-level window.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 700
WinList a
For i = 1 To UBound(a)
WinMaximize a(i)
Next i
End Sub
See WinMinimize (on page 700) (statement); WinRestore (on page 702) (statement).
Also
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
WinMinimize (statement)
Para Description
me
ter
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing 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" .
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 701
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
If window_name$ and window_object are omitted, then the window with the focus is minimized.
This command differs from the AppMinimize command in that this command operates on the
current window rather than the current top-level window.
See WinMaximize (on page 699) (statement); WinRestore (on page 702) (statement).
Also
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
WinMove (statement)
Para Description
me
ter
x,y Integer coordinates given in twips that specify the new location for the window.
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing example:
WinActivate "Notepad|Find"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 702
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".
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
If window_name$ and window_object are omitted, then the window with the focus is moved.
This command differs from the AppMove command in that this command operates on the current
window rather than the current top-level window. When moving child windows, remember that
the x and y coordinates are static to the client area of the parent window.
Exam This example moves Program Manager to upper left corner of the screen.
ple WinMove 0,0,"Program Manager"
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
WinRestore (statement)
Com Restoring a minimized window restores that window to its screen position before it was mini
ments mized. Restoring a maximized window resizes the window to its size previous to maximizing.
The WinRestore statement requires the following parameters:
Para Description
me
ter
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 703
win String containing the name that appears on the desired application's title bar. Optionally,
dow_ a partial name can be used, such as "Word" for "Microsoft Word." A hierarchy of windows
name$ can be specified by separating each window name with a vertical bar (|), as in the follow
ing 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" .
win HWND object specifying the exact window to activate. This can be used in place of the
dow_ window_name$ parameter to indicate a specific window to activate.
ob
ject
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.
Exam This example minimizes all top-level windows except for Program Manager.
ple Sub Main()
WinList a
For i = 0 To UBound(a)
WinMinimize a(i)
Next I
End Sub
See WinMaximize (on page 699) (statement); WinMinimize (on page 700) (statement)
Also
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
WinSize (statement)
De Resizes the given window to the specified width and height.
scrip
tion
Parameter Description
width,height Integer coordinates given in twips that specify the new size of the window.
window_ String containing the name that appears on the desired application's title bar. Op
name$ tionally, a partial name can be used, such as "Word" for "Microsoft Word." A hierar
chy 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 con
tains the word "Notepad" . If found, the windows owned by the top level window
are searched for one whose title contains the string "Find" .
window_ob HWND object specifying the exact window to activate. This can be used in place
ject 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 cur
rent window rather than the current top-level window.
id = Shell("Notepad.exe")
WinSize 4400,8500,NotepadApp
End Sub
Note Under Windows, the current window can be an MDI child window, a pop-up window, or a top-lev
el window.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 705
Word$ (function)
De Returns a String containing a single word or sequence of words between first and last.
scrip
tion
Pa Description
ra
me
ter
first Integer specifying the index of the first word in the sequence to return. If last is not speci
fied, 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 non-alphanumeric characters such as spaces, tabs, end-of-lines,
and punctuation. 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.
Exam This example finds the name "Stuart" in a string and then extracts two words from the string.
ple Sub Main()
c$ = Word$(s$,5,6)
End Sub
See Item$ (on page 489) (function); ItemCount (on page 490) (function); Line$ (on page 501)
Also (function); LineCount (on page 502) (function); WordCount (on page 706) (function).
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 706
WordCount (function)
Descrip Returns an Integer representing the number of words in the specified text.
tion
Sub Main()
i% = WordCount(s$)
MsgBox "'" & s$ & "' has " & i% & " words."
End Sub
See Also Item$ (on page 489) (function); ItemCount (on page 490) (function); Line$ (on page
501) (function); LineCount (on page 502) (function); Word$ (on page 705) (function).
Write# (statement)
Com The file referenced by filenumber must be opened in either Output or Append mode. The
ments filenumber parameter is an Integer used by the Basic Control Engine to refer to the open file—
the number passed to the Open statement. The following table summarizes how variables of
different types are written:
Any numer Written as text. There is no leading space, and the period is always used as the
ic type decimal separator.
User-de Written as #ERROR ErrorNumber # , where ErrorNumber is the value of the user-
fined errors defined error. The word ERROR is not translated.
The Write statement outputs variables separated with commas. After writing each expres
sion in the list, Write outputs an end-of-line. The Write statement can only be used with files
opened in Output or Append mode.
Exam This example opens a file for sequential write, then writes ten records into the file with the val
ple ues 10...50. Then the file is closed and reopened for read, and the records are read with the In
put statement. The results are displayed in a dialog box.
Sub Main()
For x = 1 To 10
r% = x * 10
Write #1,x,r%
Next x
Close
msg1 = ""
For x = 1 To 10
Input #1,a%,b%
msg1 = msg1 & "Record " & a% & ": " & b% & Basic.Eoln$
Next x
MsgBox msg1
Close
End Sub
See Open (on page 554) (statement); Put (on page 585) (statement); Print# (on page 578)
Also (statement).
WriteIni (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 708
Para Description
meter
sec String specifying the section that contains the desired variables, such as "windows."
tion$ Section names are specified without the enclosing brackets.
Item String specifying which item from within the given section you want to change. If Item
Name$ Name$ is a zero-length string (""), then the entire section specified by section$ is delet
ed.
val String specifying the new value for the given item. If value$ is a zero-length string (""),
ue$ then the item specified by ItemName$ is deleted from the ini file.
Exam This example sets the txt extension to be associated with Notepad.
ple Sub Main()
End Sub
See ReadIni$ (on page 599) (function); ReadIniSection (on page 600) (statement)
Also
Note If filename$ is not specified, the win.ini file is used. If the filename$ parameter does not include
a path, then this statement looks for ini files in the Windows directory.
X
X or (operator)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 709
Com If both expressions are either Boolean, Boolean variants, or NULL variants, then a logical exclu
ments sion is performed as follows:
If the first expression is and the second expression is then the result is
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, re
turning 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:
1 Xor 1 = 0 Example
0 Xor 1 = 1 5 01101001
1 Xor 0 = 1 6 10101010
Exam This example builds a logic table for the XOR function and displays it.
ple Const crlf = Chr$(13) + Chr$(10)
Sub Main()
For x = -1 To 0
For y = -1 To 0
z = x Xor y
Next y
Next x
MsgBox msg1
End Sub
See Al Operator Precedence (on page 560) (topic); Or (on page 567) (operator); Eqv (on page
so 402) (operator); Imp (on page 470) (operator); And (on page 230) (operator).
Y
Year (function)
De Returns the year of the date encoded in the specified date parameter. The value returned is be
scrip tween 100 and 9999 inclusive. The date parameter is any expression representing a valid date.
tion
tyear! = Year(DateValue(tdate$))
End Sub
See Day (on page 322) (function) Minute (on page 519) (function); Second (on page 617) (func
Also tion); Month (on page 522) (function); Hour (on page 461) (function); Weekday (on page
692) (function); DatePart (on page 319) (function).
CimEmAlarmEvent... (on
page 713)
CimEmPointEvent... (on
page 713)
CimLogin/CimLogout... (on
page 714)
CimRemoveUnusedPoints.
.. (on page 714)
IsTerminalServices... (on
page 715)
64-bit
Acquire...
Alarm...
Change...
CimChange...
CimEMAlarmEvent...
CimEMEvent...
CimEMPointEvent...
CimGetEMEvent...
CimIsMaster...
CimLogin/CimLogout...
CimProjectData...
CimRemoveUnusedPoints
Do...
Get...
IsTerminalServices
LogStatus
Point...
PointGet...
PointSet...
String...
Trace...
Acquire (function)
De Acquire a Critical Section with a timeout. If the section is not acquired within the specified time
scrip out, a value of False is returned.
tion
Critical Sections are used in multithreaded application to control reentrancy, protect access
global data structures, and provide synchronization. Only one thread of an application can be
within a critical section at a time. Since the Basic Control Engine is a multithreaded application,
you may need to use critical sections to prevent race type conditions.
Acquire and Release only work with the same process. In other words, two standalone executa
bles cannot protect against each other using this mechanism.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 718
In the Basic Control Engine, when an event occurs, the script is started in parallel with any oth
er currently executing scripts. If two scripts compete for the same resource in your factory (e.g.
controlling a pump) you may need to use critical sections to control access.
The Basic Control Engine automatically releases any critical sections held by the script when it
terminates. While the script is running, you can use the Acquire and Release commands to con
trol when a critical section is released. You must make a call to Release for each call you make
to Acquire for a critical section.
Com
ments
Parameter Description
Exam Prevent reentry into the routine if the script is already in progress. If the script can't acquire the
ple region immediately, it will exit.
Sub Main()
Exit Sub
end if
LastDate = Date$
PointSet "DATE",LastDate
end if
PointSet "TIME",Time$
Release "DATETIME"
End Sub
Note: In the Basic Control Engine, when an event occurs, the script is started in parallel. If another event
triggers the same script before the script ends, two scripts will be running in parallel. The Acquire and
Release routines can be used to modify this behavior. Two options are available.
1. Serialize the processing. In this case, the second instance of the script waits until the first is
complete and then begins execution. This is accomplished by placing an acquire statement at the
start of the script.
2. Skip processing. In this case, the second instance of the script exits without performing any
processing. The example in Acquire (FUNCTION) illustrated this.
AlarmGenerate (statement)
Parameter Description
Project$ String. The project to generate the alarm on. An empty string "" indicates the
current project.
AlarmId$ String. The ID of the Alarm. Must be a valid alarm of type $CIMBASIC.
ResourceId$ String. The Resource ID to generate the alarm against. Used to control rout
ing of the alarm.
Alarm Important: The following use of AlarmGenerate requires extra configuration for projects created
Mes before CIMPLICITY version 6.1.
sage
An alarm is triggered from a BCE script using AlarmGenerate. The alarm is a $CIMBASIC type.
Length
The alarm message contains 80 characters. Example:
Sub Main()
AlarmGenerate "TEST_AMV","TEST_AMV_ALARM_SCRIPT","$SYSTEM","123456789012345678
90123456789012345678901234567890123456789012345678901234567890"
End Sub
Problem
If BASIC generates an alarm that is greater than 72 characters to a project that does not have
the following solution: The project will log an error indicating there were too many fields. The
alarm will be displayed with 72 characters.
Solution
Allow 80 characters in a BASIC alarm message. Idtpop the alarm_field record. Edit the alarm_
field.idt file. Change the field_len to 80 in the $CIMBASIC record. For projects created in CIM
PLICITY version 6.1 and later 80 characters are supported automatically.
AlarmGenerate "BCEDEMO","MY_ALARM_2","RESOURCE_1",_
AlarmGenerate "BCEDEMO","MY_ALARM_2","RESOURCE_2",_
AlarmGenerate "BCEDEMO","MY_ALARM_2","RESOURCE_3",_
' Generate three of the same alarm for the same resource
AlarmGenerate "BCEDEMO","MY_ALARM_3","RESOURCE_1",_
AlarmGenerate "BCEDEMO","MY_ALARM_3","RESOURCE_1",_
AlarmGenerate "BCEDEMO","MY_ALARM_3","RESOURCE_1",_
End Sub
Notes The Alarm ID must have an Alarm Type of $CIMBASIC otherwise the alarm message may not be
displayed correctly.
A unique alarm in CIMPLICITY is defined by the Alarm ID, Resource ID and Reference ID combi
nation. Each unique alarm can be displayed as a distinct entry in the Alarm Viewer. Non-unique
alarms are stacked, so that the user only sees the most recent occurrence. In general, the Re
source ID is used to control the routing of alarms to users. The Reference ID is used by an appli
cation to distinguish between different instances of the same alarm.
Guidelines for AlarmGenerateEx (statement) (on page 721) also apply to AlarmGenerate.
AlarmGenerateEx (statement)
Parameter Description
Project$ String. The project to generate the alarm on. An empty string "" indicates
the current project
AlarmId$ String. The ID of a non-point or point Alarm that is listed in the right-pane of
the Workbench>Alarms section.
Note:
Non-point alarms must be a $CIMBASIC alarm type for all details, including
the alarm message (on page 724), to display correctly in an Alarm Viewer.
Point alarms are not $CIMBASIC alarms. As a result, there are limitations and
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 722
guidelines (on page 725) to be aware of if those alarm IDs are used in the
script.
ResourceId$ String. The Resource ID to generate the alarm against. Used to control rout
ing of the alarm.
Message$ (on page String. The generated alarm message to display. Note: This string is sub
724) stituted into the first variable field (on page 724) of the alarm's configured
message.
.NET C# System.Date
Time type
VB .NET System.Date
Time type
Note:
If you do not use UTC time, you will be responsible for making sure
your system’s Time Zone settings, including DST, are properly set.
ple
1
End Sub
ple
1
ple {
dt = dt.AddTicks(10100);
VB .NET
'This example displays the syntax.
End Sub
Note: Guidelines also apply to AlarmGenerate (on page 719) and AlarmUpdate (on page 726) .
Messages that display in the Alarm Viewer draw from the following sources and have the following
limitations.
The message, which is a string, is substituted into the first variable field of the alarm's configured
message.
Message: User-defined alarm The substituted string will be the first %s in the Alarm Definition dialog
box>Alarm Message field.
Message : Point alarm ID The substituted string will be the first variable field (%VAL, %ID) in an Alarm De
finition dialog box (or Point Properties dialog box)>Alarm Message field. However, if a point alarm ID is
used in an AlarmGenerateEx or AlarmUpdateEx (on page 729) script, because the alarm is not a $CIM
BASIC alarm, the message will most likely not display as you would expect. Examples The entry in the
Alarm Message field includes text and more than one variable POINT01 is %VAL : %STATE If the code:
Does not include a message • Text from the field will display; Vari
able values will not display.
• The first variable position will be
blank; BAD FIELD might display for
the other variables.
Does include a message "Point in alarm state." • Text will display; the message in the
code will display in the first variable
position.
• BAD FIELD might display for other
variables.
FIELD
The alarm definition (in an Alarm Definition dialog box) for a non-point alarm must include the following
values.
Alarm message %s
When an alarm is generated using a point alarm ID, the alarm that is generated is actually no longer a
point alarm.
However, like its point alarm counterpart, it also is not a $CIMBASIC alarm.
• The alarm message (on page 724) may not display correctly.
• A unique alarm in CIMPLICITY is defined by the Alarm ID, Resource ID and Reference ID
combination.
Each unique alarm can be displayed as a distinct entry in the Alarm Viewer.
If the actual point alarm is in alarm state and displays in the Alarm Viewer, using the same alarm ID in:
Note: If only the generated alarm is listed AlarmUpdateEx (on page 729) will acknowledge and/or reset
that alarm. Non-unique alarms are stacked, so that the user only sees the most recent occurrence. In
general, the Resource ID is used to control the routing of alarms to users. The Reference ID is used by an
application to distinguish between different instances of the same alarm.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 726
AlarmUpdate (statement)
De To update a currently generated alarm. The alarm being updated may be of any alarm type.
scrip However, if the AlarmMessage$ is specified, it must be an alarm with an alarm type of $CIM
tion BASIC.
Project String. The project to generate the alarm on, an empty string "" indicates the current
$ project
Re String. The Resource ID to generate the alarm against. Used to control routing of the
source alarm.
Id$
Ac Integer. Indicates whether to acknowledge or reset the alarm. Use the manifest con
tion% stants AM_ACKNOWLEDGED and AM_RESET to perform an acknowledgment and a reset. By
default, on a computer with Server Redundancy, alarm updates from the standby com
puter's Event Manager are ignored. To acknowledge or reset an alarm on the active
computer from the standby computer, use AM_ACKNOWLEDGED_M or AM_RESET_M
to override the default behavior.
Alarm String. (optional). The update alarm message to display. Note: This string is substitut
Mes ed into the first variable field of the Alarm's message. For a user-defined alarm mes
sage$ sage, this will be the first %s field in the message. For a point alarm message, it will be
the first variable field (%VAL, %ID, etc.) in the alarm message. For this reason, it is not rec
ommended that you use the AlarmMessage$ field when updating point alarms.
RefId$ String. A Reference ID used to distinguish between identical alarms. The Reference ID
needs to match the Reference ID of the generated alarm. If the alarm was generated
without a Reference ID, then this field can be omitted from the call.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 727
ple a$ = time$
AlarmUpdate "BCEDEMO","MY_ALARM_1","$SYSTEM",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_2","RESOURCE_1",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_2","RESOURCE_2",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_2","RESOURCE_3",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_3","RESOURCE_1",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_3","RESOURCE_1",x,_
AlarmUpdate "BCEDEMO","MY_ALARM_3","RESOURCE_1",x,_
End Sub
Note When updating an alarm, the AlarmId$, ResourceId$ and RefId$ must match exactly to the
alarm to be updated; if they do not match, the alarm will not be updated. When updating a point
alarm, the RefId$ is always the Point ID (which is also the Alarm ID).
Guidelines that apply to AlarmUpdateEx (on page 732) also apply to AlarmUpdate.
AlarmUpdateCA (statement)
tax [,RefId$]]]
De To update a currently generated Change approval alarm. The alarm being updated may be of
scrip any alarm type. However, if the AlarmMessage$ is specified, it must be an alarm with an alarm
tion type of $CIMBASIC.
Project String. The project to generate the alarm on, an empty string "" indicates the current
$ project
Re String. The Resource ID to generate the alarm against. Used to control routing of the
source alarm.
Id$
Ac Integer. Indicates whether to acknowledge or reset the alarm. Use the manifest con
tion% stants AM_ACKNOWLEDGED and AM_RESET to perform an acknowledgment and a reset. By
default, on a computer with Server Redundancy, alarm updates from the standby com
puter's Event Manager are ignored. To acknowledge or reset an alarm on the active
computer from the standby computer, use AM_ACKNOWLEDGED_M or AM_RESET_M to override
the default behavior.
Alarm String. (optional). The update alarm message to display. Note: This string is substitut
Mes ed into the first variable field of the Alarm's message. For a user-defined alarm mes
sage$ sage, this will be the first %s field in the message. For a point alarm message, it will be
the first variable field (%VAL, %ID, etc.) in the alarm message. For this reason, it is not rec
ommended that you use the AlarmMessage$ field when updating point alarms.
RefId$ String. A Reference ID used to distinguish between identical alarms. The Reference ID
needs to match the Reference ID of the generated alarm. If the alarm was generated
without a Reference ID, then this field can be omitted from the call.
obj.PerformerUserid = "OPERATOR"
obj.PerformerPassword = ""
obj.VerifierUserid = "MANAGER"
obj.VerifierPassword = ""
AlarmUpdateCA"ESIGDEMO","CA_TESTPOINT","$MAC_FR",AM_ACKNOWLEDGED,CAobj,
"CA_TESTPOINT","CA_TESTPOINT","CA_TESTPOINT"
End Sub
Note When updating an alarm, the AlarmId$, ResourceId$ and RefId$ must match exactly to the
alarm to be updated; if they do not match the alarm will not be updated. When updating a point
alarm, the RefId$ is always the Point ID (which is also the Alarm ID).
AlarmUpdateEx (statement)
Parameter Description
Project$ String. The project to update the alarm on. An empty string "" indicates the
current project.
AlarmId$ String. The ID of a non-point or point Alarm that is listed in the right-pane
of the Workbench>Alarms section.
Note:
Non-point alarms must be a $CIMBASIC alarm type for all details, including
the alarm message (on page 732), to display correctly in an Alarm View
er. Point alarms are not $CIMBASIC alarms. As a result, there are limitations
and guidelines (on page 733) to be aware of if those alarm IDs are used
in the script.
ResourceId$ String. The Resource ID to update the alarm against. Used to control rout
ing of the alarm.
Action Integer. Indicates whether to acknowledge or reset the alarm. Use the fol
lowing constants to perform an acknowledgment and a reset.
• AM_ACKNOWLEDGED
• AM_RESET
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 730
• AM_ACKNOWLEDGED_M
• AM_RESET_M
.NET C# Sys
tem.Date
Time type
VB .NET Sys
tem.Date
Time type
Note:
If you do not use UTC time, you will be responsible for making sure
your system’s Time Zone settings, including DST, are properly set.
Message$ (on page String. The update alarm message to display. Note: This string is substi
732) tuted into the first variable field (on page 732) of the Alarm's message.
ple
ple Test")}
VB .NET
'This example displays the syntax.
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 732
Note: Guidelines also apply to AlarmGenerate (on page 719) and AlarmUpdate (on page 726) .
Messages that display in the Alarm Viewer draw from the following sources and have the following
limitations.
The message, which is a string, is substituted into the first variable field of the alarm's configured
message.
Message: User-defined alarm The substituted string will be the first %s in the Alarm Definition dialog
box>Alarm Message field.
Message : Point alarm ID The substituted string will be the first variable field (%VAL, %ID) in an Alarm De
finition dialog box (or Point Properties dialog box)>Alarm Message field. However, if a point alarm ID is
used in an AlarmGenerateEx (on page 721) or AlarmUpdateEx script, because the alarm is not a $CIM
BASIC alarm, the message will most likely not display as you would expect. Examples The entry in the
Alarm Message field includes text and more than one variable POINT01 is %VAL : %STATE If the code:
Does not include a message • Text from the field will display; Vari
able values will not display.
• The first variable position will be
blank; BAD FIELD might display for
the other variables.
Does include a message "Point in alarm state." • Text will display; the message in the
code will display in the first variable
position.
• BAD FIELD might display for other
variables.
FIELD
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 733
The alarm definition (in an Alarm Definition dialog box) for a non-point alarm must include the following
values.
Alarm message %s
When an alarm is generated using a point alarm ID, the alarm that is generated is actually no longer a
point alarm.
However, like its point alarm counterpart, it also is not a $CIMBASIC alarm.
• The alarm message (on page 732) may not display correctly.
• A unique alarm in CIMPLICITY is defined by the Alarm ID, Resource ID and Reference ID
combination.
Each unique alarm can be displayed as a distinct entry in the Alarm Viewer.
If the actual point alarm is in alarm state and displays in the Alarm Viewer, using the same alarm ID in:
• AlarmGenerateEx (on page 721) will generate a separate alarm from the point alarm.
• AlarmUpdateEx will acknowledge and/or reset the actual alarm depending on the command(s).
Note: If only the generated alarm is listed AlarmUpdateEx will acknowledge and/or reset that alarm.
• Non-unique alarms are stacked, so that the user only sees the most recent occurrence. In general,
the Resource ID is used to control the routing of alarms to users.
• The Reference ID is used by an application to distinguish between different instances of the same
alarm.
ChangePassword (statement)
Project$ String. The project to change the password on. An empty string indicates the
current default project.
End Sub
Note The user must be logged into the specified project or the function will fail.
CimChangeApprovalData (Object)
Overview The CimChangeApprovalData object contains information about Change Approval information
(e.g.Performer and Verifier User ID, Password and Comments for Point Operations).
obj.PerformerUserid = "OPERATOR"
obj.PerformerPassword = ""
obj.VerifierUserid = "MANAGER"
obj.VerifierPassword = ""
Syntax AlarmEvent.AlarmId
Description String. Returns the Alarm ID of the Alarm that triggered the
event.
End if
End Sub
Syn AlarmEvent.FinalState
tax
De Integer. Returns the final state of the alarm after the requested action. For example, if the user ac
scrip knowledged the alarm and the deletion requirements for the alarm only require acknowledgement
tion then the final state would be AM_DELETED.
• AM_GENERATED
• AM_ACKNOWLEDGED
• AM_RESET
• AM_DELETED
End if
End Sub
Syntax AlarmEvent.GenTime
Description Date. Returns the day and time the alarm was generat
ed.
End if
End Sub
Syntax AlarmEvent.Message
Description String. Returns the text of the Alarm Message of the alarm that triggered the
event.
End if
End Sub
CimEMAlarmEvent (object)
Overview The CimEMAlarmEvent object provides information for scripts invoked from an alarm event.
Note CimEMAlarmEvent can only be used from the Event Manager. It is not valid in CimView/Cim
Edit.
Syntax AlarmEvent.PrevState
Description Integer. Returns the previous state of the alarm. Valid States
are :
• AM_GENERATED
• AM_ACKNOWLEDGED
• AM_RESET
• AM_DELETED
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 737
End if
End Sub
Syntax AlarmEvent.RefID
Description String. Returns the Reference ID of the alarm that triggered the
event.
End if
End Sub
Syn AlarmEvent.ReqAction
tax
De Integer. Returns the action requested on the alarm. For example, if the user had acknowledged
scrip the alarm in the Alarm Viewer the requested action would be AM_ACKNOWLEDGED.
tion
End if
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 738
Syntax AlarmEvent.ResourceID
Description String. Returns the Resource ID of the alarm that triggered the
event.
End if
End Sub
Syntax Event.ActionID
End Sub
CimEMEvent.AlarmEvent (function)
Syntax Event.AlarmEvent
De Returns CimEMAlarmEvent. Returns the Alarm Event object that triggered the action, or empty
scrip if action was not triggered by an alarm.
tion
End If
End Sub
Syntax Event.EventID
End Sub
CimEMEvent (object)
Overview An object used by the Event Manager to hold information about the event that triggered the
action.
End Sub
Note CimEMEvent can only sbe used from the Event Manager. It is not valid in CimView/CimEdit.
Syn Event.ObjectID
tax
De String. If the script is invoked from an object event, the Object ID invoking the action is returned.
scrip If the script is invoked from a non-object event, an empty string is returned
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 740
End Sub
CimEMEvent.PointEvent
Syntax Event.PointEvent
De Returns CimEMPointEvent. Returns the Point Event object that triggered the action, or empty if
scrip action was not triggered by point event.
tion
End Sub
Syntax Event.TimeStamp
Description Date. Returns the Time Stamp at which the event oc
curred.
End Sub
Syntax Event.Type
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 741
Description Integer. Returns the type of event that triggered the action. Valid values
are:
End If
End Sub
CimEMPointEvent.Id
Syntax PointEvent.Id
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 742
Descrip String. Returns the Point ID of the point that triggered the event.
tion
PointSet PointEvent.Id, 0
End Sub
Note CimEMPointEvent can only be used from the Event Manager. It is not valid in CimView/
CimEdit
CimEMPointEvent (object)
Overview An Event Manager Object used to contain information about a Point Event
PointSet PointEvent.Id, 0
End Sub
Syntax CimEMPointEvent.Quality
Description Long. Returns the 16-bit quality mask for the point that triggered the
event.
Set p = CimGetEmEvent().PointEvent()
X = p.Quality
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 743
Syntax CimEMPointEvent.QualityAlarmed
Description Boolean. Returns TRUE if the point that triggered the event is in alarm, FALSE other
wise.
Set p = CimGetEmEvent().PointEvent()
if p.QualityAlarmed then
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityAlarms_Enabled
Descrip Boolean. Returns TRUE if alarming for the point that triggered the event is enabled, FALSE
tion otherwise.
Set p = CimGetEmEvent().PointEvent()
if p.QualityAlarms_Enabled then
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityDisable_Write
Descrip Boolean. Returns TRUE if setpoints have been disabled for the point that triggered the event,
tion FALSE otherwise.
Set p = CimGetEmEvent().PointEvent()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 744
if p.QualityDisable_Write Then
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityLast_Upd_Man
Descrip Boolean. Returns TRUE if the value of the point that triggered the event came from a manual
tion update rather than a device read.
Set p = CimGetEmEvent().PointEvent()
If p.QualityLast_Upd_Man then
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityManual_Mode
Descrip Boolean. Returns TRUE if the point that triggers the event was in Manual Mode, otherwise
tion FALSE.
Set p = CimGetEmEvent().PointEvent()
if p.QualityManual_Mode then
ProcessManualMode
End if
End Sub
Syn CimEMPointEvent.QualityIs_In_Range
tax
De Boolean. Returns TRUE if the value of the point that triggered the event is in range, FALSE if the
scrip point is out of range. When a point is out of range its value is unavailable.
tion
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityStale_Data
Descrip Boolean. Returns TRUE if the value of the point that triggered the event is stale, otherwise
tion FALSE.
Set p = CimGetEmEvent().PointEvent()
if p.QualityStale_Data = TRUE
DoSomething
End If
End Sub
Syntax CimEMPointEvent.QualityIs_Available
Descrip Boolean. Returns TRUE if the value of the point that triggered the event is available, FALSE if
tion the value is unavailable.
Set p = CimGetEmEvent().PointEvent()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 746
DoSomething
End If
End Sub
Syntax PointEvent.State
De Integer. Returns the state of the point. Can be used to determine if the point is available. See
scrip Point.State for a complete description of states.
tion
LogStatus CIM_FAILURE,"Main()", _
end
End if
End Sub
Syntax PointEvent.TimeStamp
Description Date. Returns the date and time of the point change that triggered the
event.)
End Sub
Syntax CimEMPointEvent.UserFlags
Descrip Long. Returns the value of the 16-bit user defined flags for the point that triggered the
tion event.
Set p = CimGetEmEvent().PointEvent()
X = p.UserFlags
End Sub
Syntax PointEvent.Value
Description Variant. Returns the value of the point that triggered the
event.
End Sub
CimGetEMEvent (function)
Syntax CimGetEMEvent()
De Returns a CimEMEvent object. A function to return the event object that causes the action to
scrip run. Only valid from Event Manager.
tion
End Sub
Note CimGetEMEvent can only be used from the Event Manager. It is not valid in CimView/CimEdit.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 748
CimIsMaster (function)
Syn CimIsMaster
tax
De In a computer with Server Redundancy, to determine if the computer is operating in Active or
scrip Standby mode. This function returns TRUE if the computer is currently the active computer. This
tion function returns FALSE if the computer is currently the standby.
ple MoveCrane
End if
End Sub
CimLogin (statement)
De Initiates a login for the specified project. Similar in effect to selecting login from the Login Pan
scrip el. Only valid when the user is actively using points or viewing alarms from the project, other
tion wise it has no effect. Initiating a login will cause the CIMPLICITY login box to be displayed.
End Sub
CimLogout (statement)
De Logs the user out of the specified project. Similar in effect to selecting logout from the Login
scrip Panel. When the user is logged out of the project, all points from the project will be unavailable
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 749
and no alarm information will be available. If the user is not logged into the project, the call has
no effect.
End Sub
Syntax CimProjectData.Attributes
De String. The list of attributes, separated by commas, of the entity to return for each item match
scrip ing the filter criteria. The Attribute IDs are case sensitive and must be entered in the case docu
tion mented in CimProjectData.Entity .
ample
ple
Syn CimProjectData.Filters
tax
De String. The filter set to be used to determine which items to return. Each filter contains an At
scrip tribute ID and Value pair. You can use "*" and "?"as wildcard characters. The filters are document
tion ed in CimProjectData.Entity . Filters must be in uppercase even when matching against lower
case data.
ple
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 750
CimProjectData.GetNext (function)
De This function returns the specified attributes for the next item that matches the filter criteria. If
scrip a record is found, a value of TRUE is returned, otherwise a value of FALSE is returned. The func
tion tion takes a variable number (20 maximum) of string parameters. The values returned into the
parameters are defined by the attributes specified for the object.
: :
Exam The following sample script returns all the data items for the PID1 object.
ple 1 Sub Main()
Browse.Project = "MY_PROJ"
Browse.Entity = "OBJECT_INF"
Browse.Attributes = DATA_ITEM"
Browse.Filters = "OBJECT_ID=PID1"
Top:
Msgbox dataitem
Goto top
End Sub
Exam The following sample script returns all points for a device:
ple 2 Sub Main()
Browse.Project = "MY_PROJ"
Browse.Entity = "POINT"
Browse.Attributes = "POINT_ID,RESOURCE_ID"
Browse.Filters = "DEVICE_ID=PLC1"
Top:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 751
Goto top
End Sub
Syntax CimProjectData.Entity
Descrip String. The entity to obtain data for. Below is a list of the available entities and their attribut
tion es
Entity List
GLB_PARMS
ACTION
ALARM_BLK_GROUP
PEER_ Yes Blocking Mode: If you select Peer Blocking mode, only the first alarm of a set of
BLOCK alarms with equal priority displays for that group.
ALARM_CLASS
CLASS_ALARM_FG No The foreground color to use for points of this class that are in alarm
state.
CLASS_ALARM_BG No The background color to use for points of this class that are in alarm
state.
CLASS_NORMAL_FG No The foreground color to use for points of this class that are in normal
state.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 753
CLASS_NORMAL_BG No The background color to use for points of this class that are in normal
state.
CLASS_ACK_FG No The foreground color to use for points of this class that are in ac
knowledged state.
CLASS_ACK_BG No The background color to use for points of this class that are in ac
knowledged state.
CLASS_WAVE_FILE No The WAV file to play from the Alarm Sound Manager.
ALARM_DEF
Sample Script
objCimProjectData.Project = strOptionalProject
objCimProjectData.Entity = "ALARM_DEF"
objCimProjectData.Filters = "CLASS_ID=HIGH"
MsgBox AlID
MsgBox AlarmMessage
Wend
AMLP
CLASS
CLIENT
DEVICE
EVENT
SERVICE_ID No
EVENT_ACTION
EA_SERVICE_ Yes
ID
GLB_PARMS
MEASUNIT
MEASSYSTEM
OBJECT
OBJECT_INF
This is a specialized entity used to extract information from a specified object. The filter for this entity is
OBJECT_ID=MY_OBJECT, where MY_OBJECT is replaced with the object name you wish to read. Since the
function returns specialized attribute information, only one of the attributes may be used at a time.
This entity may not be used from the Event Manager or without a specified running project.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 758
DATA_ No Returns all data items for the object. Each data item returns by a GetNext call.
ITEM
AT No Returns the attribute for the object. If VALUE is specified, it must be the second at
TRIBUTE, tribute, and the value of the attribute will be returned
VALUE
DEFAULT_ No Returns the name of the default graphic for the object's class. Must be specified with
GRAPHIC GRAPHICS_FILE Example obj.Attributes= "GRAPHICS_FILE,DEFAULT_GRAPHIC"
POINT
DEVICE_ID Yes Device ID for the point, where the point data originates. If the point is a global point,
the device is "$GLOBAL". If the point is an equation point, the device is $DERIVED.
DISPLAY_ No Low and high display limits of the point separated by a hyphen.
LIMITS
MODIFIED No Data and time in string format that the point was last edited.
POINT_ALSTR
POINT_DISP
DISPLAY_LIM_ No The low limit for the point value display. Values below this limit will display as
LOW asterisks (***).
DISPLAY_LIM_ No The high limit for the point value display. Values above this limit will display as
HIGH asterisks (***).
POINT_ENUM
POINT_ENUM_FLD
SETPOINT_AL Yes Indicates if the point data field represented by this enumeration field can be
LOWED set.
POINT_TYPE
DATA_TYPE No The numeric data type code for the point type.
PORT
PROJECTS
PROTOCOL
RESOURCE
ALARM_MGR_ID No The Alarm Manager process that receives alarms for this re
source.
ROLE
SSPC
SYS_PARMS
UAFSETS
USER
USER_FIELDS
UPD_DEVCOMM No Write to DevComm - Data will be sent to the associated devcom when this at
tribute is set.
SAVE_WARM No Preserve value - Indicates that this field should be saved on project shutdown.
DATA
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 765
CimProjectData (object)
Overview The CimProjectData object provides the ability to search and return specific pieces of a
project's configuration. The underlying APIs used by the CimProjectData object are the same
as those used to browse point configuration on a remote project. In general, this object pro
vides a convenient way to retrieve a set of attributes based on specified filter criteria. This
object provides a read-only capability. To write configuration, please see the help file for the
CIMPLICITY Configuration Object Model.
(CimBa ' This example retrieves all points beginning with A for Device MY_PLC
sic) ' in project MY_PROJECT and displays the point id and resource id of
d.Project = "MY_PROJECT"
d.Entity = "POINT"
d.Filters = "POINT_ID=A*,DEVICE_ID=MY_PLC"
d.Attributes = "POINT_ID,RESOURCE_ID"
Dim p as string
Dim r as String
top:
goto top
End if
End Sub
using Proficy.CIMPLICITY;
try
cpd.Project = "MY_PROJECT";
cpd.Entity = "POINT";
cpd.Attributes = "POINT_ID,RESOURCE_ID";
cpd.Filters = "POINT_ID=PGM*";
int count = 0;
count++;
catch (Exception x)
Syn CimProjectData.Project
tax
De String. Get/set the project to browse data from. Must be specified when used from CimView. For
scrip use in the Event Manager, the project name should be empty to browse the local project.
tion
ple
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 767
CimProjectData.Reset (method)
Syntax CimProjectData.Reset
Description Resets the list so that a new set of search criteria, attributes, or project may be speci
fied.
Example d.reset
CimRemoveUnusedPoints (method)
Syn CimRemoveUnusedPoints
tax
De Removes unused points that have been created as a result of Variable assignments.
scrip
tion
Com The use of variables in expressions allows a user to assign points to animations at runtime. As
ments the program makes various variable assigns and adds new points to CimView, it leaves other
points in a state that no objects are using them. CimRemoveUnusedPoints can be used to remove
these unused points from the screen, which reduces the number of updates, CimView receives
from PTMAP, thus improving performance.
ple CimRemoveUnusedPoints
End Sub
DoQINTMath (function)
0 +
1 -
2 *
3 /
4 %
qtargethigh,qtargetlow,1,qhighSrc1,qlowSrc1,qhighSrc2,qlowSrc2 - Subtraction
End Sub
See al DoUQINTMath (on page 768) (function). Point.QuadValueAsString (on page 799) (proper
so ty, read), Point.QuadValueAsString (on page 800) (property, write), Point.SetQuadIntValue (on
page 810) (function).
DoUQINTMath (function)
0 +
1 -
2 *
3 /
4 %
qtargethigh,qtargetlow,1,qhighSrc1,qlowSrc1,qhighSrc2,qlowSrc2 - Subtraction
End Sub
GetCurTimeHR (function)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 770
Syntax GetCurTimeHR
timestr = GetCurTimeHR
End Sub
GetKey (function)
De To search for a keyword and returns its value. This is of use particularly from the Basic Control
scrip Engine to extract the EVENT and ACTION, which caused the script to run. An empty string is re
tion turned if the key is not found.
string String. The string to search for the keyword. The format of this string is keyword fol
$ lowed by an equal sign and the value. A comma separates multiple keyword value com
binations.
name$ = GetKey("NAME","NAME=PETE,LOCATION=ALBANY")
End Sub
GetMemoryInfoSymbolSpace (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 771
De This statement obtains information on the memory usage for storing the names of the symbols
scrip for public variables used in scripts at the module level.
tion
Parameter Description
Type ExampleRect
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
Public dd As ExampleRect
testPublicLong = 1200
pv_testString = 1200
End Sub
GetMemoryInfoStringSpaceHandles (statement)
De This statement obtains information on the handle usage for string space.
scrip
tion
Parameter Description
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 773
Dim charCount
Dim i
mymsg = ""
mymsg = mymsg & Chr$(13) & "SPACE used:" & used & ", free:" & free & ", total:" & total
mymsg = mymsg & Chr$(13) & "HANDLES used:" & used & ", free:" & free & ", total:" & total
charCount = 0
Next i
mymsg = mymsg & Chr$(13) & "---- AFTER populating, elements:" & (UBound(myarray) - LBound(myarray)) _
mymsg = mymsg & Chr$(13) & "SPACE used:" & used & ", free:" & free & ", total:" & total
mymsg = mymsg & Chr$(13) & "HANDLES used:" & used & ", free:" & free & ", total:" & total
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 774
GetMemoryInfoStringSpace (statement)
De This statement obtains information on the memory usage for string space.
scrip
tion
Parameter Description
Dim charCount
Dim i
mymsg = ""
mymsg = mymsg & Chr$(13) & "SPACE used:" & used & ", free:" & free & ", total:" & total
mymsg = mymsg & Chr$(13) & "HANDLES used:" & used & ", free:" & free & ", total:" & total
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 775
charCount = 0
Next i
mymsg = mymsg & Chr$(13) & "---- AFTER populating, elements:" & (UBound(myarray) - LBound(myarray)) _
mymsg = mymsg & Chr$(13) & "SPACE used:" & used & ", free:" & free & ", total:" & total
mymsg = mymsg & Chr$(13) & "HANDLES used:" & used & ", free:" & free & ", total:" & total
End Sub
Note The sum of the used and free parameter values will not be equal to the value of the total parame
ter. This is because of the overhead that is used to manage the allocated blocks.
GetMemoryInfoPublicSpace (statement)
De This statement obtains information on the memory usage for storing the values for public vari
scrip ables used in scripts at the module level.
tion
Parameter Description
Type ExampleRect
left As Integer
top As Integer
right As Integer
bottom As Integer
End Type
Public dd As ExampleRect
testPublicLong = 1200
pv_testString = 1200
End Sub
GetSystemWindowsDirectory (function)
Syntax d$ = GetSystemWindowsDirectory
Descrip Returns the true Windows directory and not the per user Windows directory when running un
tion der Terminal Services.
Direct$ = GetSystemWindowsDirectory
End Sub
GetTimeComponentsHR (function)
Descrip Components of the time. Current time divided into time components of year, month, day, hour,
tion min, sec and nanoseconds.
ple
Dim yy As Integer
Dim mm As Integer
Dim dd As Integer
Dim hh As Integer
localpoint.id = "\\$LOCAL\$LOCAL.DATETIME_VARUPDATE"
result = localpoint.GetQuadIntValue(qhigh,qlow)
GetTimeComponentsHR qhigh,qlow,yy,mm,dd,hh,min,sec,nano
End Sub
See also GetCurTimeHR (on page 769) (function), SetTimecomponentsHR (on page 831) (function)
GetTSSessionId (function)
Descrip The Session ID of the Terminal Services client. This is 0 if running on the console or if Termi
tion nal Services is not running.
myid& = GetTSSessionId
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 779
End Sub
IsTerminalServices (function)
Syntax IsTerminalServices
End Sub
De To provide the programmer with the ability to log errors to the CIMPLICITY Status Log. To view
scrip the errors, use the CIMPLICITY Status Log Viewer.
tion
Proce String. The name of the Basic Procedure which logged the error.
dure$
error_ref Long. (optional). A user-defined error reference. Used to distinguish the difference
erence between two errors with the same error_code.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 780
....
..
Exit Sub
error_handler :
' error$, err, and erl are BASIC variables which contain the
Exit Sub
End Sub
Syn Point.AlarmAck
tax
De Boolean. When used in combination with the Point.OnAlarmAck method, a Boolean is returned
scrip indicating if the point's alarm is in an Acknowledged state.
tion
x.ID = "Some_point"
x.OnAlarmAck
top:
x.GetNext
End Sub
Point.Cancel (method)
Syntax Point.Cancel
Descrip To cancel the currently active OnChange , OnAlarm , OnTimed or OnAlarmAck request.
tion
t.Id = "TIME"
t.OnChange
for i = 1 to 2
t.GetNext
next I
t.Cancel
t.OnTimed 3
for i = 1 to 2
t.GetNext
next I
End Sub
See Also Point.OnChange (on page 797) (method), Point.OnTimed (on page 798) (method),
Point.OnAlarm (on page 795) (method), Point.OnAlarmAck (on page 797) (method)
Syn Point.ChangeApproval = a
tax
De To set the Change Approval information for a point. Important: Change Approval must be set to
scrip an object of type CimChangeApprovalData in order to perform set point operations on a point
tion that requires change approval..
'Init Point
Case CP_CHANGEAPPROVALPERFORM
Case CP_CHANGEAPPROVALPERFORMVERIFY
Case CP_CHANGEAPPROVALNONE
End Select
MyPoint.SetValue = InputBox("Setpoint")
End Sub
See CimChangeApprovalData (on page 734) (Object), AlarmUpdateCA (on page 727) (Method),
also PointChangeApprovalInfo (on page 782) (property, read).
Syntax Point.ChangeApprovalInfo
Descrip Integer. To determine the level of change approval that is required to perform an operation.
tion
'Init Point
Case CP_CHANGEAPPROVALPERFORM
Case CP_CHANGEAPPROVALPERFORMVERIFY
Case CP_CHANGEAPPROVALNONE
End Select
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 783
See also AlarmUpdateCA (on page 727) (Method), CimChangeApprovalData (on page 734) (Ob
ject), Point.ChangeApproval (on page 781) (property, write)
Syntax Point.DataType
a$ = MyPoint.Value
else
a% = MyPoint.Value
end if
Syntax Point.DisplayFormat
Description String. To return a string containing the configured display format for the
point.
Syntax Point.DownLoadPassword
Example ' Prompt the user for the download password if required to set
Sub Main()
p.Id = "CP_UINT"
p.Value = 10
if p.DownLoadPassword then
p.Set pass$
else
p.Set
end if
End Sub
See also Point.SetPointPriv (on page 809) (property, read); Point.InUserView (on
page 793) (property, read).
Syntax Point.Elements
De Integer. To return the number of elements configured for the point. For array points this will be
scrip greater than 1, for non-array points the value will be 1.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 785
MyPoint.Id = "ARRAY_POINT"
for x = 0 to MyPoint.Elements - 1
MyPoint.Value(x) = x
next x
MyPoint.Set
End sub
Point.EnableAlarm (method)
Descrip To enable or disable alarming on the point. Can be used to temporarily disable alarming on a
tion point.
Enable Boolean. A value of TRUE enables alarming for the point and value of FALSE dis
ables alarming for the point.
myPoint.Id = "ALARM_POINT"
myPoint.EnableAlarm FALSE
End Sub
Syntax Point.Enabled
Description Boolean. To determine if the point is enabled to be collected from the PLC.
Exit Sub
end if
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 786
Syntax Point.EuLabel
Example a$ = MyPoint.EuLabel
or
...
end if
Point.Get (statement)
Syn Point.Get
tax
De To get the current value of the point from the CIMPLICITY Point Manager and store it in the ob
scrip ject. You may inspect the value through the Value and RawValue properties.
tion
MyPoint.Get
End Sub
See Point.Value (on page 819) (method), Point.OnChange (on page 797) (method), Point.On
also Timed (on page 798) (method).
Point.GetArray (statement)
De To retrieve an array point's values directly into a Basic array using Engineering Units Conversion
scrip if applicable. There are several rules to keep in mind:
tion
• If the array is undimensioned, the array will be re-dimensioned to the same size as the
point.
• If the array is dimensioned smaller than the point, only that many elements will be copied
into the array.
• If the array is larger than the point, all elements of the point are copied, and the rest of the
array is left as is.
If the startElement is specified, the function will start copying data into the array at this element
and will continue until the end of the point is reached or the array is full whichever occurs first.
If the endElement is specified, the function will stop copying data into the array after populating
this element or when the end of the point is reached. If the fromElement is specified, the values
copied into the array start at this element in the point array and continue as described above.
Note: You must get the point value using the Get or GetNext method prior to using the GetAr
ray method. The GetArray method does not retrieve the current value from the Point Manag
er. Instead, it retrieves the current value in the Point Object, which was generated during the last
Get or GetNext . See the example below.
array Array. A dimensioned or un-dimensioned Basic Array to which the point data will
be copied.
startEle Integer. (optional) The first array element to which data will be copied.
ment
endEle Integer. (optional) The last array element to which data will be copied.
ment
fromEle Integer. (optional) The first point element from which data is to be copied.
ment
End Sub
See Point.SetArray (on page 807) (method); Point.GetRawArray (on page 790) (method);
Also Point.HasEuConv (on page 792) (property, read); Point.Value (on page 819) (property, read/
write); Point.RawValue (on page 804) (property, read/write).
Point.GetNext (function)
De Boolean. A function, to read the next value of a point with a specified timeout in milliseconds.
scrip Returns True if the point was read, False if it timed out.
tion
Else
end if
End Sub
See al Point.OnChange (on page 797) (method); Point.OnTimed (on page 798) (method); Point.On
so Alarm (on page 795) (method); Point.OnAlarmAck (on page 797) (method); Point.Cancel (on
page 780) (method).
Point.GetNext (statement)
Syn Point.GetNext
tax
De To wait for and get the next value of the point. This method returns when a point update is re
scrip ceived for the point, based on a previously submitted OnChange, OnAlarm, OnTimed or OnAlar
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 789
mAck call. If the point never changes, the call never returns. To wait with a timeout, see the Get
Next(function.)
Ex ' Calculate the average of the next two point values.
End Sub
See Point.OnChange (on page 797) (method); Point.OnAlarm (on page 795) (method); Point.On
Also Timed (on page 798) (method); Point.OnAlarmAck (on page 797) (method)..
Point.GetQuadIntValue (function)
Descrip Will return the value of a 64-bit QINT or QUINT point in the form of two 32-bit double inte
tion gers.
'Declare variables
'Initialize
localpoint.id = "\\$LOCAL\$LOCAL.DATETIME_VARUPDATE"
'Gets the value of a QuadInt and places it in our two 32 bit Basic doubles
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 790
result = localpoint.GetQuadIntValue(qhigh,qlow)
MsgBox qhigh
Msgbox qlow
Else
MsgBox "Error!"
End If
End Sub
Point.GetRawArray (statement)
De To retrieve an array points value directly into a Basic array bypassing Engineering Units Conver
scrip sion.
tion
If the startElement is specified, the function will start copying data into the array at this element
and will continue until the end of the point is reached or the array is full whichever occurs first.
If the endElement is specified, the function will stop copying data into the array after populating
this element or when the end of the point is reached. If the fromElement is specified, the values
copied into the array start at this element in the point array and continue as described above.
Parameter Description
array Array. A dimensioned or un-dimensioned Basic Array to which the point data will
be copied.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 791
startEle Integer. (optional) The first array element to which data will be copied.
ment
endEle Integer. (optional) The last array element to which data will be copied.
ment
fromEle Integer. (optional) The first point element from which data is to be copied.
ment
End Sub
See Point.GetArray (on page 786) (method); Point.SetRawArray (on page 810) (method);
Also Point.HasEuConv (on page 792) (property/read); Point.Value (on page 819) (property, read/
write); Point.RawValue (on page 804) (property, read/write).
Point.GetTimeStampHR (statement)
tax
De Date. To retrieve the Microsecond timestamp into 2 double 32-bit values. The timestamp indi
scrip cates the time at which the point's value was read from the PLC.
tion
x.Id = a$
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 792
x.GetTimeStampHR(qhigh,qlow)
End Sub
See Point.QuadValueAsString (on page 799) (property, read), Point.QuadValueAsString (on page
also 800) (property, write,) Point.SetQuadIntValue (on page 810) (function), Point.TimeStampHR
(on page 791) (property, read), GetTimeComponentsHR (on page 777) (function), GetCurTime
HR (on page 769) (function).
Syn Point.GetValue
tax
De To get a snapshot of the point value from the Point Manager and return it. This operation com
scrip bines the Get Method and Value Property into a single command.
tion
If the point is unavailable (due to the device being down, remote server unavailable, etc.) an er
ror will be generated if you attempt to access the value (since the value is unavailable.) See the
Point.State property if you need to determine if the point is available or not.
am Dim MyPoint as new Point ' Declare the point object
End Sub
Syn Point.HasEuConv
tax
De Boolean. To determine if the point has Engineering Units conversion configured.
scrip
tion
if MyPoint.HasEuConv then
else
end if
End Sub
See Point.SetRawArray (on page 810) (method); Point.SetArray (on page 807) (method);
also Point.GetArray (on page 786) (method); Point.GetRawArray (on page 790) (method);
Point.Value (on page 819) (property, read/write); Point.RawValue (on page 804) (property,
read/write).
Syntax Point.Id
De String. To get or set the object's CIMPLICITY Point ID. The function generates an error if the
scrip point is not configured or the remote server is not available.
tion
Com If an error is generated, one of the following error codes may be reported.
ments
Err Description
End Sub
...
end if
End Sub
Syn Point.InUserView
tax
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 794
if MyPoint.InUserView = TRUE
MyPoint.SetValue = 10
else
end if
End Sub
See Point.SetPointPriv (on page 809) (property, read); Point.DownLoadPassword (on page 784)
also (property, read).
Syntax Point.Length
Descrip Integer. To return the length in Bytes of the point value. This is valid only for character
tion strings.
Point (object)
Overview The Point object provides an object-oriented interface to CIMPLICITY real-time point data.
Through the object, you may set and read point values. Methods are supplied to receive the
point value as it changes, periodically, or when the alarm state changes.
Example 1 Dim MyPoint as new Point ' Creates a new empty point object
Set ThisPoint = MyPoint ' Now the two object are equal (BCE)
Notes In the above example, a point object is created two different ways.
1 Uses a new keyword; this is typically the method you will use. This constructs a point
object, at which time you can set the ID of the point and use it.
A runtime error will occur if you attempt to access methods of the object, since it is current
ly unassigned. You can assign the reference to a particular object by using the SET command.
In general, you will use this with the PointGetNext function, which takes a list of point objects
and returns the first one that changes.
Important:
Point objects in .NET scripting must be explicitly disposed of by doing either of the
following:
Failing to do so will freeze the IDE (on page 173) when the script is finished running.
Point.OnAlarm (statement)
Description To request the point's value when its alarm state changes. If no para
meters are specified, the value will be returned whenever the alarm
state changes. The four optional parameters can be used to restrict
which alarm conditions will be reported to the application.
Comments Call GetNext to obtain the next value of the point. Only one of the
OnChange , OnAlarm , OnTimed or OnAlarmAck requests may be
active at a time. Optional Parameters
Value Description
MyPoint.Id = "TANK_LEVEL"
MyPoint.OnAlarm
Top:
MyPoint.GetNext
MsgBox "Unavailable"
else
MsgBox "Normal"
end if
goto top
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 797
See Also Point.GetNext (on page 788) (method); Point.Cancel (on page
780) (method); Point.OnAlarmAck (on page 797) (method).
Notes The point value is sent when the point goes to warning or alarm
state (based on the selected value), and then point value is sent
again when the point goes back to normal state.
Point.OnAlarmAck (statement)
Syntax Point.OnAlarmAck
Descrip To receive the point's value when the alarm acknowledgment state changes.
tion
Only one of the OnChange , OnAlarm , OnTimed or OnAlarmAck requests may be active
at a time.
See also Point.GetNext (on page 788) (method); Point.Cancel (on page 780) (method); Point.On
Alarm (on page 795) (method).
Point.OnChange (statement)
Syn Point.OnChange
tax
De To request the point's value on change. The next value of the point may be received by calling the
scrip GetNext method or function. The current value of the point is returned immediately. Any subse
tion quent GetNext call will block until the point's value changes.
Only one of the OnChange , OnAlarm , OnTimed or OnAlarmAck requests may be activate at a
time.
Sub Main()
top :
End Sub
See Point.GetNext (on page 788) (method); Point.OnTimed (on page 798) (method); Point.Cancel
also (on page 780) (method).
Point.OnTimed (statement)
De To poll the points value periodically. A new value will be sent to the application every time_peri
scrip od seconds. The application should call GetNext to retrieve the next value.
tion
Com Unlike the OnChange method, you may miss values of the point if it changes in between your
ments polls. Use the OnChange method to receive the point whenever it changes. OnTimed is useful
if the point is rapidly changing and you are only interested in its value in a periodic manner. Only
one of the OnChange , OnAlarm , OnTimed or OnAlarmAck requests may be active at a time.
Parameter Description
ple Dim MyPoint as new Point ' Declare the point object
Top :
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 799
See Point.GetNext (on page 788) (method); Point.OnChange (on page 797) (method); Point.Can
Also cel (on page 780) (method).
Syntax Point.PointTypeId
MyPoint.Id = "CP_DIGITAL"
else
end If
End Sub
Syn Point.QuadValueAsString
tax
De String. To return the string for the point values that are QINT,UQINT. Converts LONGLONG or
scrip ULONGLONG values of datatypes QINT or UQINT into strings and returns them.
tion
p.Id = "UQINT"
val = p.QuadValueAsString
MsgBox val
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 800
See Point.QuadValueAsString (on page 800) (property, write), write,) Point.SetQuadIntValue (on
also page 810) (function), Point.TimeStampHR (on page 791) (property, read).
Syn Point.QuadValueAsString
tax
De Boolean. To take string of digits and convert them into 64-bit values and set the point values.
scrip
tion
p.Id = "UQINT"
End Sub
Syntax Point.Quality
Description Long. Return the 16-bit quality mask for the point.
p.Id = "VALVE_1"
p.Get
MsgBox cstr(p.Quality)
End Sub
Syntax Point.QualityAlarmed
p.Id = "VALVE_1"
p.Get
if p.QualityAlarmed then
End If
End Sub
Syntax Point.QualityAlarms_Enabled
Description Boolean. Returns TRUE if alarming for the point is enabled, FALSE otherwise.
p.Id = "VALVE_1"
p.Get
if p.QualityAlarms_Enabled then
End If
End Sub
Syntax Point.QualityDisable_Write
Description Boolean. Returns TRUE if setpoints have been disabled for the point, FALSE otherwise.
p.Id = "VALVE_1"
p.Get
if p.QualityDisable_Write Then
End If
End Sub
Syntax Point.QualityIs_Available
Description Boolean. Returns TRUE if the points value is available, FALSE if the value is unavail
able.
p.Id = "VALVE_1"
p.Get
End If
End Sub
Syn Point.QualityIs_In_Range
tax
De Boolean. Returns TRUE if the current value of the point is in range, FALSE if the point is out of
scrip range. When a point is out of range its value is unavailable.
tion
p.Id = "VALVE_1"
p.Get
End If
End Sub
Syntax Point.QualityLast_Upd_Man
Descrip Boolean. Returns TRUE if the current value of the point came from a manual update rather
tion than a device read.
p.Id = "VALVE_1"
p.Get
if p.QualityLast_Upd_Man then
End If
End Sub
Syntax Point.QualityManual_Mode
Description Boolean. Returns TRUE if the point has been placed into Manual Mode, otherwise
FALSE.
p.Id = "VALVE_1"
p.Get
if p.QualityManual_Mode then
Else
End If
End Sub
Syntax Point.QualityStale_Data
De Boolean. Returns TRUE if the value of the point is stale, otherwise FALSE. For more information
scrip on stale data, see QUALITY.STALE_DATA (Attribute) (on page ).
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 804
p.Id = "VALVE_1"
p.Get
if p.QualityStale_Data = TRUE
End If
End Sub
De Same as Point.Value except bypasses Engineering Units conversion if configured for the point.
scrip Will return into any type subject to some restrictions. All numeric types may be returned into
tion any other numeric type and into string types. String and BitString types can only be returned into
string types. If the variable being returned into does not have a type, the variable will be changed
to the appropriate type, based on the point type.
Com The option base determines if the first element of an array point will be zero or one. If you do
ments not explicitly set the option base , all arrays in Basic start at 0. If you set it to 1, all arrays in Ba
sic start at 1. See the example below.
.RawValue does not return the underlying numerical value for an enumerated point. If you want to
obtain the underlying numerical value.
Parame Description
ter
index Integer. (optional) The array element to access. Range depends on the option base
setting.
End sub
Sub Main()
next I
End Sub
Sub Main()
' Loop through all elements. Since arrays are set to start
' at 0, the index of the last element is one less than the
for I = 0 to MyPoint.Elements - 1
next I
End Sub
Exam 'Access both the enumerated text and the underlying numerical 'value for a point.
ple 2 Sub Main()
p1.id = "ENUMERATEDPOINT"
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 806
p1.get
trace "enumerated text for " & p1.id & " is " & p1.value
p2.id = "ENUMERATEDPOINT.$RAW_VALUE"
p2.get
trace "underlying numeric value for " & p1.id & " Is " & p2.value
End Sub
Syntax Point.ReadOnly
else
end if
End Sub
Point.Set (statement)
De To write the point's value out to the CIMPLICITY project. An optional download password can be
scrip supplied.
tion
Com The values set into the Point using the Value, RawValue, SetArray and SetRawArray methods are
ments not written out to the CIMPLICITY project until they are committed with a Set or SetNoAudit (on
Parameter Description
ple Dim MyPoint as new Point ' Declare the point object
End Sub
See Point.SetValue (on page 812) (property, write), and Point.SetNoAudit (on page 809) (state
Also ment)
Point.SetArray (statement)
If the startElement is specified, the function will start copying data from the array at this ele
ment and will continue until the end of the array is reached or the point is full whichever occurs
first. If the endElement is specified, the function will stop copying data from the array after copy
ing this element or when the point is full. If the fromElement is specified, the values copied from
the array start at this element in the point array and continue as described above.
Parameter Description
array Array. A dimensioned or undimensioned Basic Array from which the point data will
be copied.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 808
startEle Integer. (optional) The first array element from which data will be copied.
ment
endEle Integer. (optional) The last array element from which data will be copied.
ment
fromEle Integer. (optional) The first point element to which data is to be copied.
ment
Exam ' Read an array point, sort the elements by value and write them
Sub Main()
End Sub
See Point.SetRawArray (on page 810) (method); Point.Value (on page 819) (property, read/write),
Also Point.GetArray (on page 786) (method); Point.Set (on page 806) (method).
Note The SetArray method only updates the internal value of the point object. The Set method
must be executed to write the value out to the CIMPLICITY project.
Point.SetElement (statement)
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 809
MyPoint.Id = "INT_ARRAY"
End Sub
Point.SetNoAudit (statement)
De To write the point's value to the CIMPLICITY project. Setpoint audit trail events will not be trig
scrip gered when using this method. An optional download password can be supplied.
tion
Com The values set into the Point using the Value, RawValue, SetArray and SetRawArray methods are
ments not written out to the CIMPLICITY project until they are committed with a Set (on page 806) or
SetNoAudit statement.
Parameter Description
ple Dim MyPoint as new Point ' Declare the point object
End Sub
Syntax Point.SetpointPriv
Description Boolean. To determine if the user accessing the point has Setpoint privilege.
MyPoint.Id = "TANK_LEVEL"
else
end if
End Sub
Point.SetQuadIntValue (function)
Syn Point.SetQuadIntValue(qhigh,qlow)
tax
De To set the point's value in a CIMPLICITY project. This operation combines the Value and Set oper
scrip ations into one command. The SetQuadIntValue function takes two double values to set the value
tion of any 64 bit data type QINT or UQINT.
Ex ' To set the value of any point with data type QINT or UQINT
qstr = "1000000899876543212"
QINTFromString qstr,qhigh,qlow
SetQuadIntValue (qhigh,qlow)
End Sub
Point.SetRawArray (statement)
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 811
De To set an array point's values directly from a Basic array, bypassing Engineering Units Conver
scrip sion.
tion
If the startElement is specified, the function will start copying data from the array at this ele
ment and will continue until the end of the array is reached or the point is full whichever occurs
first. If the endElement is specified, the function will stop copying data from the array after copy
ing this element or when the point is full. If the fromElement is specified, the values copied from
the array start at this element in the point array and continue as described above.
Parameter Description
array Array. A dimensioned or undimensioned Basic Array from which the point data will
be copied.
startEle Integer. (optional) The first array element from which data will be copied.
ment
endEle Integer. (optional) The last array element from which data will be copied.
ment
fromEle Integer. (optional) The first point element to which data is to be copied.
ment
Exam ' Copy the log value of one array point to another array point.
for I = 0 to source.Elements - 1
x(I) = log(x(I))
next I
End Sub
See Point.SetArray (on page 807) (method); Point.RawValue (on page 804) (property, read/write);
Also Point.GetRawArray (on page 790) (method).
Note The SetRawArray method only updates the internal value of the point object. The Set method
must be executed to write the value out to the CIMPLICITY project.
Syn Point.SetValue = a
tax
De To set the point's value in a CIMPLICITY project. This operation combines the Value and Set
scrip operations into one command. The SetValue method uses Engineering Units Conversion and
tion cannot be used to set elements of an array point.
Ex ' Ramp tank level from 0 to 100 in steps of five, with a delay
next I 'Loop
End Sub
Syntax Point.State
State Description
Example ' Increment the point value by one, if the point is unavailable,
' set it to 0.
Sub Main()
MyPoint.Id = "TANK_LEVEL"
MyPoint.Get
MyPoint.SetValue = 0
else
MyPoint.SetValue = MyPoint.Value + 1
end if
End Sub
See Also Point.Get (on page 786) (method); Point.GetNext (on page 788)
(method)
Point (subject)
Overview The values of CIMPLICITY points can be used in a variety of ways by a script. You can use
scripts that act on point values to define reactions to changing conditions in your process.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 814
Points are manipulated by the PointSet statement and PointGet function or the point ob
ject. In general, PointSet and PointGet are useful if you require the value of the point or
wish to set the point. The point object extends your capabilities by allowing you to receive
point values as they change, access array points, provide more information about the point's
configuration; and improve performance when repeatedly setting a point.
Security The CIMPLICITY extensions to Basic provide the same security which all your CIMPLICITY
applications use; Set Point Security, Set Point Privilege, Download Password and Set Point
Audit trail. In order to discuss security, first we will need to understand when security is im
posed on your access to points. There are two categories of processes running on your CIM
PLICITY Server; User Applications and Resident Processes. User Applications are applica
tions run by the user, that usually provide a user interface. Examples of such programs are
CimView, CimEdit, Alarm Viewer and Program Editor. In order for the application to access
a point on the local CIMPLICITY project or a remote CIMPLICITY project, a user login is re
quired. The CIMPLICITY privileges defined for your User ID define your capabilities. Resident
Processes are processes that are started as part of your CIMPLICITY project. Examples of
resident processes are the Database Logger, Point Manager and scripts automatically run by
the Basic Control Engine. Since a resident process is a trusted part of your system, a resident
process is not required to obtain a login in order to access points in their project. If the resi
dent process wishes to access a point on a remote system, a remote project must be config
ured to supply the resident process with the User ID and Password with which to log in to the
remote system.
Perfor The CIMPLICITY extensions to Basic provide a high performance mechanism to interact with
mance your Point Database. However, there are several considerations to keep in mind when design
ing your application to obtain the highest performance possible. First, is the Set Point Audit
Trail. For each CIMPLICITY role, you may configure whether or not the user will generate an
audit trail for each setpoint. The audit trail is composed of a $DOWNLOAD event containing
information on who set the point. This information is sent to your event log and can provide
a detailed audit trail of who and what was set. However, the audit trail imposes significant
overhead (20 times slower), since the record is logged to the database for each setpoint. This
is particularly noticeable when running setpoints in a loop in the Program Editor. However,
when the script is run from the Basic Control Engine, a $DOWNLOAD event will not be gener
ated since a resident process is trusted. If you do not require an audit trail is it recommended
that you disable it through role configuration (this is the default).
Second, is the difference between a PointSet statement and using the Point Object. With a
Point Object, you create the object once and initialize its point information once (data type, el
ements, etc.). Subsequent operations on the Point are very fast, since the point characteris
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 815
tics are contained in the object. Conversely, PointSet and PointRead must fetch the point
information on each execution (in benchmark testing this is 2 times slower.) Consider the fol
lowing example :
sub slow_set()
for I = 0 to 100
PointSet "MY_POINT", I
next I
End Sub
sub fast_set
MyPoint.Id = "MY_POINT"
for I = 0 to 100
MyPoint.SetValue = I
next I
End Sub
The subroutine fast_set ramps the point ten times faster than the slow_set routine. While
the second example at first may appear more complex, you will find that the object interface
provides much more flexibility. As a rule, use PointGet and PointSet when you need to read
or set the point's value once within your script.
Polling CIMPLICITY provides a high performance Point Interface. As a result, improperly written ap
plications can degrade the overall performance of a system. One common issue is polling a
point to wait for it to change. Consider the following example. Incorrect Code
Poll:
If PointGet("POLL_POINT") = 0 then
Sleep 100
Goto poll
End If
The sleep statement causes a 100ms delay between polls. However many extra polls are still
being performed. Correct and Most Efficient Code
p.Id = "POLL_POINT"
p.Onchange
Poll:
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 816
Wait_for
p.GetNext
In this example, the script requests the value of the point as it changes. When the point
changes, the GetNext statement returns. When the point is not changing the script is waiting
and using no system resources.
Error Basic provides a flexible error handling capability with the On Error command. The CIMPLICI
Handling TY extensions to Basic are designed to use the built in error handling capability. When an er
ror occurs while executing your CIMPLICITY command, a Basic Run Time error is generated.
There are many ways you can implement error handling. Among these are :
• No error handling. When an error occurs, the script's execution halts and the error is re
ported (in the Program Editor, this is via a Message Box, and in the control engine by
logging an error message to the status log).
• Error Handler. When an error occurs, the script's execution moves to the defined error
handler. Within the error handler, the user can report the error or try to recover.
• In line error checking. When an error occurs, the script's execution continues on the
next program statement. The user can check the err variable to determine if an error
occurred.
In the fast_set example above a run time error could be generated on the setting of the ID
or the setting of the value. Since the routine provides no error handling, when an error oc
curs, the routine exits and returns to the calling routine. If no error handler is found as the
program returns up the call stack, a default error handler reports the run-time error. If you run
the script from the Program Editor, a dialog box opens, and if it is run from the Basic Control
Engine, a Status Log message is created.
Sub inline_errorcheck()
PointSet "BAD_POINT", 10
err = 0
Exit Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 817
End if
PointSet "BAD_POINT1", 10
err = 0
Exit Sub
end if
End Sub
sub outline_errorcheck()
PointSet "BAD_POINT", 10
PointSet "BAD_POINT1", 10
Exit Sub
error_handler:
MsgBox "Error"
Exit Sub
End Sub
Syntax Point.TimeStamp
De Date. To retrieve the timestamp into a Basic Date Object. The timestamp indicates the time at
scrip which the point's value was read from the PLC.
tion
x.Id = a$
x.OnChange
top :
x.GetNext
goto top
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 818
See al Point.Get (on page 786) (method); Point.GetNext (on page 788) (method).
so
Syntax Point.TimeStampHR
De Date. To retrieve the Microsecond timestamp into a string object. The timestamp indicates the
scrip time at which the point's value was read from the PLC.
tion
x.Id = a$
x.OnChange
top :
x.GetNext
goto top
End Sub
Syntax Point.UserFlags
Description Long. Returns the value of the 16-bit user defined flags for the
point.
p.Id = "VALVE_1"
p.Get
MsgBox cstr(p.UserFlags)
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 819
De To retrieve or set the value in the point object. The optional index may be supplied to access val
scrip ues of an array point. The first element of the array is at the zero index. The value property uses
tion Engineering Units conversion if supplied by the point. To bypass Engineering Units conversion,
use the RawValue property.
Automatic conversion will be performed between data types as needed. The only exceptions are
String and BitString points, which can only be assigned from Strings.
MyPoint.Value = "10"
MyPoint.Value = 10.01
End Sub
See Point.RawValue (on page 804) (property, read/write); Point.GetArray (on page 786) (method);
also Point.GetRawArray (on page 790) (method).
Notes • To retrieve the point value, the Point.Get method must be invoked first. Once the value
has been read, it can be accessed many times without having to retrieve it from the Point
Manager on each reference. If the point hasn't been read, an exception is generated.
• When setting a value, the value is not written to the device until the Set method is in
voked.
PointGet (function)
Example ' Prompt user for point id, get the point value and display
Sub Main()
End Sub
Important:
For CIMPLICITY Machine Edition's array point names
Enclose CIMPLICITY Machine Edition array point names (that are passed through CIMPLICITY Plant
Edition Basic) in the the ASCII encoding for single quotes Chr$(39).
CIMPLICITY Machine Edition returns array points as single values using the form name[index].
• Is not enclosed in Chr$(39), BASIC will parse this out as a reference to an array element. You will
receive an error indicating a bad point name.
• Is enclosed in Chr$(39) the point will not be parsed in the PointSet and PointGet BASIC procedures.
The name will be passed straight through to Machine Edition.
Note:
You cannot directly put a single quote (') on an argument line because the single quote in Basic
denotes that the remainder of the line is a comment.
Examples
• val = PointGet("MyPointName")
Result
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 821
Result
PointGetMultiple (function)
De Request data from up to 30 points in a single snapshot request. If the function fails, an error is
scrip generated.
tion
Com If you need to get data from several points, use this function rather than issuing a single Point
ments Get command for each point. For the example below, it is six times more efficient to use Point
(Cim GetMultiple , since the data is retrieved from the Point Manager in a single request, rather than
Basic) six separate PointGet requests.
Parameter Description
pointn Point objects for which data is going to be requested. Up to 30 may be specified
as function parameters.
PointGetMultiple x,x1,x2,x3,x4,x5
End Sub
PointGetMultiple takes an array of Point objects, which is different from CimBasic where Cim
Basic functions take variable arguments with each being a Point object. Otherwise .NET and
CimBasic behavior is the same for this function.
using (Point one = new Point(), two = new Point(), three = new Point())
one.Id = "PGM_01";
one.OnChange();
two.Id = "PGM_02";
two.OnChange();
three.Id = "PGM_03";
three.OnChange();
array[0] = one;
array[1] = two;
array[2] = three;
try
Cimplicity.PointGetMultiple(array);
}
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 823
catch (Exception x)
PointGetNext (function)
De To return the next point value from a list of points with a timeout.
scrip
tion
Positive
Integer
Point1 is a point object with an outstanding request. Up to 16 points can be specified on the
function call. Alternatively, the user may pass an array of point objects. The function returns the
object whose value changed or empty. Parameter: timeOutMs, pointn, PointArray.
Exam ' Trace the values of 2 point as they change or trace timeout if neither
Sub Main()
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 824
Top :
Trace "TimeOut"
Else
end if
goto top
End Sub
PointGetNext takes an array of Point objects, which is different from CimBasic where CimBasic
functions take variable arguments with each being a Point object. Otherwise .NET and CimBa
sic behavior is the same for this function.
using (Point one = new Point(), two = new Point(), three = new Point())
one.Id = "PGN_1";
one.OnChange();
two.Id = "PGN_2";
two.OnChange();
three.Id = "PGN_3";
three.OnChange();
array[0] = one;
array[1] = two;
array[2] = three;
try
Point result;
do
if (result != null)
catch (Exception x)
finally
PointSet (statement)
End Sub
Important:
For CIMPLICITY Machine Edition's array point names
Enclose CIMPLICITY Machine Edition array point names (that are passed through CIMPLICITY Plant
Edition Basic) in the the ASCII encoding for single quotes Chr$(39).
CIMPLICITY Machine Edition returns array points as single values using the form name[index].
• Is not enclosed in Chr$(39), BASIC will parse this out as a reference to an array element. You will
receive an error indicating a bad point name.
• Is enclosed in Chr$(39) the point will not be parsed in the PointSet and PointGet BASIC procedures.
The name will be passed straight through to Machine Edition.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 827
Note:
You cannot directly put a single quote (') on an argument line because the single quote in Basic
denotes that the remainder of the line is a comment.
Examples
Result
Result
PointSet sets the element with the index 10 of the Machine Edition array point MEArrayPointName to the
value of val.
Important: This syntax will not work for Plant Edition array points.
Result
PointSet sets the element with the index 10 of the Plant Edition array point PEArrayPointName to the
value of val
PointSetMultiple (function)
De Performs setpoints for up to 30 points in a single setpoint request. If a failure occurs the func
scrip tion returns false, otherwise true is returned.
tion
Com If you need to set the value of multiple points, use this function rather than issuing multiple sin
ments gle setpoint requests for faster script execution. The point ErrCode property will be set to a non-
zero value for a setpoint that failed. The point ErrMsg property will contain the associated error
message.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 828
There are two variants of PointSetMultiple. The first variant takes all the points declared in the
argument list. The second variant takes an array.
Exam This example in Basic demonstrates both variants, argument list and array.
ple 1 Sub Main()
sp1.Value = 1
sp2.Value = 2
sp3.Value = 3
sp4.Value = 4
status = PointSetMultiple(sp1,sp2,sp3,sp4)
MsgBox sp1.ErrMsg
End If
End If
status = PointSetMultiple(points)
End Sub
using System.Collections.Generic;
using Proficy.CIMPLICITY;
int status;
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 829
using (Point sp1 = new Point(),sp2 = new Point(),sp3 = new Point(),sp4 = new Point())
sp1.Id = "SP1";
sp2.Id = "SP2";
sp3.Id = "SP3";
sp4.Id = "SP4";
array[0] = sp1;
array[1] = sp2;
array[2] = sp3;
array[3] = sp4;
sp1.Value = 1;
sp2.Value = 2;
sp3.Value = 3;
sp4.Value = 4;
status = Cimplicity.PointSetMultiple(array);
PointSetMultipleEx (function)
De Performs setpoints for up to 30 points in a single setpoint request, using the provided setpoint
scrip password. If a failure occurs the function returns false, otherwise true is returned.
tion
Com If you need to set the value of multiple points, use this function rather than issuing multiple sin
ments gle setpoint requests for faster script execution. The point ErrCode property will be set to a non-
zero value for a setpoint that failed. The point ErrMsg property will contain the associated error
message.
There are two variants of PointSetMultiple. The first variant takes all the points declared in the
argument list. The second variant takes an array.
Exam This example in Basic demonstrates both variants, argument list and array.
ple 1
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 830
Sub Main()
pwd = "mypassword"
sp1.Value = 1
sp2.Value = 2
sp3.Value = 3
sp4.Value = 4
status = PointSetMultipleEx(pwd,sp1,sp2,sp3,sp4)
MsgBox sp1.ErrMsg
End If
End If
status = PointSetMultipleEx(pwd,points)
End Sub
using System.Collections.Generic;
using Proficy.CIMPLICITY;
int status;
using (Point sp1 = new Point(),sp2 = new Point(),sp3 = new Point(),sp4 = new
Point())
sp1.Id = "SP1";
sp2.Id = "SP2";
sp3.Id = "SP3";
sp4.Id = "SP4";
array[0] = sp1;
array[1] = sp2;
array[2] = sp3;
array[3] = sp4;
sp1.Value = 1;
sp2.Value = 2;
sp3.Value = 3;
sp4.Value = 4;
status = Cimplicity.PointSetMultipleEx("MyPassword",array);
Error Point.ErrCode
Mes
Integer value containing the error code for a failed call to PointSetMulitple or PointSetMultiple
sage
Ex, or zero for a successful operation.
Point.ErrMsg
String value containing the error message for a failed call to PointSetMulitple or PointSetMulti
pleEx, or empty string for a successful operation
SetTimecomponentsHR (function)
De Given components of the time. Current time divided into time components of year, month, day,
scrip hour, min, sec and nanoseconds.
tion
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 832
Dim yy As Integer
Dim mm As Integer
Dim dd As Integer
Dim hh As Integer
'Initialize Objects
yy = 2011
mm = 7
dd = 13
min = 43
sec = 10
nano = 0
SetTimeFromComponentsHR qhigh,qlow,yy,mm,dd,hh,min,sec,nano
MsgBox qhigh
MsgBox qlow
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 833
QINTFromString (function)
Description To convert one numeric string into QINT , split it’s value into 2 doubles and return
them.
Param1 String.
qstr = "1000000899876543212"
QINTFromString qstr,qhigh1,qlow1
ret = MyPoint.SetQuadIntValue(qhigh,qlow)
End Sub
StringFromQINT (function)
tax
De To convert two doubles into one signed 64-bit value and finally to a string
scrip
tion
Param1 String.
Param2 Double.
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 834
Param3 Double.
ret = MyPoint.GetQuadIntValue(qhigh,qlow)
‘qlow
End Sub
See DoQINTMath (on page 767) (function), DoUQINTMath (on page 768) (function), Point.Quad
also ValueAsString (on page 799) (property, read), Point.QuadValueAsString (on page 800) (prop
erty, write), Point.SetQuadIntValue (on page 810) (function), StringFromUQINT (on page 833)
(function).
StringFromUQINT (function)
tax
De To convert two doubles into one signed 64-bit value and finally to a string
scrip
tion
Param1 String.
Param2 Double.
Param3 Double.
ret = MyPoint.GetUQuadIntValue(qhigh,qlow)
‘qlow
End Sub
See DoQINTMath (on page 767) (function), DoUQINTMath (on page 768) (function), Point.Quad
also ValueAsString (on page 799) (property, read), Point.QuadValueAsString (on page 800) (prop
erty, write), Point.SetQuadIntValue (on page 810) (function), StringFromQINT (on page 833)
(function).
Trace (statement)
Syn Trace a$
tax
De Traces (prints) a string to the trace output. By default, when running in the Program Editor, tracing
scrip will be output to the trace window. When running from the Event Manager, tracing must be specif
tion ically enabled (TraceEnable) in order for tracing to occur.
x.Id = a$
x.OnChange
top :
x.GetNext
goto top
End Sub
TraceEnable/TraceDisable (statement)
De TraceEnable enables tracing to a file. The file will be located in your project's log directory. Trac
scrip ing to a file is only supported from the event manager. The trace output will be written to the log
tion directory. Tracing has a performance impact since the file is opened and closed for each write.
Tracing is intended for debug use only and should be removed from production code.
end if
TraceDisable
End Sub
UQINTFromString (function)
De To convert one numeric string into UQINT , take a positive value with the highest value that can
scrip be taken by ULONGLONG and return it.
tion
Param1 String.
qstr = "1000000899876543212"
UQINTFromString qstr,qhigh1,qlow1
ret = MyPoint.SetQuadIntValue(qhigh,qlow)
End Sub
Basic Control Engine and Scripting Reference | 3 - Basic Control Engine Language Reference | 837
The BCEUI window displays the status of actions triggered by events that are currently being monitored by
BCEUI. You can use the Paused option to display this list in dynamic or paused mode.
• In dynamic mode, the list is automatically refreshed as events occur or change status.
• In paused mode, the list remains fixed until you update it. To update the list, you can select Refresh
from the View menu, or press F5.
• Actions for all running projects that BCEUI is connected to are displayed in black.
• If BCEUI is connected to a CIMPLICITY project and monitoring events, and the project stops:
• All events for the project are grayed out in the Properties dialog box.
• Triggering is disabled for events in the stopped project.
• A $Disconnected event displays in the main window with a message telling you which project is
stopped. This event runs and tries to reconnect to the project until either the project starts or you
close your BCEUI session.
• All unfinished actions in the main window are grayed out to indicate that their current status is
unknown.
• When a CIMPLICITY project that BCEUI is attempting to connect to restarts, grayed actions are
redisplayed in black and refreshed to their current status.
1. Select Project>Basic Control Engine>BCE User Interface in the Workbench left pane.
2. Select BCE User Interface in the Workbench right pane.
3. Do one of the following.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 839
Either Or
BCEUI Menus
BCEUI Menus
You can use the menu options to save and restore event monitoring configurations, add or list events,
pause, stop or resume scripts, trigger events, pause and resume dynamic updates, refresh the display and
access Help.
File menu
Events menu
Scripts menu
View menu
Help menu
Open Opens an existing BCEUI document in your currently active BCEUI window.
Save Saves the current BCEUI document to a file. Use this option if you want to specify the path
As… name of the saved file.
Recent Displays a list of recently opened BCEUI document files for easy retrieval.
File
List Opens the Properties dialog box, from which you can add, delete or trigger events.
Add Opens the Select an Event browser, from which you can connect to a project and select events to
add to the list of monitored events.
Stop Stops any currently selected scripts that are paused or run
ning.
Clear Finished Actions Clears finished actions from the event list.
Help Topics Displays the main Help windows for the BCEUI.
About BCEUI Displays the program identification, version number and copyright for the
BCEUI.
BCEUI Toolbar
You can use the Toolbar option on the View menu to turn on and off the display of the BCEUI Toolbar. You
can fix the Toolbar in the BCEUI window or display it in a separate window at your discretion.
Event List Opens the Properties dialog box, from which you can add, delete or trigger
events.
Add Events Opens the Select an Event browser, from which you can connect to a
project and select events to add to the list of monitored events.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 843
Stop Scripts Stops any currently selected scripts that are paused or running.
About Displays the program identification, version number and copyright for the
BCEUI.
The following are the more commonly used keystrokes that are available for your use in the BCEUI:
BCEUI Viewer
BCEUI Viewer
• Use the Select an Event browser to connect to a project and select events to add to the BCEUI
event list.
• Use the Properties dialog box to list monitored events, add or remove events from the view, and
trigger events manually.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 844
After you create a BCEUI view, you can select script actions and pause, resume, or stop the scripts.
Once you create a BCEUI view, you can save it. You can recall saved views at any time.
When you select Add from the Events menu or click the Add Events button on the Toolbar, the Select an
Event browser opens.
After you select events and click OK, the Properties dialog box automatically opens so that you can add
the selected events to your view. If you click Cancel, the Select an Event browser closes and the main
BCEUI window is redisplayed.
By default, the Auto Browse option is disabled. If you enable the Auto Browse option, whenever you open
the Select a Event dialog box, the events for the first project in the Project list are automatically displayed
in the list window.
If Auto Browse is enabled, a check mark is displayed to its left in the View menu.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 846
3. Connect to a Project
1. Click the drop-down list button to the right of the Project field to see the list of currently available
projects.
2. Select a project from the list.
3. Click Browse to see the list of events available for the project.
4. Select Events
1. Highlight the events you want to select. You may use the Shift and Ctrl keys when selecting
multiple events.
2. Click OK to transfer your selection to the BCEUI event list and close the Select an Event browser.
Note:
Note the following:
• Triggering is enabled only for events in connected projects that are running.
• All events for projects that are running and BCEUI is connected to are displayed in black.
• Events in the list that belong to projects that are not currently running or that become disconnected
are grayed out.
• When you add events for a new project, they are grayed out in the Properties dialog box because
BCEUI has not connected to the project yet.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 848
• The first time you select an event for a newly selected project, then select Apply, BCEUI connects
to the project. When the connection completes successfully, all the events for the project are
displayed in black.
• You can select events for projects that are not currently running or that are disconnected. When the
project starts, BCEUI will automatically connect with the project and start monitoring the events.
The default maximum number of completed actions that the BCEUI window can display is 100. You can
choose less or more than this number. Once the list reaches its maximum, the oldest completed action is
removed when the newest one is added.
1. Select the events you want to monitor from the list of events in the Select an Event browser. You
can use the Shift and Ctrl keys to select multiple events.
2. Click Apply to add the events to the view and keep the Properties dialog box open, or click OK to
add the events to the view and close the Properties dialog box.
1. Select the events in the list that you want to remove. You can use the Shift and Ctrl keys to select
multiple events. You can also click Select All to select all events in the list.
2. Click Delete.
The events you select are removed from the BCEUI window and the Properties dialog box.
They will not appear again in Properties dialog box until you add them in the Select a Event
browser, and they will not be monitored again in the BCEUI window until you select them for
viewing in the Properties dialog box.
9. Trigger Events
Your role must have the Trigger Event privilege enabled for you to be able to trigger events for a particular
project.
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 849
1. Select the events in the list that you want to trigger. You can use the Shift and Ctrl keys to select
multiple events. You can also click Select All to select all events in the list.
2. Click Trigger.
The Confirm Trigger Action message box opens and displays the first event to trigger.
Note:
If you click Yes or No and you are triggering multiple events, you are automatically
prompted to confirm the next trigger action.
The statuses of the events you trigger are displayed in the BCEUI window.
Control Scripts
Control Scripts
Your role must have the Script Control privilege enabled for you to be able to pause, resume and stop
scripts in the BCEUI window in specific projects.
Pause Scripts
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 850
1. Select the actions whose scripts you want to pause in the BCEUI window. You can use the Shift
and Ctrl keys to select multiple actions.
You may safely select multiple scripts, even if some of the scripts you select cannot be paused
(such as stopped scripts or scripts that are already paused). Such scripts will not be affected by
the Pause Scripts request.
Note:
If you click Yes or No and you are pausing multiple scripts, you are automatically prompted
to confirm the next script in the list.
Resume Scripts
Basic Control Engine and Scripting Reference | 4 - Basic Control Engine User Interface | 851
1. Select the actions whose scripts you want to resume in the BCEUI window. You can use the Shift
and Ctrl keys to select multiple actions.
2. Do one of the following.
◦ Select Resume from the Scripts menu, or
◦ Click the Resume Scripts button on the toolbar, or
◦ Select Resume from the Window Pop-up menu.
Note: If you click Yes or No and you are resuming multiple scripts, you are automatically prompted
to confirm the next script in the list.
Stop Scripts
1. Select the actions whose scripts you want to stop in the BCEUI window. You can use the Shift and
Ctrl keys to select multiple actions.
2. Do one of the following.
◦ Select Stop from the Scripts menu, or
◦ Click the Stop Scripts button on the toolbar, or
◦ Select Stop from the Window Pop-up Menu.
Note: If you click Yes or No and you are stopping multiple scripts, you are automatically prompted
to confirm the next script in the list.
The status of the scripts for the events you select changes from Paused or Running to Stopped and the
message field for each stopped script displays the line number where the script was stopped.
Note:
Once you stop a script, you cannot restart it with the Resume command.
Chapter 5. Event Editor
About the Event Editor
You use the Event Editor to define actions to take in response to events that occur in a process. One event
may invoke multiple actions, or one action may be invoked by many events.
An event can be defined as a changing point or alarm state, or even a time of day.
At run-time, the Basic Control Engine monitors for events and executes the configured actions.
The Basic Control Engine is based on a multi-threaded design, which allows the system to invoke and
execute multiple Basic Control Engine scripts concurrently.
The order of execution of event actions is a sequential execution from top to bottom.
Note: The script is run in parallel with all actions that are being executed for the event. In other words, the
Basic Control Engine does not wait for the script to complete before it initiates the next action defined for
the event.
Point Actions Based on Alarm Events Allow a physical indication of an alarm, such as activating a
light on a control panel.
Events Whose Actions Call A User-Defined Defines custom functions that are invoked in response to
Routine or Script configured system events.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 854
Note:
The Basic Control Engine calls a startup script when the Event Manager starts up and a
termination script when it shuts down. These scripts are initially null (that is, they do not do
anything). You can use these scripts to perform initialization and termination tasks, such as
restoring and saving the value of a global variable. The two scripts are:
• EM_INIT.BCL
• EM_TERM.BCL
You will find copies of these scripts in your project's \scripts directory.
Step 6 Copy, filter, select display fields for events and ac
(on page tions.
895)
Basic Control Engine and Scripting Reference | 5 - Event Editor | 855
Either Or
Either Or
You can use the menu options to create new events and actions, modify, delete or copy selected events
and actions, reorder the actions for an event, display the attributes for an event or action, toggle dynamic
updates, and access Help.
• File menu
• Edit menu
• View menu
• Tools menu
• Help menu
Basic Control Engine and Scripting Reference | 5 - Event Editor | 857
File menu
New Left Event Creates a new Event. This option is displayed if the Event pane is active.
Event... (on
page
863)
New Right Event Creates a new action for the currently selected Event. This option is displayed
Event_ (on if the Event pane is active, and you have clicked the mouse once in the Action
Action... page pane.
893)
New Ac Left Ac Creates a new Action. This option is displayed if the Action pane is active.
tion... tion
(on
page
879)
Edit Menu
1 An event is selected.
2 An action is selected.
Modify Opens the Modify Event dialog box, and lets you change the Event Type and associated
Event fields.
Modify Ac Opens the Modify Action dialog box, and lets you change the Action Type and associated
tion fields.
Delete Event Deletes the selected Event from the list of available Events
Delete Removes the selected Action from the list of Actions for the selected Event.
Event-Action
Delete Ac Deletes the Action. This function will remove the Action from all Events that use it and re
tion move it from the list of available Actions.
Copy Event Copies the selected Event to a new Event. You can also choose to copy the Actions.
Move Up While viewing Event-Actions, controls the execution order of the selected Action by mov
ing it up in the list of Actions for the Event.
Move Down While viewing Event-Actions, controls the execution order of the selected Action by mov
ing it down in the list of Actions for the Event.
Alarm Filter Opens the Alarm Setup dialog box and lets you set the filter for the alarms the Event Man
ager will respond to.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 859
Note:
Scripts run a-synchronously, so their order in the list does not guarantee their order of execution.
Other actions, like Setpoint , can be ordered.
View menu
1 An event is selected.
2 An action is selected.
Search If you are displaying By Event, opens the Event Search dialog box. If you are displaying By
Action, opens the Action Search dialog box.
Event At If you are displaying By Event, opens the Configure Display Attributes dialog box for Events,
tributes... and lets you select Event attributes to display in the window.
Action At If you are displaying By Action, opens the Configure Display Attributes dialog box for Ac
tributes... tions, and lets you select Action attributes to display in the window.
All Ac Displays all Actions in the Action pane. You can then select Actions and drag them into an
tions Event.
Tools menu
Dy Enables or disables Dynamic Configuration of points, alarms, etc., when configuring Events or Ac
nam tions.
ic
Up Dynamically updates the Basic Control Engine with the current Event configuration and scripts
date used by the Actions in the configuration. The Basic Control Engine normally loads and compiles
your scripts at project startup. If you modify a script and save it to disk while your project is run
ning, the Basic Control Engine will not load the modified script until you perform an Update or the
until project is stopped and restarted.
Help menu
Index Displays the main Help window for the Event Editor.
Using Help Displays the main Help window for Windows operating system.
About Eventmgr Displays the program identification, version number, and copyright for the Event
Cfg... Editor.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 861
1 Event is selected
2 Action is selected
F Attributes Opens the Field Chooser dialog box for events or actions.
J Action order up Moves the selected action up in the list for an event.
K Action order Moves the selected action down in the list for an event.
down
The following are the more commonly used keystrokes that are available for your use in the Event Editor:
Key Description
stroke
Method 1
Method 2
Method 3
Select New Event on the Event Editor File menu (on page 857).
Basic Control Engine and Scripting Reference | 5 - Event Editor | 864
Method 4
Note: The event ID can be a maximum of 256 characters and mixed case.
5. Click OK.
Events are:
◦ Alarm Acknowledged
◦ Alarm Deleted
◦ Alarm Generated
◦ Alarm Reset
◦ Point Change
Basic Control Engine and Scripting Reference | 5 - Event Editor | 865
◦ Point Equals
◦ Point Transition High
◦ Point Transition Low
◦ Point Unavailable
◦ Point Update
◦ Run Once
◦ Timed
Note:
You can modify these fields in the Modify Event (on page 896) dialog box.
The dialog box closes and the new event appears in the Event list in the CIMPLICITY Event Editor window.
An Alarm Acknowledged Event occurs when the alarm identified in the Alarm ID field for the Event is
acknowledged.
Field Description
Alarm ID of an alarm or wild card to specify a group of alarms that will trigger this event when the
ID alarm is acknowledged.
Displays popup menu to create a new alarm, browse for or edit an existing
alarm
Displays popup menu to create a new resource, browse for or edit an exist
ing resource.
Class Alarm classification that will evaluate this event. Note: This field is unavailable if an Alarm ID is
ID selected
Displays popup menu to create a new alarm class, browse for or edit an ex
isting alarm class.
Note:
Alarms can be acknowledged manually by operators, or automatically via software.
An Alarm Deleted Event occurs when the alarm identified in the Alarm ID field for the Event is deleted.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 867
Field Description
Alarm ID of an alarm or wild card to specify a group of alarms that will trigger this event when the
ID alarm is deleted.
Displays popup menu to create a new alarm, browse for or edit an existing
alarm
Displays popup menu to create a new resource, browse for or edit an exist
ing resource.
Class Alarm classification that will evaluate this event. Note: This field is unavailable if an Alarm ID is
ID selected
Displays popup menu to create a new alarm class, browse for or edit an ex
isting alarm class.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 868
Note:
Alarms may be deleted manually by operators, or automatically via software.
An Alarm Generated Event occurs when the alarm identified in the Alarm ID field for the Event is
generated.
Field Description
Alarm ID of an alarm or wild card to specify a group of alarms that will trigger this event when the
ID alarm is generated.
Displays popup menu to create a new alarm, browse for or edit an existing
alarm
Displays popup menu to create a new resource, browse for or edit an exist
ing resource.
Class Alarm classification that will evaluate this event. Note: This field is unavailable if an Alarm ID is
ID selected
Displays popup menu to create a new alarm class, browse for or edit an ex
isting alarm class.
Note:
All alarm events allow wild cards for pattern matching. Valid wild cards are * and ?. In the above
example, the event "Alarm" will occur whenever a HIGH Class alarm occurs.
An Alarm Reset Event occurs when the alarm identified in the Alarm ID field for the Event is reset.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 870
Field Description
Alarm ID of an alarm or wild card to specify a group of alarms that will trigger this event when the
ID alarm is reset.
Displays Popup menu to create a new alarm, browse for or edit an existing
alarm
Displays Popup menu to create a new resource, browse for or edit an exist
ing resource.
Class Alarm classification that will evaluate this event. Note: This field is unavailable if an Alarm ID is
ID selected
Displays Popup menu to create a new alarm class, browse for or edit an ex
isting alarm class.
Note:
Alarms can be reset manually by operators, or automatically via software.
A Point Change Event occurs when value of the point identified in the Point ID changes.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 871
Note:
Point value changes to and from the unavailable value are not Point Change events. Use the Point
Update (on page 875) event to detect these changes.
Field Description
Point ID of a point that will trigger this event when the point value changes.
ID
Displays Popup menu to create a new alarm, browse for or edit an ex
isting alarm
A Point Equals Event occurs when value of the point identified in the Point ID field equals the value in the
Value field.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 872
Field Description
Point ID of a point that will trigger this event when the value equals the value in the Value field.
ID
A Point Transition High Event occurs when value of the Digital type point identified in the Point ID field
transitions to HIGH (that is, it changes value from 0 to 1).
The code explicitly runs the action for transition high (or transition low events) if the value was
unavailable.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 873
Field Description
Point ID of a point that will trigger this event when the point value transitions to HIGH. If the point is
ID an array point, you can specify the element that will trigger this event. To specify an element, ap
pend the index in brackets at the end of the Point ID (for example, ARRAY_PT[3]). If you do not
specify the element for an array point, the first element is assumed.
A Point Transition Low Event occurs when value of the Digital type point identified in the Point ID field
transitions to LOW (that is, it changes value from 1 to 0).
The code explicitly runs the action (for transition high or) transition low events if the value was
unavailable.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 874
Field Description
Point ID of a point that will trigger this event when the point value transitions to LOW. If the point is an
ID array point, you can specify the element that will trigger this event. To specify an element, ap
pend the index in brackets at the end of the Point ID (for example, ARRAY_PT[3]). If you do not
specify the element for an array point, the first element is assumed.
A Point Unavailable Event occurs when value of the point identified in the Point ID field becomes
unavailable.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 875
Field Description
Point ID of a point that will trigger this event when the point becomes unavailable.
ID
A Point Update Event occurs when value of the point identified in the Point ID field is updated. The rate
at which the point is updated is a function of its Update criteria, which will be one of the following:
On Demand On The point is updated at each scan interval while it is being requested by a CIM
Scan PLICITY process.
On Demand On When its value changes while it is being requested by a CIMPLICITY process.
Change
Field Description
Point ID of a point that will trigger this event when the point value updates.
ID
Displays Popup menu to create a new point, browse for or edit an ex
isting point.
Note:
Point value changes to and from the unavailable value are also Point Update (on page 875)
events.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 877
Run Once
The Event Type, Run Once , is invoked once when the Event Manager starts.
Field Description
Timed Events
The various options in the Advanced section in the New Event dialog box are as follows.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 878
Option Description
Script Ex In Par Runs a script each time an event is invoked. More than one copy of the script may
ecution allel run at a time. You must use critical sections to control access to resources.
The maximum number of scripts that run in parallel is undefined. Thus, several
threads are created to execute the scripts in parallel, thereby requiring more com
puting resources.
In the Runs the script in threads from a thread pool. The thread pool is created when the
thread EMRP process starts.
pool
The scripts also run in parallel, but the number of threads is limited to the size of
the thread pool. For details on the thread pool size and how to configure it, see
Running a script in parallel (in the thread pool).
In Se (Default) When an event is triggered, if an existing instance of the event is still exe
quence cuting, the script will be queued to start after the current script is done.
The maximum number of script actions that can run simultaneously is CE_MAX_
THREADS + CE_POOL_THREADS.
Maximum If the option In sequence is selected, you must specify a maximum queue size. In this case,
Queue when more than 20 events are queued, the oldest will be discarded.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 879
Generate (Default) If the sequential queue overflows, select this check box to generate an $EM_
Alarm on QUEUE alarm.
Overflow
If your event is an alarm event, generating an alarm may cause your event to trigger again
and generate another alarm. This will cause a circular cycle of alarms.
Log Error (Default) If the sequential queue overflows, check to generate a message in the status log.
on Over
flow
Method 1
Method 2
Method 3
Basic Control Engine and Scripting Reference | 5 - Event Editor | 880
Select New Acton on the Event Editor File menu (on page 857).
Method 4
Note: The action ID can be a maximum of 256 characters and mixed case.
Important:
The name must begin with a letter, not a number.
5. Enter the name of the new Action in the Action ID field and click OK.
Alarm Look-Up
Basic Control Engine and Scripting Reference | 5 - Event Editor | 881
Log Only
Recipe Upload/Download
Run Script
Set Point
Transition Set
The dialog box closes and the new action appears in the Action list in the CIMPLICITY Event Editor
window.
Note:
You can modify these fields in the Modify Action (on page 897) dialog box.
(Required) enter the name of the CIMPLICITY Alarm ID for which the action will be taken.
Important:
When you create the Alarm ID in the Alarm Definition dialog box, you must:
A Log Only action logs the associated Event in the Database Logger Event Log. No other action is taken.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 882
A Point Alarm Acknowledge action acknowledges the alarm defined by the Alarm ID and Resource ID.
To create this Action, enter the following information in the New Action dialog box:
1 (on Alarm ID
page
882)
2 (on Re
page source
883)
1 Alarm ID
ID of an alarm to be acknowledged.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 883
Popup Menu Displays Popup menu to create a new alarm, browse for or edit an ex
button isting alarm
2 Re
source
Note:
This field is automatically filled in, when an Alarm ID is entered, with the resource assigned to the
alarm.
Popup Menu Displays Popup menu to create a new resource, browse for or edit an
button existing resource.
A Point Alarm Disable action disables alarming for the point in the Point ID field.
To create this Action, enter the following information in the New Action dialog box:
Point ID
Basic Control Engine and Scripting Reference | 5 - Event Editor | 884
Popup Menu but Displays Popup menu to create a new point, browse for or edit an ex
ton isting point.
A Point Alarm Enable action enables alarming for the point in the Point ID field.
To create this Action, enter the following information in the New Action dialog box:
Point ID
Popup Menu but Displays Popup menu to create a new point, browse for or edit an ex
ton isting point.
Recipe Upload/Download
A Recipe Upload/Download action uploads or downloads the recipe defined by a selected parameter file.
To create this Action, enter the following information in the New Action dialog box:
Basic Control Engine and Scripting Reference | 5 - Event Editor | 885
Parameter
file
Popup Displays a Popup menu to create a new automatic action Recipe file,
Menu but browse for or edit an existing automatic action Recipe file.
ton
The selected script name cannot exceed 48 characters. If you try to select an action with a name longer
than 48 characters CIMPLICITY will not allow you to use it.
A Run Script action executes a selected script. Event Manager supports the following types of scripts:
• Basic Script
• C# Script
• Visual Basic .Net Script
• Python Script
The script is run in parallel with all actions that are being executed for the event. In other words, the Basic
Control Engine does not wait for the script to complete before it initiates the next action defined for the
event.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 886
3. Select OK.
2. Select New.
When the event to which the script is added occurs, the script gets executed. You can view the status of
the script execution in the BCE User Interface.
Note:
The selected script name cannot have more than 48 characters. If you try to select a script with a
name longer than 48 characters CIMPLICITY will display an error message and will not allow you
to use it.
Important:
The Basic Control Engine loads and compiles your scripts when your project starts up. If you
modify a script and save it to disk while your project is running you need to do either of the
following to make the Basic Control Engine load the modified script.
Method 1
Select Update.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 888
Method 2
When a configured event with a script action is triggered, the script can be executed in the following ways:
• In sequence
• In parallel (includes thread pool)
To configure an event with the type of script execution, see Step 3.2. Enter Advanced Event Specifications
(on page 877).
You can run scripts in parallel if they wait on Input/Output (I/O) operations for extended periods of time.
This will support running more threads.
You can run scripts in sequence if they interact with an external system that cannot perform multiple
operations in parallel.
The set of threads used to run scripts in parallel or in sequence are managed by a common thread
manager. The CE_MAX_THREADS global parameter controls the maximum number of threads the thread
manager will use to run scripts, and decides when and if the script will be run.
• If there are fewer than CE_MAX_THREADS scripts currently running in parallel, the script will be run
immediately.
• If there are CE_MAX_THREADS or more scripts running in parallel, the script is discarded and a Too
many executing threads, action ignored message is logged to the status log.
• If there is another script running in sequence for a configured event and there are fewer actions
queued than the maximum queue size of the configured event, the script is queued.
• If there is no other script running in sequence for a configured event and there are fewer than
CE_MAX_THREADS scripts currently running in sequence, the script is run immediately.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 889
• If as many actions as the maximum queue size of the configured event are queued, the script
running in sequence is discarded and an alarm is generated and/or a message is logged to the
status log depending on the configuration of the event.
• If there is no other script running in sequence for a configured event and there are
CE_MAX_THREADS or more scripts currently running in sequence, the script is discarded and a Too
many executing threads, action ignored message is logged to the status log.
You can run a CPU-intensive script in parallel in a set of threads managed by a thread pool. The thread
pool should be sized so that there is one thread per logical processor in the system. This helps minimize
the time spent in switching CPU cores.
Note:
For cores that support hyperthreading, the number of logical processors is twice the number of
cores. For cores that do not support hyperthreading, the number of logical processors is equal to
the number of cores.
The CE_POOL_THREADS global parameter controls the maximum size of the thread pool, and also
decides when the script will be run.
• If there are fewer than CE_POOL_THREADS scripts currently running, the script will be run
immediately.
• If there are CE_POOL_THREADS or more scripts running, the script is queued.
Notes
• The thread pool size ranges between 0 and 200, and when calculated automatically will be twice
the number of logical processors in the system. When the size is set to 0, its size is automatically
calculated.
• CE_MAX_THREADS should be set to the expected number of simultaneous events. The actions of
the surplus events triggered will be ignored.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 890
• The maximum number of script actions that can run simultaneously is CE_MAX_THREADS +
CE_POOL_THREADS.
• BCL and .NET scripts share the same set of threads.
• When a script is started, it can run in any available thread.
• The CE_THREAD_TIMEOUT global parameter controls the number of seconds a thread managed
for parallel and sequential events will be idle before it is freed. This period should be long
enough so that regularly executed events do not need to create threads, but short enough so that
infrequent events do not cause the event manager to consume an abnormal amount of memory for
extended periods of time.
• The CE_MIN_STANDBY_THREAD_COUNT global parameter controls the number of threads allowed
by the event manager to be idle indefinitely. Threads that are idle for CE_THREAD_TIMEOUT
seconds will not be freed if there are CE_MIN_STANDBY_THREAD_COUNT or fewer threads in the
idle state.
In BCL, you can declare public or private variables at the module level, outside of any function. In .NET, you
can declare static or instance variables at the class level, outside of any function.
The following table provides the differences between BCL and .NET variables:
Lifetime of Multi-thread
Variable Scope of variable Shared
variable value ing issues
BCL public Global, visible to all script files Forever, across event in Yes Yes
(modules) stances
BCL private Visible only to this script file Forever, across event in Yes Yes
(module) stances
.NET class sta Visible only to this script file (Ap Forever, across event in Yes Yes
tic pDomain) stances
.NET class in Visible only to this script file (Ap Forever, across event in No No
stance pDomain) stances
• Scope of variable - Denotes the visibility of the variable to other script files, such as modules and
AppDomains.
• Lifetime of variable value - Denotes how long the value of a variable will last.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 891
• Shared - Denotes if two or more event instances will share the value of the variable.
• Multi-threading issues - Denotes if multi-threading issues occur when multiple instances run at the
same time.
To create this Action, enter the following information in the New Action dialog box:
1 Point ID
Popup Menu but Displays Popup menu to create a new point, browse for or edit an ex
ton isting point.
2 Val
ue
A Source Transition Set action sets the value of the point in the Point ID field to the value of the point in
the Source field.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 892
To create this Action, enter the following information in the New Action dialog box:
1 Point ID
Popup Menu but Displays Popup menu to create a new point, browse for or edit an ex
ton isting point.
2 Source
Note:
If the source point is the same as the point that triggered the event, the old value of the source
point will be copied to the point ID. This lets you save a point value before it is updated. If you
want to copy the new value of the point, use the Transition Set (on page 892) action.
A Transition Set action sets the value of the point in the Point ID to the value of the point in the Point ID
field of the Event associated with this Action.
To create this Action, enter the following information in the New Action dialog box
Basic Control Engine and Scripting Reference | 5 - Event Editor | 893
Point ID
ID of a point that will be updated with the value of an associated event's point ID. Valid entries are either a
device or global point ID
Popup Menu but Displays Popup menu to create a new point, browse for or edit an ex
ton isting point.
1. Make sure you are displaying the Event Editor By Event. (on page 859)
2. Select an event in the Event list.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 894
Field Description
Displays popup menu to create a new action, browse for or edit an existing
action.
Log Checked Logs the event and action to the Database Logger
Flag Event Management log.
Tip:
You can also use the Toggle Logging button on the Event Editor toolbar to enable or
disable logging the selected event and action.
Method 1
Method 2
Basic Control Engine and Scripting Reference | 5 - Event Editor | 897
Method 3
Select Modify Event on the Event Editor Edit menu (on page 858).
Method 4
A Modify Event dialog box opens with the configuration for the selected event.
3. Change any of the fields as you did when you created (on page 862) the event.
Method 1
Method 2
Method 3
Select Modify Acton on the Event Editor Edit menu (on page 858).
Method 4
A Modify Action dialog box opens with the configuration for the selected event.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 899
3. Change any of the fields as you did when you created (on page 879) the action.
Method 1
Method 2
Method 3
Select Copy Event on the Event Editor Edit menu (on page 858) .
Method 4
Selection Description
Add the associated ac Checked Copies all actions associated with the source event to the
tions? target event.
Unchecked Copies only the event configuration; does not copy associ
ated actions.
6. Click OK
The dialog box closes and the new Event appears on the Event list.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 901
Method 1
Method 2
Method 3
Basic Control Engine and Scripting Reference | 5 - Event Editor | 902
Method 4
Selection Description
Add the associated Checked Copies all events associated with the source action to the
events? target event.
Unchecked Copies only the action configuration; does not copy associ
ated events..
5. Click OK.
The dialog box closes and the new Action appears on the Action list.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 903
The Alarm Setup dialog box lets you filter the alarms to which the Event Manager will respond.
• Resource ID
• Alarm Class ID.
You can also have the Event Manager respond to either or both;
Important:
You must enter information in the Setup (on page 904) dialog box in order to receive alarm and/
or event data.
Do one of the following to open the Alarm Setup dialog box. The Setup dialog box opens when you use
any of these methods.
Method 1:
Method 2
Method 3
• Select Alarm Filter on the CIMPLICITY Event Editor Edit (on page 858) menu.
• Method 4
• Press Ctrl+F in the CIMPLICITY Event Editor.
Setup Options
Basic Control Engine and Scripting Reference | 5 - Event Editor | 905
Option Description
Resource ID Resource ID for which the Event Manager can receive information.
Alarm Class ID Alarm Class for which the Event Manager can receive information.
Option Description
Maximum Concurrent Specifies the maximum number of scripts that can execute concurrently with
Scripts in the Event Manager. When this limit is exceeded:
Maximum concurrent Specifies the maximum number of scripts that can execute concurrently with
scripts in the Event Manager.
Automatically calculate Sets the thread pool size to twice the number of logical processors in the sys
thread pool size tem.
Set thread pool size to Sets the thread pool size to a value between 0 and 200 that you enter.
If you enter a value that is greater than twice the number of logical proces
sors in the system, a warning is displayed.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 907
Option Description
.Net Assembly Refer Additional .NET assembly references for C# and VB .NET; additional refer
ences (on page 188) ences can be added or removed
Example 1
Enter and select the following to make the Event Manager receive all alarms and events.
A Alarms Check
B Events Check
Example 2
Enter and select the following to make the Event Manager receive only Event data for system resources.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 908
B Alarms Clear
Events Check
Example 3
C Alarms Check
D Events Check
Method 1
Basic Control Engine and Scripting Reference | 5 - Event Editor | 909
Method 2
a. Click the right mouse button in the Event Editor left pane.
b. Select Field Chooser on the popup menu.
Method 3
Select Field Chooser on the Event Editor View menu (on page 859) .
Result: The Field Chooser dialog box for the Event field columns opens.
Fea Description
ture
Basic Control Engine and Scripting Reference | 5 - Event Editor | 910
Lists Avail Event fields that are not currently being displayed.
able
Field
Dis Event fields that are currently being displayed. The fields display in columns.
play Columns go from left to right, starting at the top of the list and moving down.
Fields
Fields Selections correspond to the selections in the Event dialog boxes (on page 863).
But Add Add selected available fields to the Display Fields list
tons
Re Stops displaying selected fields by sending them back to the Available Field list.
move
Move Each click moves a selected field one column to the left. Note: Event ID is always
Up the farthest left.
Move Each click moves a selected field one column to the right.
Down
Method 1
Method 2
a. Click the right mouse button in the Event Editor left pane.
b. Select Field Chooser on the popup menu.
Method 3
Select Field Chooser on the Event Editor View menu (on page 859).
Result: The Field Chooser dialog box for the Action field columns opens.
Fea Description
ture
Lists Avail Action fields that are not currently being displayed.
able
Field
Dis Action fields that are currently being displayed. The fields display in columns.
play Columns go from left to right, starting at the top of the list and moving down.
Fields
Fields Selections correspond to the selections in the Action dialog boxes (on page 879).
But Add Add selected available fields to the Display Fields list
tons
Re Stops displaying selected fields by sending them back to the Available Field list.
move
Move Each click moves a selected field one column to the left. Note: Action ID is al
Up ways the farthest left.
Move Each click moves a selected field one column to the right.
Down
Method 1
Method 2
Method 3
Basic Control Engine and Scripting Reference | 5 - Event Editor | 914
Select Search on the Event Editor View menu (on page 859).
Method 4
Field Description
A Event ID ID or partial ID with a * wild card of the event or events you want to find.
4. Click OK.
Tip:
Leave the fields blank in the Event search dialog box to re-display all of the events in the Event
Editor after you have searched for selected events.
Method 1
Method 2
Method 3
Select Search on the Event Editor View menu (on page 859).
Method 4
Field Description
A Action ID ID or partial ID with a * wild card of the action or actions you want to find.
4. Click OK.
Tip:
Leave the fields blank in the Event search dialog box to re-display all of the actions in the Event
Editor after you have searched for selected actions.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 917
• Make entries in the Global Parameters file to change the maximum number of scripts that can run
simultaneously, or specify how long an idle thread should remain active.
CE_MAX_THREADS
CE_THREAD_TIMEOUT
• Make entries in the Basic Control Engine points file to cache frequently used points.
Each time a script uses a point, it must retrieve the point's definition. You can use the bce_points.cfg
file to pre-load point definitions into the Basic Control Engine for the Event Manager. This can provide a
performance boost.
The bce_points.cfg file is an ASCII file that needs to be located in your project's Data directory.
2. Type cd %SITE_ROOT%\data.
3. Type notepad bce_points.cfg.
Basic Control Engine and Scripting Reference | 5 - Event Editor | 918
4. Enter all the point IDs that you want to cache, one per line in the file.
5. Exit Notepad and save the file.
6. Stop and restart your project to have the caching take effect.
Chapter 6. Action Calendar
About the Action Calendar
Action Calendar is a feature added to CIMPLICITY, which allows you to dynamically create, maintain, and
execute a calendar schedule of manufacturing events and associated actions. Turn on lights, heat, and
equipment based on a schedule, which you configure and maintain through simple point and click actions.
This Application Module is fully integrated with CIMPLICITY software's Base System functionality to
enhance its already powerful monitoring capability in a full range of computer integrated manufacturing
environments. Designed from the ground up as a true client / server architecture, CIMPLICITY has always
provided more than simple monitoring and control. CIMPLICITY software's flexible system architecture
and modular design also allows for easy add-on of functionality. When you take on the challenge of an
enterprise wide system, you face challenges which simple MMI systems just cannot handle. With the
CIMPLICITY Action Calendar you can coordinate plant operations on a timed basis.
The Action Calendar Application Module, which interfaces with the Base System Point Management
facility and User Interface, allows you to easily schedule the execution events in your system through a
simple calendar based user interface. Configured events can drive real world I/O through CIMPLICITY
and turn equipment/utilities on and off based on production schedules. In addition internal events can be
activated to trigger:
• Data collection
• Data logging
• Report generation
• Execution of scripts or programs.
Managing events and activities associated with your production schedule are made easy with the
CIMPLICITY Action Calendar.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 920
The Action Calendar option gives you, the system administrator, the ability to build a set of automated
events that can be applied in one area of or throughout your plant. You can invoke events with associated
actions at specific times of a day and during day types (for example, weekdays) that you define.
An action can be any action supported by the Event Editor. For example an action can set a point,
generate an alarm, download a recipe or even run a user written Basic Script.
Note:
The Action Calendar schedules events with associated actions. It is not designed for Production
scheduling.
1. Graphical User Interface (on page 921) (GUI) allows users to interactively configure and view
schedule information.
2. Scheduler (on page 924) is responsible for ensuring that your operations are initiated at the
appropriate times.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 921
The Graphical User Interface, which has a familiar electronic day planner appearance:
◦ Provides the screens needed for you to configure all Calendar data, including areas, event
actions, and schedules.
◦ Lets you project what events are scheduled either today or for any date in the future, based
on existing Action Calendar configuration data.
◦ Lets you specify exceptions to these standard schedules, as needed, to meet production
needs for a specific date. These schedule overrides can be used to completely alter a day's
schedule (for example, to accommodate holidays), or to modify, add, or skip a single event
on a specified date.
1. If you want to schedule an event to execute every minute, use the CIMPLICITY Event Editor. The
Event Editor provides an easier way than the Action Calendar to schedule these types of repetitive
events.
2. If you want to schedule an event in less than one-second real time intervals, use a PLC or a
CIMPLICITY PC control to perform the real time control. In the Action Calendar, events can be
scheduled to the second. On a normally loaded system, your event will execute within +1 second of
the target time.
Create and define Areas with scheduled events (on page 922)
The Action Calendar lets you divide your facility into any number of areas, each with its own unique set of
events and schedules.
An Area defines specific locations, stations, or work units with which schedule information may be
associated. Examples of areas are
• ASSEMBLY
• Inspection
• Factory
Each area has its own configuration data. One immediate benefit of this feature is that users only need
to be familiar with their own area, and do not need to understand the entire plant's operation in order to
create or modify schedules. Of course, you, the system administrator, may also define plant wide areas, to
schedule events for the entire factory.
For example, you may dedicate an area to factory_lights. You can then create a configuration that will
instruct the Action Calendar to turn the lights on and off throughout the plant, at the times you designate.
• Events
• Day types with associated weekdays
• Schedules for the day types
Event Definitions
An Event definition (on page 926) provides a list of actions to perform such as Setpoints, and assigns a
unique event name to the association.
Example
To define the event MAIN_LIGHTS_ON, associate the CIMPLICITY Point ID MASTER_LIGHTS with a value
of one (1).
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 923
Day type definitions (on page 948) (or classifications) identify the different types of days are required to
accommodate the various production needs of the plant.
Area A
Area B
• Workday. Tuesday
• Maintenance. Friday
Schedules
A Schedule definition (on page 961) specifies the sequence and timing of events associated with the
area. All times may be specified to the nearest second on a 24-hour clock.
Example
The schedule for a FACTORY area specifies the event MAIN_LIGHTS_ON to occur at 6:00:00am.
Projected Schedules
Projected schedules (on page 961) display a time ordered list of events that are scheduled to occur on a
selected date.
In addition to building base schedules for each area, the Graphical User Interface provides you with the
mechanism to:
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 924
• Project what an area's schedule will look like for today or for any date in the future.
• Override any or all events associated with that date with:
• Day type overrides completely replace the set of events associated with one-day type with the base
schedule associated with a new day type.
• Event overrides affect individual events, letting you dynamically add, skip, or reschedule events at
any time.
This day type will be either the standard day type for the area or, if the day type has been
overridden, the new requested day type.
3. Reads that day type's schedule, along with any event overrides specific to today's schedule, and
merges with all other area schedules for that day.
4. Begins processing of the events once the complete schedule has been built.
Important:
Some important notes about how the Action Calendar Scheduler deals with events include:
◦ If any events are being scheduled during the time that the Action Calendar is actually
generating the schedule, these events will be initiated, in order, immediately upon
completion of the schedule generation.
◦ There will be no predictable order for events that are scheduled to execute simultaneously.
◦ If a single event performs more than one action, the sequence of the actions is guaranteed.
When the Calendar determines that an event needs to be initiated, it sends an event request to the
Event Manager (EM) subsystem. If the event has been configured with logging enabled, then the
success or failure of the actions will be logged.
1. Areas
2. Events with associated actions
3. Day types with assigned days
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 925
4. Actual Schedules
Once you have completed the overall plan, you can then:
Setting up Areas
Setting up Areas
When setting up your configuration you need to decide what are the:
You may want to begin planning by defining what appear to be obvious areas. As you continue planning
your configuration, you may see different relationships that prompt you to redefine your original areas.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 926
• Physically independent areas that have their own repetitive actions in machinery or peripheral
equipment, for example, a raw material cutting area that has its own light source.
• Logical areas, each with its scheduling needs, for example, reporting that is due every Friday.
Note:
The Action Calendar lets you handle your entire facility through a single area. In fact, Action
Calendar provides a pre-configured area, Plant that you can use as a starting point.
A plant wide area may be appropriate for company wide actions. However, most likely you will also need
to define more specific areas.
Once you have your initially defined areas, review each area to determine the types of operations that
occur in that area. There may be one or more events associated with each operation and one or more
actions associated with each event.
Each operation typically corresponds to something that is controllable through a CIMPLICITY point.
In most cases, there will be a set of two or more events (or ultimately, event point values) that correspond
with the operation point referenced in your configuration.
Note:
The Action Calendar lets you configure events for points which have been defined but which have
not been incorporated into the runtime system via a Configuration Update operation.
This enables you to set up a system for a future point configuration modification that will make these
events valid at a future date. Until that time, these events will be ignored by the Calendar, and messages
will be logged whenever an attempt is made to incorporate these events into a day's schedule.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 927
Example
A machine requires a light to be on for part of the day and to be off for the remainder.
unit_on
unit_off .
The Action Calendar will turn the machine light on and off, based on the times for which you
schedule unit_on and unit_off.
You may also have a series of actions that involve turning off the machine light, which you can call
up through the use of a script.
Having determined at least the initial set of events that will be required within an area, you can begin to
determine when these events may be invoked. As you review the day types, you may need to redefine
some areas.
The Action Calendar carries out events that you schedule for day types.
You may:
• Require multiple standard day types to handle the scheduling requirements such as weekdays,
weekends and holidays.
• Configure additional reserved day types for a specific area because your plant has other conditions,
which you must accommodate (for example, extended production days or shutdown).
• Configure a day type that has no events. Any days of the week assigned to that day type will have
no events scheduled for that area.
However, within one area, you can only assign a specific day of the week, for example, Friday, to one day
type.
Example
1. Define Weekdays as a day type to which you assign Monday through Friday
2. Decide that the area has additional events on Friday and, therefore, define Friday as a day type. You
assign Friday to it, thereby removing Friday from Weekdays
3. Do define Saturday and Sunday as None. "None" has no schedule.
or
◦ Keep Friday as a day type in this area with a schedule that includes all the events for
Weekdays and Friday's additional events. Action See "Configuring the Action Calendar –
Copying Day Types"
Once you have designed and configured standard configuration data, you can analyze your system's
needs for any date specific overrides. Overrides supported by the Action Calendar can be divided into two
distinct categories:
They are:
Note:
Since the configuration screens are intended to accommodate standard, repetitive events,
exception conditions should not be included in the initial schedules. Instead, these can be more
appropriately handled through event or day type overrides, discussed in more detail below.
Day type overrides replace an entire day's schedule for the designated area.
This is particularly useful in the case of holidays or special events that fall on a day in which production
would normally run.
Example
If July 4 falls on a Monday, which is configured as a Weekday in the base configuration, you use a day type
override to define July 4 as a Holiday.
Another example is a case where, due to increased production demands, the plant decides to run extra
hours to meet these demands. If an alternate schedule and day type have been configured to meet these
additional production hours, you can use the alternate day type to override the standard day type.
This type of override is useful in situations when an operation is required on a given date where it
normally would not be part of that day's schedule.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 930
This override can be used to alter the time at which a scheduled event is initiated.
This override is useful in situations where a standard event is not desired on a particular date.
There are a number of rules associated with overrides, which are important to understand.
◦ Any override, which is scheduled for the current day, will be incorporated into the current
schedule immediately upon being requested by the user.
◦ If a day type override is configured, all existing event overrides for that same date and area
will be immediately deleted, so that an override is not inadvertently applied to an event for
which it was not intended.
◦ Initiate all day type and event overrides after you project a schedule for the date in question.
These overrides will be automatically reflected in the projected schedule being presented to
the user.
As you define an area's events and their scheduling requirements, including needs for overrides, you may
discover groups of events that are logically related and are, therefore, always processed as a set.
You can expedite scheduling the group at any time, by establishing an Initial/Offset Event relationship
among these events.
An Initial Event is one that, whenever scheduled, has one or more offset events scheduled static to it at
fixed time intervals.
An offset event occurs static to when the initial event occurs. For example, it may occur one minute
before the initial event, or three hours after.
Establishing an initial/offset event relationship has the following impact on a schedule, no matter whether
you are adding it to the base schedule or as an event type override.
• Adding an unscheduled initial event to a schedule causes all the initial event's offset events to be
scheduled automatically.
• Rescheduling an initial event to a new time causes all the initial event's offset events to be
rescheduled automatically, so that the fixed time intervals between all the events in the set are
preserved.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 931
• Skipping or deleting an initial event, which would otherwise be initiated, causes all the initial event's
offset events to be skipped or deleted automatically.
• Changing the interval of the offset events causes all instances of the scheduled event/offsets to
change automatically.
You uniquely define Initial/offset event relationships for each area. Within an area, the relationships you
define apply across schedules for all day types.
If your plant has multiple shifts and 24 hour or nonstandard productions days, you may have to customize
the Action Calendar definitions of production shifts and days.
If your production facility operates in a multiple shift environment, it may be desirable from an operational
or maintenance viewpoint to configure your system so that each shift maintains its own schedule of
operations. Since an Action Calendar area may only be associated with a single day type at any given
time, you can define Pseudoareas within an Action Calendar.
A pseudoarea maintains its own event, day type, schedule, and day of the week definitions, while still
merging the individual schedules at runtime into a single plant wide schedule for any given day.
Within a given area, each Pseudoarea will really represent the same set of devices, locations, points, etc.,
but will only schedule events against these points during the respective timeframe of each shift.
Example
Pseudoareas could be "Assembly_Shift1" and "Assembly_Shift2", each with their own respective
schedules.
By default, Action Calendar is set up to display a production day as midnight this morning through
midnight tonight.
However, if your production facility has production days that run 24 hours, with one production shift
running through midnight, you may want to set up different parameters for your production day.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 932
If you prefer, you can configure the Action Calendar to adjust the 24hour-production period to a period
more desirable for your production facility.
As you configure schedules through the Action Calendar User Interface, the data is sent to the Action
Calendar, which stores it in a set of Action Calendar configuration files. The data is immediately
incorporated into the runtime system. This means that if you modify a day type schedule that is in effect
for the day, your modifications will be applied immediately to the currently running schedule.
When you have to add an event to the current day's schedule you may add it to the schedule using an Add
Event (on page 929) override.
In order to control production activities, a set of CIMPLICITY Point IDs is needed as follows:
Note:
: This example assumes that these points are already configured.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 934
1. PLANTWIDE
2. KILN_AREA
3. ASSEMBLY
Having defined three areas, we can now split the list of events (as indicated above) into area specific
events, and begin to configure each area.
PLANTWIDE Events
Beginning with the PLANTWIDE area, we can define the following events:
LIGHTS_ON_EV MAIN_ 1
LIGHTS
LIGHTS_OFF_EV MAIN_ 0
LIGHTS
START_BREAK_EV BREAK_LIGHT 1
END_BREAK_EV BREAK_LIGHT 0
START_LUNCH_ BREAK_LIGHT 1
EV
END_LUNCH_EV BREAK_LIGHT 0
KILN_ONLY Events
KILN_ON_EV KILN_ENABLED 1
KILN_OFF_EV KILN_ENABLED 0
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 935
CONVEYOR_ON_EV ASSY_CONVEY 1
CONVEYOR_OFF_ ASSY_CONVEY 0
EV
Having defined events for each area, we can now create sets of events that are done in a group. Creating
events offset from a base event by a static time does this.
Beginning with the PLANTWIDE area, we can define the following offset events:
There is one set of day types for the PLANTWIDE Area and one for the KILN_ONLY and ASSEMBLY areas.
The day types associated with both the KILN_ONLY and ASSEMBLY areas is:
The base schedule associated with the ASSEMBLY area would be:
Finally, the days of the week are assigned to day types for each area as follows:
• Define and automatically execute events in your plant, based on a standard schedule.
• Project a schedule of automated events for any day in the future
• Add, delete or reschedule events for a specific day.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 939
Once you have planned your areas and events, entering information into the Action Calendar is very
straightforward.
Note: If the icon does not appear in the Workbench left pane, you may need to enable the Action
Calendar optionin your project.
Either Or
Either Or
When you open the Action Calendar, you see the Action Calendar window that is divided into four
parts:
◦ Area
◦ Schedule Type
◦ Day Type Legend (on page 951)
◦ Weekday Schedule
Area
The Area box displays the current area being viewed, for example an area called Plant. Selecting
the new menu option accessed by clicking the right mouse button over the control or selecting the
Schedule Type
Day Type to configure and view the events for a type of day.
The Day Type Legend grid provides configuration and selection of the day type being viewed. Each
day type is assigned a color. Each day of the week (for example, Tuesday) displays the color of the
day type to which it is assigned.
When your Schedule Type is in Day Type mode, the Day Type Legend displays the:
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 941
When your Schedule Type is in Calendar mode, the Day Type Legend displays the:
Weekday Schedule
◦ Allows the configuration and viewing of the events configured for a day type or a projected
calendar schedule. You can add or remove events from the schedule.
◦ Tags the hour intervals for which events are scheduled. These tags remain stationary even
when you scroll the schedule up and down.
◦ Day Type schedules and select a day type in the Day Type Legend you will see the day type's
associated schedule in the schedule area.
◦ Calendar schedules you will see the schedule for the date that is selected on the calendar.
A Print Preview window opens displaying the document that will be printed.
A Windows Print Setup dialog box opens enabling you to set up the appropriate printer.
◦ Select Print.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 942
A Windows Print dialog box opens enabling you to enter print specifications and print the Action
Calendar schedule.
Note:
You can also click the Print button on the Action Calendar toolbar to open the Print dialog
box.
When you have completed planning each area's events, day types and schedules and are ready to enter
data into the Action Calendar, it is recommended that you enter information in the following order.
When you have completed planning each area's events, day types and schedules and are ready to enter
data into the Action Calendar, there is an efficient configuration sequence..
• Configure areas.
• Create day types.
• Assign days of the week to day types.
Area Configuration
Area Configuration
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 944
Method 1:
Method 2:
a. Click the Popup menu button , to the right of the Area dialog box.
b. Select New.
De A 40 character or less description used by you to provide more information about the
scrip area.
tion
Re The Resource ID to use for the area. Resources can be used to implement access control
source for the user interface. If you don't know yet what sort of security you will implement, se
ID lect the $SYSTEM resource. The configuration can always be changed later.
Edit Areas
2. Click the Popup menu button to the right of the Area field...
3. Select Edit.
Delete Areas
Important:
When an area is deleted, all of its day types, events and scheduling information are also
deleted.
Before you begin to schedule events, you need to define day types and assign days of the week to the day
types, for each area in your plant.
• Use immediately and to which you assign one or more days of the week (for example, Friday).
• Reserve for future use, by creating it but not assigning any days of the week to it.
These reserved day types can then have days of the week assigned to them whenever their schedules are
needed. This feature is particularly useful when one schedule replaces another for extended periods of
time.
Note:
If you only need to change the schedule for a few Thursdays, you can override each Thursday
that requires the long production run. You do this when the selected Schedule Type is in Calendar
mode.
Example
A cutting machine, in the Cutting Area, normally runs from 1:00pm through 4:00pm every Monday through
Friday.
• You schedule the Action Calendar to turn the machine on and off.
• The Cutting Area has already been defined.
Now you will create a day type in the Cutting Area called Weekdays and assign Monday through Friday to
that day type.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 947
• The plant manager tells you that every Thursday the cutting machine will have to run from Noon
through 6:00pm.
You create a day type called Long Run and assign Thursday to that day type. Every Thursday the Action
Calendar will run the Long Run Schedule. You do this when the Action Calendar is in Day Type mode.
Method 1
Method 2
Method 3
2. Enter the following information in the Day Type Properties dialog box:
Name The 16 character mixed case name for the day type.
De A 40 character or less description used by you to provide more information about the day
scrip type.
tion
Color A color used to represent the day type graphically in the week and month calendars.
Black is an invalid color, it is used to represent unassigned days.
You can:
3. Either:
◦ Click the standard color you want once. It will appear both in the grid and, for the
corresponding days, on the Weekday Title bar.
◦ Click a custom color or custom color square. The Color dialog box appears in which you can
create a custom color.
Method 1
Method 2:
A menu appears.
2. Select Edit.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 950
Using either method, the Day Type Properties dialog box appears for the Day Type that you want to edit.
You can copy an existing day type to a new day type within an area. To get the greatest benefit from this
feature, use it after you have created the original day type's entire schedule. When you do, you will copy
the entire schedule for the original day type to the new day type.
This feature is particularly useful when you want to create a new day type that contains a slightly modified
schedule from the original. You can then easily edit the new day type and assign days of the week to it
whenever the modified schedule is required.
todo:
To copy a day type:
1. Select the day type in the Day Type grid that you want to copy.
2. Click the right mouse button.
3. Select Copy from the menu that appears.
4. Type the name of the new day type in the New Day Type field.
5. Click OK.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 951
The Action Calendar creates a new day type with the name you specified and copies the original
day type's weekday schedule to the new day type.
Example
For example, you have a Weekday schedule for the spring and summer to start and stop a molding
machine that is in the Molding area . However, in the fall and winter you need to lengthen the
molding machine's run time on Wednesday and Thursday. You create a Long Run day type by
copying the Weekday schedule and editing it to extend the molding machine's runtime hours. When
the fall season begins, you can then assign Wednesday and Thursday to the Long Run day type.
Method 1:
Method 2:
Note:
A day type cannot be deleted when it has a day of the week assigned to it or is used as a
day type override.
Once you have created day types you can assign each day of the week that requires scheduling in an area
to its appropriate day type.
Example
For example, if you created a day type called Weekend and your plant adheres to a weekend schedule on
both Saturday and Sunday, you assign Saturday and Sunday to the Weekend day type.
Note:
In each area, you can only assign a day of the week (for example, Monday) to one day type.
However, you can have day types to which no days of the week are assigned
When you assign a day of the week to a day type, the day of the week (for example, Wed) displays in
its day type color. The Action Calendar displays days that you have not yet assigned in black. Once you
assign a day of the week to a day type you can assign it to a different day type. However, you cannot
change it back to being unassigned.
There are several methods to assign days of the week to day types. Following is a description of three
methods to assign days of the week to day types. You perform the first two in Day Type mode, the third in
Calendar mode
When you select Day Type mode in the Schedule Type group (above the Day Type Legend) you will see the
days Sun through Sat underneath the grid. (You will not see days of the month.). While in this mode you
can either call up the Day of Week Assignments dialog box or use a shortcut method..
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 953
todo:
To assign a day of the week to a Day Type:
1. Double click the appropriate day of the week from the row of days.
3. Click the right mouse button over the appropriate day of the week (for example Tue) from the row
of days.
A Popup menu lists all of the day types you configured for the area.
5. Click the right mouse button on the Day of the Month grid.
6. Select the Day Of Week Assignments menu option.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 954
Event Configuration
Event Configuration
In addition to creating day types for each area, you need to create the events that may be scheduled
during one or more day types in that area.
• Creating a new event, which can include a series of one or more actions that make up the event.
Actions include:
• Setpoints
• Alarm generation
• Scripts
• Recipes.
• Modifying an existing event
• Scheduling the event to occur at specific times in your schedule
• When necessary, changing the event. All of your changes affect all instances of the event in the
schedule.
• Creating offset events to expedite scheduling
• Before you begin scheduling, when the Schedule Type is in Day Type mode.
• While you are entering schedules and the Schedule Type is in Calendar mode.
a. Select the day type for which you are creating a schedule.
b. Select the time that the event will occur.
c. Click the right mouse button.
d. Select New from the popup menu.
e. Click the Popup Menu button to the right of the Event dialog box.
f. Select New.
When you complete any method, the General tab of the New Event Properties dialog box displays.
2. Use the side buttons on the General tab of the New Events Properties dialog box as follows:
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 956
Move Up / Move Down Position an Action item in the desired order of execu
tion.
The fields you fill in on the bottom of the General tab of the New Events Properties dialog box
depend on what action you select in the Action type field.
Ac The default action is Setpoint(,). This action appears in the Actions box the first time you
tion click New. You can configure that action or select another from the Action type. menu field.
type If you select another action the fields will change to reflect your choice.
Result: The General tab of the Event Properties dialog box appears, displaying the event you want
to modify.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 957
5. Use the buttons in the General tab of the Event Properties dialog box as follows:
The fields you fill in on the bottom of the Event Properties dialog box depend on what action you
select in the Action type field.
Ac If you did not select an action when you created the event, the default action, Setpoint(,), ap
tion pears in the Actions box the first time you click New.You can configure that action or select
type another from the Action type menu field. If you select another action the fields will change
to reflect your choice.
View Events
• At first, you will see a tree of the events along with scheduling information for each event..
• As you navigate through the tree, the hour Schedule part of the Action dialog box will update and
position the corresponding event.
• Events can be:
• Deleted
• Added
• Edited
• Scheduled
• Unscheduled
Note:
Events can only be deleted when they are not scheduled.
Offset Events allow you to specify a sequence of events that always occur in a certain order and at a
certain time.
Offset Events provide you with a way to expedite any rescheduling that occurs for the sequenced events
by reducing the number of calendar entries you have to make for each time the sequence is scheduled to
one (1). Needless to say this also minimizes the possibility for error.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 959
Important:
Offset events only support one level of offset. You cannot create an offset of an offset.
In the next example, the Kiln_Start event, which is an offset of Kiln_On cannot have an event that is
scheduled static to when it occurs. For example, Kiln_Preheat has to occur static to Kiln_On (20 minutes
prior). It cannot be configured to occur 10 minutes after Kiln_Start. Simply said, if you are a programmer—
offsets cannot be nested.
Example
For the sake of the example, say your factory has a Kiln. To start this Kiln, you must perform the following
events in the following order:
There are at least three methods to configure your schedule. However, the first is inefficient; the
second is problematic; the third is the best choice. See the example below.
Important:
Events with offset that wrap around the end of the day are not supported.
Example
You schedule an event for 11:59 PM on March 1 and an offset event of two minutes. The offset
event will be scheduled for 12:01 AM on March 1, NOT 12:01 AM on March 2.
Method 1. (Inefficient)
4. 7:00 – Kiln_Start
5. 7:10 – Kiln_Preheat
6. 7:30 – Kiln_On_Full
However, if you decide to start the Kiln 30 minutes earlier tomorrow, you need to reschedule three
events. Or if you decide that the preheat cycle can be decreased to 10 minutes, you need to move
all Kiln_On_Full events back 10 minutes in all of our schedules.
Method 2. (Problematic)
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 960
One possible offset configuration is, in the Offset tab of the Event Properties dialog box, to
configure the event:
7. Kiln_Start
8. Kiln_Preheat to happen 10 minutes later
9. Kiln_On_Full to be 30 minutes after Kiln_Start
This way when you schedule Kiln_Start the other two events are automatically scheduled.
The problem with this strategy is that you need the Kilns to be on at 7:30. If the preheat cycle is
decreased by 10 minutes you still need to change your schedules to move Kiln_Start forward .
The correct solution is illustrated below. In the Offset tab of the Event Properties dialog box,
configure the event:
Now if you need the kilns to be ready at 7:30 you simply place the Kiln_On event at 7:30.
5. Use the buttons in the Offset tab of the Event Properties dialog box as follows:
6. Enter the following information in the Offset tab of the Event Properties dialog box fields:
Off Time that should pass between the initial event and the offset event. If the offset event
set occurs before the initial event, make a negative entry; after, make a positive entry in an
HH:MM:SS format.
Schedules
Schedules
When you have defined a plant's areas and configured each area's day types, you are ready to configure
schedules.
Schedule
A schedule defines the series of activities that should occur on the days of the week that are assigned to
a day type.
If you created the area's events, you now only need to schedule them. If you did not create the events, you
can create them during scheduling.
First, when your Schedule Type is in Day Type mode, configure the basic day type schedules for each
area.
You configure a schedule of events for each day type. As a result, the Action Calendar will apply a day
type's schedule of events to each day of the week assigned to it
Later, you can switch your Schedule Type to Calendar mode and override any specific days or events,
where necessary.
Example
You assign Monday, Wednesday and Friday to a day type called Weekday. The Action Calendar will carry
out whatever schedule you create for the day type Weekday on Monday, Wednesday and Friday.
Before you get started, you may want to take a look at how you can adjust the Schedule View.
There are several options available to you when viewing the schedule. The options can be found on the
applications view menu, or by using the right mouse button on the schedule.
Option Description
Time In Allows you to specify the time interval to use in the day view. Valid intervals are 10, 15, 30 and
terval 60 minutes.
Time Toggles the time bar on the left of the schedule. The time bar allows you to rapidly find events.
Bar
24 Hour Enables you to switch back and forth between a 24 hour clock and a 12 hour AM/PM clock.
Clock
Show Lets you decide if offset events are viewed in the schedule.
Offset
Events
Day Lets you toggle back and forth between a day view and a list to display the scheduled events.
Sched If you find the day view becoming cluttered due to many events scheduled in the same time
ule slot, try the list view.
a. Click the Popup menu button to the right of the Browse button.
b. Select New from the popup menu.
c. Configure a new event. (on page 954)
guide:
Guideline: Scheduling Time
Actions cannot be scheduled to at the exact same time as the start of the day. This is because this
is the transition period from one day schedule to the next, and this time is ambiguous.
To help work with this limitation the start of day configuration has been modified so that the start
of the day can be configured with 1 minute resolution.
The start of the day should be selected to coincide with a time between shifts that
Midnight is often a good time for this, but for others 3:00 am may be better.
7. Select the scheduled event in the hour Schedule part of the Action Dialog box.
8. Press the Delete key.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 964
When you have completed configuring an area's basic schedule, you may have specific days or events that
will need to be changed during a specified calendar day.
Day Type Overrides allow you to change the day type for a specified calendar day. You might need to
make the change for a variety of reasons including holidays, long weekends, plant shutdowns or to
accommodate a longer production schedule.
Example
You normally run your cutting machine, in the Cutting Area, from 1:00pm through 4:00pm every Monday
through Friday. You schedule the Action Calendar to turn the machine on and off. You have all ready
defined the Cutting Area. Now you will create a day type in the Cutting Area called Weekdays and assign
Monday through Friday to that day type.
The plant manager tells you that beginning three weeks from the current week, the cutting machine will
have to run from noon through 6:00pm for four Thursdays in a row.
Anticipating these long runs you have created a day type called Long Run that turns the machine on
at noon and off at 6:00pm. You can immediately select the four involved Thursdays and override the
Weekdays day type with Long Run. On those four Thursdays the Action Calendar will follow the Long Run
schedule.
Note:
: Switch the Schedule Type to Calendar mode to assign Day Type Overrides.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 965
• Add
• Remove
• View
• Edit
• Delete
The Day Type Override dialog box tells you (read only) the:
New Day Type The day type to use instead of the currently assigned day
type
3. Click OK.
Event Overrides
Event Overrides
Event Overrides allow you to change an event n a schedule during a specific calendar day.
For example, you want to start production an hour early tomorrow or extend lunch by an hour. You use an
event override to make the change.
Note:
All event overrides are performed when the Action Calendar is in Calendar mode.
The Scheduled Event dialog box tells you (read only) the:
Skip Event Select to skip the event on the selected calendar day.
Resched Enter the time the event should occur on the selected calendar day. The event and
ule Time all of its offsets, if any, will be rescheduled.
Note:
When a day has event overrides, an asterisk is displayed next to the day in the month
calendar.
An O displays in the Schedule part of the Action Dialog box on the Events that are overridden.
The Scheduled Event dialog box associated with that event override appears.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 971
Security
Security
The Action Calendar provides access control to CIMPLICITY users logged into the system.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 972
Security is provided and can be enforced only when the project is running.
When the project is not running, any user may perform configuration from the configuration cabinet.
You, the system administrator, have assigned each CIMPLICITY user a role. Each role has a set of
privileges associated with it. When the Action Calendar is part of the project, the Calendar tab of the Role
Properties dialog box is displayed:
Choices for the Calendar tab of the Role Properties dialog box are:
Enabled A user will only be able to see areas whose Resource ID is assigned to the user
Example If you have schedules across several parts of your plant, you may wish to restrict the
paint booth operator from modifying the assembly schedule. Resource based security is the
way to do this.
Checked Users will be able to configure a schedule for any areas they can see.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 973
Important:
Day Start cannot be changed when the project is running. Changing the Day Start requires
that the application be exited.
The CalCfg.exe program takes command line options. These can be useful if you want to launch CalCfg
from a CimView screen.
Command Description
/ONLI Application can only run when CIMPLICITY project is active. This is useful if you want to re
NEONLY quire operators to be logged in and subject to role privileges.
Basic Control Engine and Scripting Reference | 6 - Action Calendar | 974
Command Description
/PROJECT Specifies the path to the project's file (e.g. C:\Program Files\Proficy\Proficy CIMPLICI
path TY\projects\cimpdemo\cimpdemo.gef) to use.
/READON Do not allow any configuration to be performed while the project is or is not running regard
LY less of Role configuration.