Dialog Boxes
Now that you've had the opportunity to use the InputBox command on occasion, have you ever looked at the screen display of an InputBox and wished you could change the size of the window, the location of the window, the location of the buttons inside the window, the size and number of the data entry fields, and so forth? Or just wished you could design an input window so that users could type in information and the macro could then use and play with what was typed in? There is a way to do this using dialog boxes--but be warned, the concepts are easy but the actual implementation can be extremely intimidating and aggravating.
Connexion comes with a dialog box editor, so you have the ability to create dialog boxes, add controls, and change the size and contents of a dialog box by using the mouse and menus, and the computer then takes care of figuring out the programming commands needed to achieve the look you want. You will usually find it easier to use that rather than manually create dialog boxes by hand, but you still need to know how the commands work in order to get data from the dialog box, and it can be helpful to know how to make some changes manually, so that you do not have to constantly open and close the dialog box editor. (It can be kind of like a refrigerator door in that regard.) Additionally, when you use the dialog box editor to make changes to existing dialog boxes, there may be some things it does not handle well, so it may accidentally wreck a dialog box that you've worked and worked on to get working just the way you want it to.
Here is the program code for a sample dialog box along the lines of what is used by the InputBox command. Note that this is completely non-functional as is, in order to better explain the various parts. Elements in angle brackets represent strings that can be included as a string or as plain text in quotation marks; square brackets designate optional elements.
Begin Dialog <name1> [x, y,] dx, dy, [<caption>] Text x, y, dx, dy, <text> TextBox x, y, dx, dy, .func1 OKButton x, y, dx, dy CancelButton x, y, dx, dy End Dialog Dim <name2> As <name1> z = Dialog(<name2>)
As you can see by comparing the first line to the second to last line, the <name> of the dialog is used later on to define the way the elements in the dialog box are referenced by the rest of the macro.
The <caption> is the title (if any) you want to appear in the blue bar at the top of the window; if this is left out, the default is "Softbridge Basic Language", as you've probably seen on message boxes.
Note that you generally must have at least one button showing on your dialog box, so that users have a way to exit from the dialog box. It does not have to be an OKButton or a CancelButton, but most dialog boxes will have one or the other or both of those two.
X = across, y = down. X = 1 is 1/4 the average width of a letter; since the font used does not have uniform-width letters, x = 2 is roughly the width of the letter "i", and x = 6 is roughly the width of the letter "m". Y = 1 is 1/8 of the height of a normal capital letter; y = 12 will give enough room to display the entirety of any capital letter or a letter with a tail. Dx and dy are the total width and height of the box/window being defined. In the Begin Dialog statement, x and y are optional; they define where on the screen to place the box. If they are left out, the default is a central location.
<Name2> is defined to be the results of dialog <name1>; because of this, <name2> is used by the rest of the macro to refer to the various elements of the dialog box rather than <name1>. That is, <name2>.<identifier> (for example, SampleDialog.MyTextBox) is a variable containing whatever was typed in the MyTextBox textbox of the SampleDialog dialog window.
The Dialog statement at the end is what actually displays the dialog box and waits for the user to do something; it closes the dialog box and the macro continues as soon as the user clicks any button. Z then reflects which button was pressed; -1 for an OKButton, 0 for a CancelButton, and 1 and higher for any user-defined buttons, in the order that the user-defined Button commands appear in the macro.
Continue on to part 2 of the lesson...
Return to Lesson #11.
Return to Main page.