INFORMIX SOFTWARE, INC., LENEXA, KS Wingz Technical Support Bulletin Number 004 Title: Common problems in dialog box creation Date: March 1, 1989 By using Hyperscript, Wingz' powerful development language, it is possible to create dialog boxes to enhance and customize the user interface. This ability greatly increases the users' control over his productive environment. There are some common problems encountered when creating and debugging your scripts to build dialog boxes. It is these problems that will be addressed in this bulletin. Error: "Nothing happens when I run the script." This condition may result from using either ctstring() or ctvalue() in your script after the dialog box has been closed. The following is an example: NEW MODAL DIALOG BOX AT (-1,-1) (3 inch,3 inch) ADD PUSH BUTTON "OK","Cancel" AT (.5 inch,2.5 inch) +(2 inch,.4 inch) DIALOG CANCEL PUSH BUTTON SELECT CONTROL 1 DIALOG DEFAULT PUSH BUTTON ADD RADIO BUTTON "Yes","No" AT (.1 inch,.1 inch) +(1.8 inch,1 inch) SHOW CONTROL TITLE "Are you Sure?" USE DIALOG BOX IF CTVALUE(3,0) = 1 QUIT NOW END IF Here is a breakdown of what happens when this script is executed. First, memory is allocated for the dialog box. Second, the push buttons are added to the box and given defaults. The two DEFAULT statements inherently have QUIT DIALOG BOX, the command to close the box and deallocate the memory. Third, the radio buttons are added to the dialog box and a title is added. Next, the dialog box is displayed with the USE DIALOG BOX command. At this point, execution of the script stops until the dialog box is closed. Once the box is closed, execution of the script resumes with the first command following USE DIALOG BOX. In the preceding example, control 3, the radio button, is being referenced in the IF statement after the USE DIALOG BOX command. Since the radio button was part of the dialog box, and the box has been closed and its memory deallocated, that control no longer exists in memory. The IF statement will always be false. To avoid this, assign the return of the control to a variable in a script attached to the "OK" button. Following is the correct procedure: DEFINE var,duit NEW MODAL DIALOG BOX AT (-1,-1) (3 inch,3 inch) ADD PUSH BUTTON "OK","Cancel" AT (.5 inch,2.5 inch) +(2 inch,.4 inch) DIALOG CANCEL PUSH BUTTON SELECT CONTROL 1 DIALOG DEFAULT PUSH BUTTON SCRIPT "filename:var = ctvalue(3,0) filename:duit = 1" ADD RADIO BUTTON "Yes","No" AT (.1 inch,.1 inch) +(1.8 inch,1 inch) SHOW CONTROL TITLE "Are you Sure?" duit = 0 USE DIALOG BOX IF duit IF var = 1 QUIT NOW END IF END IF The difference here is the script attached to the "OK" button. When the user clicks "OK", the ctvalue() of control 3 is assigned to the variable "var". "Var" is then used in the IF statement. Error: "Don't understand 'var' ". This error message occurs whey you first run the script that creates your dialog box. Then, when you click on "OK" in the error message dialog box, your dialog box displays. What is happening in this situation is that the variable has either not been defined or is not prefaced correctly. An example: SELECT CONTROL 1 DIALOG DEFAULT PUSH BUTTON SCRIPT "var = ctvalue(3,0) duit = 1" In the above excerpt, a script is being attached to the "OK" push button. The script being attached is considered by Wingz to be a separate script since "var" was defined in a separate,distinct script. This causes the inability to understand or find "var". What is required is to preface the variable name with the file name it was defined in. Assuming "filename" is the name of the file, here is the corrected excerpt: SELECT CONTROL 1 DIALOG DEFAULT PUSH BUTTON SCRIPT "filename:var = ctvalue(3,0) filename:duit = 1" This error will also occur if the variables were not defined properly. In this case, the proceeding line would need to be included in the script: DEFINE var,duit Error: "An action is always performed, even when clicking 'Cancel'." As explained in the first example in this bulletin, script execution resumes with the first command following USE DIALOG BOX. If a condition is not built to control script execution, then the commands, if there are any, will always be executed. Examine the following: DEFINE var,var1,duit NEW MODAL DIALOG BOX AT (-1,-1) (3 inch,3 inch) ADD PUSH BUTTON "OK","Cancel" AT (.5 inch,2.5 inch) +(2 inch,.4 inch) DIALOG CANCEL PUSH BUTTON SELECT CONTROL 1 DIALOG DEFAULT PUSH BUTTON SCRIPT "filename:var = ctvalue(3,1) filename:var1 =tvalue(3,2) filename:duit = 1" ADD CHECK BOX "One","Two" AT (.1 inch,.1 inch) +(1.8 inch,1 inch) SHOW CONTROL TITLE "Are you Sure?" duit = 0 USE DIALOG BOX IF duit IF var = 1 put "One" into a1 END IF IF var1 = 1 put "Two" into a2 END IF END IF Note: If you copy the script exactly as above and execute it, a worksheet must the be current window for proper execution. If a script window is the current window, there would not be an "a1" or an "a2" cell reference to put any text into. In the above example, a condition is created so that if the "Cancel" button is clicked, nothing will happen because "duit" will be zero. The commands following USE DIALOG BOX will only be executed if "duit" is one. "Duit" will only be set to one only if the "OK" button is clicked, causing the script attached to that button to be executed. Error: "Control numbers are referring to the wrong control. How are they numbered?" The control numbering scheme is really quite simple. The numbers start at one and increase by one with each control added. There is only one tricky part, and that is when push buttons are added. Take the following command line: ADD PUSH BUTTON "OK","Cancel" AT (.25 inch,2.5 inch) +(1.5 inch,.4inch) Even though the above command line is only one line, it adds two distinct controls, "OK" and "Cancel". Each of these buttons are considered by Wingz to be two separate controls, and are thus numbered individually. In any of the examples in this writing, adding the push buttons "OK" and "Cancel" are always the first controls added and are numbered one and two. Any subsequent control added would be numbered as three. In conclusion, Hyperscript gives Wingz a powerful tool that can be used to do anything from modifying the user interface to creating custom applications for a business. And with a little care taken during the creation stage, your scripts can be error free.