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 dialog boxes using simple operations such as dragging buttons to the desired locations. Unlike in Microsoft Visual Basic, the user-defined dialog boxes will be stored along with the program code as data of type UserDialog. This method of creating dialog boxes makes it possible for you to create sophisticated user interfaces that can easily be edited in textual form; also, by defining the entire dialog box as a variable, you can completely define dialog boxes inside subroutines, which can be freely moved around the program.

However, user-defined dialog boxes designed in the Statistica Visual Basic environment cannot be ported directly to Microsoft Visual Basic, which uses a form-based method of creating dialog boxes. 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) dialog boxes. 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 box and "service" the user choices in this dialog box. 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.

Creating the dialog box
Next select Dialog Editor from the Tools menu or click the Dialog Editor toolbar button to display the UserDialog Editor.

Click the OK button on the left side of this dialog box, and then click in the upper-right corner of the window; an OK button will be inserted in that location.

Note: you can further edit the size and location of the OK button by clicking on it and dragging it to the desired location or resizing it. Repeat these steps for the Cancel button and for a user-defined button. The latter can be produced by clicking the blank button toolbar button on the lower-left of the toolbar on the UserDialog, and then clicking on the desired location in the dialog editor.

By default, the new button is labeled Pushbutton1; to change that, double-click on it to display the Edit PushButton Properties dialog box. Then edit the fields as follows:

Note: the Caption for the new button is &My Button! When you click Close, the actual caption of the button will change to My Button!, i.e., with the M underlined. Thus, M is the keyboard accelerator that will "click" this button. The other important information in the Edit PushButton Properties dialog is the ID of the button, entered into the Field box. The ID for this button is MyButton; this ID will be referenced throughout the SVB program to service the button, i.e., to identify when the button was pushed, and to respond inside the program.

Now close the Edit PushButton Properties dialog box, 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.

Servicing the new dialog, simple dialogs
If you run the program created thus far, the dialog we designed will be displayed on the screen; when you click on any button the program will terminate. The next task is to "connect" specific programming instructions to different user actions on the dialog. For example, you could display message boxes to indicate which button the user clicked.

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.)