VISUAL QUICKPRO GUIDE FileMaker Pro 7 Advanced FOR WINDOWS AND MACINTOSH [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

VISUAL QUICKPRO GUIDE FileMaker Pro 7 Advanced FOR WINDOWS AND MACINTOSH [Electronic resources] - نسخه متنی

Cynthia L. Baron, Daniel Peck

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











Creating Custom Dialog Boxes


In the previous section "To control scripts with user input," we use the Show Custom Dialog step to give the user information and provide a choice between going forward or canceling. This method is a clean way to communicate simple information or prompt the user to choose between two opposite actions, but it's otherwise limited. If you need more complex user interaction, you can use the Show Custom Dialog script step to create a dialog box that can gather text input from the user into fields. A dialog box created using the Show Custom Dialog step can display up to three fields into which the user can enter values.

To illustrate how useful this method can be, we'll create a script that displays a dialog box prompting the user to enter any combination of the contents of the Last Name, City, and State fields to perform a find. The script will use global storage fields to capture the user input and set the find criteria from the contents of these global storage fields.

To customize a dialog box for user input



1 .

Choose File > Define >Database (Control+Shift+D/Command+Shift+D). When the Define Database dialog box appears, click the Fields tab.

2 .

Type gLastName in the Field Name box, choose Text (Control+T/Command+T) as the field type, and click Create.

3 .Click the Options button. When the Options dialog box appears, click the Storage tab. Click the Use global storage box (Figure 8.52). Click OK.

Figure 8.52. The global storage field gLastName will be used to get the user's input for the Find step.


4 .Highlight the gLastName field and click Duplicate twice. Rename one copy gCity. Click Change. Rename the second copy gState (Figure 8.53).

Figure 8.53. Duplicating the gLastName field is faster than creating the new field from scratch.


[View full size image]

5 .

Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S). When the Define Scripts dialog box appears, click New.

6 .

In the Edit Scripts dialog box, type a name for the script (we use Dialog Find).

7 .Scroll down to the Miscellaneous section in the step list on the left and double-click Show Custom Dialog (Figure 8.54).

Figure 8.54. The Show Custom Dialog step can be used for more than Yes/No choices.


[View full size image]

8 .In the Script Step Options section, click Specify.

9 .

The "Show Custom Dialog" Options dialog box opens with the General tab selected. Under Title, enter the text for the title of the dialog box (Figure 8.55).

Figure 8.55. Keep the dialog box title short and to the point.


10 .

Under Message, enter the text of the dialog box message. In our example, we give the user explicit instructions on how to use the dialog box (Figure 8.56).

Figure 8.56. The dialog message should contain a brief, clear explanation of the dialog box function.


11 .The default button names are already inserted for the three possible buttons. If you want to rename any of the buttons, highlight the text and type the new caption. If a button field is left blank, the button will not appear in the custom dialog box (Figure 8.57).

Figure 8.57. The button defaults can be customized to fit your needs.


12 .Click the Input Fields tab. Check "Show input field #1."

13 .

When the Specify Field dialog box appears, double-click the gLastName field.

14 .

In the Label input box, enter Last Name for the field label (Figure 8.58).

Figure 8.58. The label for an input field should match the standard field name, not the global storage field name, to avoid user confusion.


15 .Click the Show input field #2 check box. Repeat steps 1214 for the gCity field, and then again for the gState field.

16 .Click OK to return to the Edit Script dialog box. In the step window on the left scroll up to the Control section. Double- click If.

17 .

In the Script Step Options section, click Specify.

18 .When the Specify Calculation dialog box appears, click the View drop-down menu and scroll down to "Get functions." Click to select it and display the detailed Get functions list.

19 .In the list of Get functions, double-click the Get(LastMessageChoice) function (Figure 8.59).

Figure 8.59. This Get function returns 1 for the first button, 2 for the second button, and 3 for the third button in a custom dialog box.


[View full size image]

20 .In the formula box, click to the right of the status function and type =2 (Figure 8.60). Click OK.

Figure 8.60. If the user clicks the second button to cancel, Get(LastMessageChoice) will return the number 2, telling the script to Cancel.


[View full size image]

21 .

In the step window on the left, double-click Exit Script.

This If step looks at which button you clicked. If you chose the first button (Never Mind), it cancels the script without any action.

22 .To make sure that the next script steps are inserted after the If statement, click to select End If in the script-assembly list.

23 .

Under the Navigation category of the script step list on the left, double-click Enter Find Mode. Uncheck the Pause box (Figure 8.61).

Figure 8.61. Since this script will perform a new find, the Pause option is not needed.


[View full size image]

24 .We need to set the find criteria to use values only for the fields the user selects. In the step window on the left, double-click If.

25 .In the Script Step Options section, click Specify.

26 .When the Specify Calculation dialog box appears, double-click not in the Operators list (Figure 8.62).

Figure 8.62. Less frequently used operators are listed in a scrolling list, rather than as buttons.


27 .

In the function list, double-click IsEmpty.

28 .

Replace the text parameter by double-clicking gLastName in the field list (Figure 8.63). Click OK.

Figure 8.63. If no data is entered in the Last Name field, it will not be used in the find.


29 .In the step window on the left, scroll down to the Fields category and double-click Set Field. In the Script Step Options section, click the "Specify target field" check box.

30 .When the Specify Field dialog box appears, double-click to choose Last Name and return to the Edit Script dialog box.

31 .In Script Step Options, click the Calculated result: Specify button.

32 .When the Specify Calculation dialog box appears, double-click gLastName in the field list. Click OK (Figure 8.64).

Figure 8.64. The script enters the contents of the gLastName field in the Last Name field in Find mode.


If the user has typed anything into the Last Name section of the custom dialog box, this portion of the If step transfers it to the LastName field.

33 .Click the If step you created in step 24. Hold down the Shift key and then select the Set Field and End If steps. Click the Duplicate button twice (Figure 8.65).

Figure 8.65. Since the steps are just about the same for all three sections, using the Duplicate button is easier than creating the individual steps.


[View full size image]

34 .

Double-click the second of the three identical If steps. When the Specify Calculation dialog box appears, highlight "gLastName" after IsEmpty and double-click to replace it with gCity.

35 .

In the script-assembly list, double-click the second of the three Set Field steps. When the Specify Field dialog box appears, double-click the field City.

36 .In the Script Step Options section, click the Calculated result: Specify button. When the Specify Calculation dialog box appears, change the field from gLastName to gCity. Click OK.

37 .

Repeat steps 3436, changing the fields in the last If and Set Field steps to gState and State (Figure 8.66).

Figure 8.66. After you duplicate the steps, only the field specifications have to be changed.


38 .

To make sure that the next script steps are inserted after the If statement, click to select the last End If in the script-assembly list.

39 .In the step window on the left, scroll to the Found Sets category and double-click Perform Find (Figure 8.67).

Figure 8.67. The Perform Find step will use the data entered in the Custom Dialog box.


[View full size image]

Now we'll add another If section to alert the user if there are no records found. Otherwise, if no records are found, the user gets dumped into the generic No Records Found dialog box, which would be confusing.

40 .In the step window on the left, double-click Set Error Capture.

41 .In the step window on the left, scroll up to the Control category and double-click If. In the Script Step Options section, click the Specify button.

42 .When the Specify Calculation dialog box appears, click the View drop-down menu and scroll down to choose "Get functions."

43 .

In the list of Get functions, double-click Get(LastError).

44 .

Click after the close parentheses and type =401 (Figure 8.68). Click OK. If no records match the Find criteria, Error 401 is returned.

Figure 8.68. Error 401 is returned when no records match the find criteria.


45 .In the step window on the left, scroll down to the Miscellaneous category. Double-click Show Custom Dialog. In the Script Step Options section, click Specify.

46 .When the "Show Custom Dialog" Options dialog box appears, type a title for the dialog box in the Title input box. Add a message to be displayed when no records are found in the Message input box.

47 .

Delete "Cancel" from the Button 2 input box (Figure 8.69). Click OK to return to the Edit Script dialog box.

Figure 8.69. Since the user has only one option, only one button caption is required.


48 .

In the step window on the left, scroll up to the Found Sets category and double-click Show All Records.

If no records are found, this step will reset the database to display all records.

49 .

After the find is performed, we need to clear all three global fields. Click the last EndIf step in the script-assembly list. In the step window on the left, scroll up to the Fields category and double-click Set Field.

50 .In the Script Step Options section, click the "Specify target field" check box. When the Specify Field dialog box appears, double-click to choose gLastName.

51 .Click Calculated result: Specify button. When the Specify Calculation dialog box appears, click the quotes button in the Operators keypad (Figure 8.70). Click OK.

Figure 8.70. The empty quotes clear the contents of the field.


By putting nothing between the quotes, you erase whatever was in the global storage field.

52 .

Click the Set Field step you just created. Click Duplicate twice.

53 .Double-click the first of the new Set Field steps. When the Specify Field dialog box appears, change the field to gCity.

54 .Repeat step 52 to replace the last global field with gState (Figure 8.71). Click OK twice to finish.

Figure 8.71. All three global fields should be cleared before the script is done.


[View full size image]

When the script is run, the user will see a dialog box in which to enter the find requests (Figure 8.72). If the user clicks Do It, the script will perform the find. If no records are found, the second dialog box will tell the user so. At the end the script will clear the global fields so the data entered won't appear the next time the script is run.

Figure 8.72. The data entered in any of the fields will be used to create the find request.



Tips

Although they're terribly addictive, try to avoid the temptation of creating too many nested If statements. They become next to impossible to follow in the script editor, guaranteeing lots of wasted time if you have to troubleshoot them.

As shown earlier in this section, clearing a global field after you use it in a script is a good housekeeping step. If you create a database with many global fields, you might consider creating a separate table for them. Then you can create a single script to clear all your globals when necessary.

The first button in a Show Custom Dialog dialog box is always the default choice. If you press Enter instead of clicking a button when the message box is displayed, the Get(LastMessageChoice) function will react as if you chose the default button. Protect your users from unpleasant accidents by choosing the least destructive option as the default choice.


/ 227