Examples and References > Basic Dialog Box Script Example
  
Basic Dialog Box Script Example
The internal script stream below includes all the basics required for a simple dialog box:
^fname=
^columns=2#
^filepath=
^var=^31086
defstr 352,"J Doe|@Jane Doe\n"
addstr 352,"J Smith|@John Smith\n"
defstr 351,"|Test dialog box\n"
addstr 351,"\n"
addstr 351,"\n"
addstr 351,"Do you need the date? }^date %b\n"
addstr 351,"-\n"
addstr 351,"Your name }^fname %1..30s!352!\n"
addstr 351,"Load file }^filepath %1..999;20s!?11*.txt!\n"
addstr 351,"Number of columns }^columns %1..4r[1] [2] [3] [4]\n"
addstr 351,"\n"
addstr 351,"ALD version }^var %1.30t\n"
addstr 351,"-\n"addstr 351,"|%2..1e[OK] [Cancel]\n"
wdb 351
^wdb--
?=0,^wdb trun 0
Lines 1-3: At the start of the script, the variables, used in the main dialog box, are cleared first so that any previous information that may have been passed to them is deleted. However, the columns variable will be set with a value of 2. The button number 2, where this variable is used in the dialog box, will be pressed by default.
Line 4: The variable var is set to the value of ALD getvar 31086. This value of this variable is used later on in the script. Getvar 31086 obtains the current version of PTC ALD. For more information on getvars see the reference chapter System Variables and the macro getvar.
Lines 5-6: These two script lines define string 352 with options that will appear in a pull down menu. Menu options must be defined in the script before they are called in the dialog box field definition (see line 12). The text before the @ symbol is the value that will appear in the pull down menu. The text after the @ symbol will be inserted into the variable assigned to the dialog box field in which these options appear. The dialog box field and menu definitions must be assigned to a different string number to the menu options. In this example the field and menu are defined in string 351, while the options are specified in string 352.
Line 7: This line in the script defines the string 351, upon which the coding of the dialog will be based, hence defstr 351. The text in the line is the title of the dialog box. By default, the heading will be aligned to the left with the inclusion of the | character (other alignment methods are discussed later, for example || is the syntax with which to align text to the right). The \n syntax signifies the start of a new line.
Line 8: Inserts a new line.
Line 9: Inserts a new line.
Line 10: The %b syntax is the coding used to build a tick box. If the box is ticked by the user a value of 1 will be passed to the variable ^date, if not a value of 0 will be transmitted. The } character provides an alignment point. ALD looks for other } characters in the script and will align the dialog box content items they are associated with accordingly.
Line 11: Inserts a new line with a rule (denoted by the -character) across the width of the dialog box.
Line 12: The coding in this line is used to build an entry field. The coding %1..30s means that the field requires a minimum of one character to be entered, with the option to enter up to thirty. The content entered into the field by the end user is then passed to the variable ^fname to be used later. The !352! tells PTC ALD that a menu is attached to this edit field and refers PTC ALD to the menu string 352 (previously defined) which contains the information about the entries in that menu.
Line 13: This line defines another field of a different type, i.e. one in which the end user can select a file. The ;20 tells PTC ALD to just display twenty characters of the filename in the field, once the file has been selected. The !?11! is a built in special menu function that displays a file picker dialog. The added parameter .txt specifies that the user should only be permitted to search for .txt files when the file picker is invoked.
Line 14: The coding %1..4r tells PTC ALD to draw four push down buttons and gives each button a value, from 1 to 4. If button 1 is pressed then number 1 is passed to the variable ^columns and so on.
Line 15: Inserts a new line.
Line 16: This is a non-editable field. The variable ^var, which was set earlier in the script to the value of getvar 31086, is used here. This field is for information only.
Line 17: The code for a dialog's exit buttons is %2..1e. The number 2 represents the OK button and 1 the Cancel button. The e tells ALD that these are exit buttons. The values 1 or 2 are then automatically passed to a variable called ^wdb. If the user exits the dialog box via the ENTER button or CTRL+A, a 0 is returned.
Line 18: Inserts a new line with a rule (-) across the width of the dialog box.
Line 19: Draws the dialog box based on string 351 to the screen.
Line 20: This subtracts 1 from the contents of the variable.
Line 21: Tests if ^wdb is 0. If so stop all scripts and close the dialog without using any information in it, via the macro trun 0. The value of ^wdb would be 0 if the end user pressed the Cancel button to exit the dialog.
The above script will output this dialog box: