Syntax Clipboard.SetText data$ [,format]
Description Copies the specified text string to the Clipboard.
Comments The data$ parameter specifies the text to be copied to the Clipboard. The format parameter, if specified, must be 1.
Example 'This example gets the contents of the Clipboard and uppercases it.
Sub Main()
If Not Clipboard.GetFormat(1) Then Exit Sub Clipboard.SetText UCase$(Clipboard.GetText(1)),1 End Sub
See Also Clipboard$ (statement); Clipboard.GetText (method); Clipboard$
(function).
Platform(s) Windows and Macintosh.
CLng (function)
Syntax CLng(expression)
Description Converts expression to a Long.
Comments This function accepts any expression convertible to a Long, including strings.
A runtime error is generated if expression is Null. Empty is treated as 0. The passed expression must be within the following range:
–2147483648 <= expression <= 2147483647
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).
Example 'This example displays the results for various conversions of i and j (note
'rounding).
Sub Main() i% = 100 j& = 123.666
MsgBox "The result is: " & CLng(i% * j&) 'Displays 12367.
MsgBox "The variant type is: " & Vartype(CLng(i%)) End Sub
See Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl
(function); CInt (function); CSng (function); CStr (function); CVar (function);
CVErr (function); Long (data type).
Platform(s) Windows and Macintosh.
Close (statement)
Syntax Close [[#] filenumber [,[#] filenumber]...]
Description Closes the specified files.
Comments If no arguments are specified, then all files are closed.
Example 'This example opens four files and closes them in various combinations.
Sub Main()
Open "test1" For Output As #1 Open "test2" For Output As #2 Open "test3" For Random As #3 Open "test4" For Binary As #4
MsgBox "The next available file number is :" & FreeFile()
Close #1 'Closes file 1 only.
Close #2, #3 'Closes files 2 and 3.
Close 'Closes all remaining files(4).
MsgBox "The next available file number is :" & FreeFile() End Sub
Chapter 2 ComboBox (statement) 107 See Also Open (statement); Reset (statement); End (statement).
Platform(s) Windows and Macintosh.
ComboBox (statement)
Syntax ComboBox X,Y,width,height,ArrayVariable,.Identifier
Description This statement defines a combo box within a dialog box template.
Comments When the dialog box is invoked, the combo box will be filled with the elements from the specified array variable.
This statement can only appear within a dialog box template (i.e., between the Begin Dialog and End Dialog statements).
The ComboBox statement requires the following parameters:
Parameter Description
X, Y Integer coordinates specifying the position of the control (in dialog units) relative to the upper left corner of the dialog box.
width, height Integer coordinates specifying the dimensions of the control in dialog units.
ArrayVariable Single-dimensioned array used to initialize the elements of the combo box. If this array has no dimensions, then the combo box will be initialized with no elements. A runtime error results if the specified array contains more than one dimension.
ArrayVariable can specify an array of any fundamental data type (structures are not allowed). Null and Empty values are treated as zero-length strings.
.Identifier Name by which this control can be referenced by statements in a dialog function (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 variable 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 dialog box is dismissed, the .Identifier variable is updated to contain the current value of the edit field.
Example 'This example creates a dialog box that allows the user to select a day of
'the week.
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"
Begin Dialog DaysDialogTemplate 16,32,124,96,"Days"
OKButton 76,8,40,14,.OK Text 8,10,39,8,"&Weekdays:"
ComboBox 8,20,60,72,days$,.Days End Dialog
Dim DaysDialog As DaysDialogTemplate DaysDialog.Days = "Tuesday"
r% = Dialog(DaysDialog)
MsgBox "You selected: " & DaysDialog.Days End Sub
See Also CancelButton (statement); CheckBox (statement); Dialog (function); Dialog
(statement); DropListBox (statement); GroupBox (statement); ListBox
(statement); OKButton (statement); OptionButton (statement); OptionGroup
(statement); Picture (statement); PushButton (statement); Text (statement);
TextBox (statement); Begin Dialog (statement), PictureButton (statement).
Platform(s) Windows and Macintosh.
ComboBoxEnabled (function)
Syntax ComboBoxEnabled(name$ | id)
Description Returns True if the specified combo box is enabled within the current window or dialog box; returns False otherwise.
Chapter 2 ComboBoxExists (function) 109 Comments The ComboBoxEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the combo box.
The name of a combo box is determined by scanning the window list looking for a text control with the given name that is immediately followed by a combo box. A runtime error is generated if a combo box with that name cannot be found within the active window.
id Integer specifying the ID of the combo box.
A runtime error is generated if the specified combo box does not exist.
Note: The ComboBoxEnabled function is used to determine whether a combo box is enabled in another application's dialog box. Use the DlgEnable function in dynamic dialog boxes.
Example 'This example checks to see whether a combo box is active. If it is, 'then it inserts some text into it.
Sub Main()
If ComboBoxEnabled("Filename:") Then
SelectComboBoxItem "Filename:","sample.txt"
End If
If ComboBoxEnabled(365) Then
SelectComboBoxItem 365,3 'Select the third item.
End If End Sub
See Also ComboBoxExists (function); GetComboBoxItem$ (function);
GetComboBoxItemCount (function); SelectComboBoxItem (statement).
Platform(s) Windows.
ComboBoxExists (function)
Syntax ComboBoxExists(name$ | id)
Description Returns True if the specified combo box exists within the current window or dialog box; returns False otherwise.
Comments The ComboBoxExists function takes the following parameters:
Parameter Description
name$ String containing the name of the combo box.
The name of a combo box is determined by scanning the window list looking for a text control with the given name that is immediately followed by a combo box. A runtime error is generated if a combo box with that name cannot be found within the active window.
id Integer specifying the ID of the combo box.
Note: The ComboBoxExists function is used to determine whether a combo box exists in another application's dialog box. There is no equivalent function for use with dynamic dialog boxes.
Example 'This code fragment checks to ensure that a combo box exists and is enabled
'before selecting the last item.
Sub Main()
If ComboBoxExists("Filename:") Then If ComboBoxEnabled("Filename:") Then
NumItems = GetComboBoxItemCount("Filename:") SelectComboBoxItem "Filename:",NumItems End If
End If End Sub
See Also ComboBoxEnabled (function); GetComboBoxItem$ (function);
GetComboBoxItemCount (function); SelectComboBoxItem (statement).
Platform(s) Windows.
Command, Command$ (functions)
Syntax Command[$][()]
Description Returns the argument from the command line used to start the application.
Comments Command$ returns a string, whereas Command returns a String variant.
Chapter 2 Comments (topic) 111 Example 'This example gets the command line and parameters, checks to see
whether
'the string "/s" is present, and displays the result.
Sub Main()
cmd$ = Command$
If (InStr(cmd$,"/s")) <> 0 Then
MsgBox "Application was started with the /s switch."
Else
MsgBox "Application was started without the /s switch."
End If
If cmd$ <> "" Then
MsgBox "The command line startup options were: " & cmd$
Else
MsgBox "No command line startup options were used!"
End If End Sub
See Also Environ, Environ$ (functions).
Platform(s) Windows and Macintosh.
Comments (topic)
Comments can be added to WM Basic code in the following manner:
All text between a single quotation mark and the end of the line is ignored:
MsgBox "Hello" 'Displays a message box.
The REM statement causes the compiler to ignore the entire line:
REM This is a comment.
WM Basic supports C-style multiline comment blocks /*...*/, as shown in the following example:
MsgBox "Before comment"
/* This stuff is all commented out.
This line, too, will be ignored.
This is the last line of the comment. */
MsgBox "After comment"
Note: C-style comments can be nested.