Can I create custom dialogs and other interactive user input controls in SVB?
The Statistica Visual Basic environment provides all tools to program complete custom user interfaces. A powerful User-Dialog Editor is included to design dialoges using simple operations such as dragging buttons to the desired locations. Unlike in Microsoft Visual Basic, the user-defined dialoges will be stored along with the program code as data of type UserDialog. This method of creating dialoges makes it possible for you to create sophisticated user interfaces that can easily be edited in textual form; also, by defining the entire dialog as a variable, you can completely define dialoges inside subroutines, which can be freely moved around the program.
However, user-defined dialoges designed in the Statistica Visual Basic environment cannot be ported directly to Microsoft Visual Basic, which uses a form-based method of creating dialoges. This is not a serious limitation, though, but rather a design issue, in the sense that you should decide which environment you prefer before embarking on the development of a complex program with extensive custom (user-defined) dialoges. For example, if you are already familiar with the Microsoft Visual Basic environment, or want to augment an existing program that was developed in that environment, there would be clear advantages in staying with that language. Most Statistica Visual Basic functions are accessible from the Visual Basic environments in other applications (such as Microsoft Visual Basic, Microsoft Excel, Microsoft Word, etc.). Note that the ribbon bar is not customizable.
The following example illustrates how to create a simple dialog and "service" the user choices in this dialog. Start by creating a new macro: Select New from the File menu, select the Macro (SVB) Program tab, and create a new macro called SimpleDialog.
Click the OK button on the left side of this dialog, and then click in the upper-right corner of the window; an OK button will be inserted in that location.
By default, the new button is labeled Pushbutton1; to change that, double-click on it to display the Edit PushButton Properties dialog. Then edit the fields as follows:
Now close the Edit PushButton Properties dialog, and close the UserDialog Editor by clicking the
toolbar button in the UserDialog Editor. The SVB program will now contain the following code.
Sub Main
Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1
OKButton 300,14,70,21
CancelButton 300,42,70,21
PushButton 30,14,90,21,"&My Button!",.MyButton
End Dialog
Dim dlg As UserDialog
Dialog dlg
End Sub
Remember that to learn more about the different keywords and statements used in this program so far, you can always select the respective text, and then press F1 to display Statistica Help, which explains the syntax for the respective keyword or statement and provides simple examples on how to use them.
The simplest way to do this is to use the codes returned by the Dialog method; this method will return a 0 when Cancel is clicked, -1 for OK, and different integers greater than 0 to enumerate the other controls on the dialog. So in this example, clicking the My Button button would return a 1. Here is the program that would service all buttons.
Sub Main
Begin Dialog UserDialog 400,203 ' %GRID:10,7,1,1
OKButton 300,14,70,21
CancelButton 300,42,70,21
PushButton 30,14,90,21,"&My Button!",.MyButton
End Dialog
Dim dlg As UserDialog
Dim ReturnId As Integer
' NOTE: here we added parenthesis around the argument
' (dlg) for the Dialog method; this allows us to
' retrieve the return code from that method.
ReturnId = Dialog (dlg)
Select Case ReturnId
Case -1
MsgBox "The OK button was pressed"
Case 0 ' Cancel Button
MsgBox "The CANCEL button was pressed"
Case 1 ' The 'first' button on the Dialog,
MsgBox "The MY BUTTON was pressed"
End Select
End Sub
This program uses the standard Visual Basic Select Case statement to execute the code for the desired message box, based on the ID number returned by the Dialog method; you could of course also accomplish the same effect by using If ... Then ... Else statements. (All general Visual Basic statements are documented in the general SVB syntax help.)