Comments Check box controls are either on or off, depending on the value of .Identifier.
This statement can only appear within a dialog box template (i.e., between the Begin Dialog and End Dialog statements).
The CheckBox 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.
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 (indicating that the Font control may be selected by pressing the F accelerator key).
.Identifier Name by which this control can be referenced by statements in a dialog function (such as DlgFocus and DlgEnable). This parameter also creates an integer variable whose value corresponds to the state of the check box (1 = checked; 0 = unchecked). This variable 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.
Example 'This example displays a dialog box with two check boxes in different states.
Sub Main()
Begin Dialog SaveOptionsTemplate 36,32,151,52,"Save"
GroupBox 4,4,84,40,"GroupBox"
Dim SaveOptions As SaveOptionsTemplate
SaveOptions.IncludeHeading = 1 'Check box initially on.
SaveOptions.ExpandKeywords = 0 'Check box initially off.
r% = Dialog(SaveOptions) If r% = -1 Then
MsgBox "OK was pressed."
End If End Sub
See Also CancelButton (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.
Platform Notes:
Windows
On Windows, accelerators are underlined, and the accelerator combination Alt+letter is used.
Platform Notes:
Macintosh
On the Macintosh, accelerators are normal in appearance, and the accelerator combination Command+letter is used.
CheckBoxEnabled (function)
Syntax CheckBoxEnabled(name$ | id)
Description Returns True if the specified check box within the current window is enabled;
returns False otherwise.
Comments The CheckBoxEnabled function takes the following parameters:
Parameter Description
name$ String containing the name of the check box.
id Integer specifying the ID of the check box.
When a check box is enabled, its state can be set using the SetCheckBox statement.
Note: The CheckBoxEnabled function is used to determine whether a check box is enabled in another application's dialog box. Use the DlgEnable function within dynamic dialog boxes.
Example 'This code checks to see whether a check box is enabled.
Sub Main()
If CheckBoxEnabled("Portrait") Then SetCheckBox "Portrait",1
End If End Sub
See Also CheckBoxExists (function); GetCheckBox (function); SetCheckBox
(statement).
Platform(s) Windows.
Chapter 2 CheckBoxExists (function) 99
CheckBoxExists (function)
Syntax CheckBoxExists(name$ | id)
Description Returns True if the specified check box exists within the current window;
returns False otherwise.
Comments The CheckBoxExists function takes the following parameters:
Parameter Description
name$ String containing the name of the check box.
id Integer specifying the ID of the check box.
Note: The CheckBoxExists function is used to determine whether a check 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 the Portrait check box is 'selectable before selecting it.
Sub Main()
If CheckBoxExists("Portrait") Then If CheckBoxEnabled("Portrait") Then
SetCheckBox "Portrait",1 End If
End If End Sub
See Also CheckBoxEnabled (function); GetCheckBox (function); SetCheckBox
(statement).
Platform(s) Windows.
Choose (function)
Syntax Choose(index,expression1,expression2,...,expression13)
Description Returns the expression at the specified index position.
Comments The index parameter specifies which expression is to be returned. If index is 1, then expression1 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 selected one.
Example 'This example assigns a variable of indeterminate type to a.
Sub Main()
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 Also Switch (function); IIf (function); If...Then...Else (statement);
Select...Case (statement).
Platform(s) Windows and Macintosh.
Chr, Chr$ (functions)
Syntax Chr[$](Code)
Description Returns the character whose value is Code.
Comments Code must be an Integer between 0 and 255.
Chr$ returns a string, whereas Chr returns a String variant.
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$(13) + Chr$(10) End-of-line (carriage return, linefeed) Chr$(26) End-of-file
Chr$(0) Null
Chapter 2 CInt (function) 101 Example Sub Main()
'Concatenates carriage return (13) and line feed (10) to CRLF$, 'then displays a multiple-line message using CRLF$ to separate lines.
crlf$ = Chr$(13) + Chr$ (10)
MsgBox "First line." & crlf$ & "Second line."
'Fills an array with the ASCII characters for ABC and displays their
'corresponding characters.
Dim a%(2) For i = 0 To 2
a%(i) = (65 + i) Next i
MsgBox "The first three elements of the array are: " & Chr$(a%(0))
& Chr$(a%(1)) & Chr$(a%(2)) End Sub
See Also Asc (function); Str, Str$ (functions).
Platform(s) Windows and Macintosh.
CInt (function)
Syntax CInt(expression)
Description Converts expression to an Integer.
Comments This function accepts any expression convertible to an Integer, including strings. A runtime error is generated if expression is Null. Empty is treated as 0. The passed numeric expression must be within the valid range for integers:
–32768 <= expression <= 32767
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 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).
Example 'This example demonstrates the various results of integer manipulation 'with CInt.
Sub Main()
'(1) Assigns i# to 100.55 and displays its integer representation (101).
i# = 100.55
MsgBox "The value of CInt(i) = " & CInt(i#)
'(2) Sets j# to 100.22 and displays the CInt representation (100).
j# = 100.22
MsgBox "The value of CInt(j) = " & CInt(j#)
'(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 Also CCur (function); CBool (function); CDate, CVDate (functions); CDbl
(function); CLng (function); CSng (function); CStr (function); CVar (function);
CVErr (function); Integer (data type).
Platform(s) Windows and Macintosh.
Clipboard$ (function)
Syntax Clipboard$[()]
Description Returns a String containing the contents of the Clipboard.
Comments If the Clipboard doesn't contain text or the Clipboard is empty, then a zero-length string is returned.
Example 'This example puts text on the Clipboard, displays it, clears the Clipboard,
'and displays the Clipboard again.
Const crlf = Chr$(13) + Chr$(10) Sub Main()
Clipboard$ "Hello out there!"
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
Clipboard.Clear
MsgBox "The text in the Clipboard is:" & crlf & Clipboard$
End Sub
Chapter 2 Clipboard$ (statement) 103 See Also Clipboard$ (statement); Clipboard.GetText (method); Clipboard.SetText
(method).
Platform(s) Windows and Macintosh.
Clipboard$ (statement)
Syntax Clipboard$ NewContent$
Description Copies NewContent$ into the Clipboard.
Example 'This example puts text on the Clipboard, displays it, clears the