A Simple Message Box, and If..Then..End If Block

The following program illustrates various general features of the Visual Basic (VB, and SVB) language. This simple example program displays the following dialog box, and then one of two message boxes depending on the user's action.

 

In Statistica, select File New. In the Create New Document dialog box, select the Macro (SVB) Program tab and create a macro called Overview 1.

Sub Main

' Bring up a Message Box, with the Ok and Cancel

' and with the following text;

' note the continuation symbol _(underline) at the

' end of the first line, to allow the single statement

' to span two lines

To run this program, click the button on the toolbar, press F5, or select Run Macro from the Run menu.

This program consists only of the Main routine which is declared as Sub Main at the beginning, and terminated with an End Sub at the end. As you can see, all lines that start with a single quotation mark are interpreted as comments. You can break single commands into multiple lines by terminating each line with an underscore ("_"; which must be separated from the preceding text by a blank space). Note that at any time, to learn more about the different keywords and statements used in this program, you can highlight the respective text, and then press F1 to display the general SVB help text explaining the syntax for the respective keyword or statement and providing simple examples on how to use them.

The MsgBox function will display a standard MS Windows message box. To learn more about this function, highlight it, and then press F1 to display the help for that keyword (see MsgBox). As you can see, the function can be called with text that will be displayed inside the message box, a second (optional) parameter constant which determines whether an OK, Cancel and OK, etc. buttons are shown in the message box, and a third (optional) parameter (not used in this example) to set the title of the message box. The function will return a numeric constant (e.g., vbOK, vbCancel), and the If...Then...Else...End if block is constructed to detect whether the Ok or Cancel buttons where clicked.

See also, Advanced Conditional Expressions for additional information regarding If ... Then statements.