Create User Dialogs in Script
Question / Problem:
Do you have any information on creating a dialog box (User Dialog) in script with WinWrap?
Answer / Solution:
You can use the "User Dialog" feature of the WinWrap Script Editor to create more detailed user dialogs that you can pop up in an interactive module. You can create custom dialog titles, captions, radio buttons, check boxes, combo/list boxes, etc., and position each element as desired.
Creating a User Dialog
To create a user dialog:
- Place the cursor inside the script function/subroutine that requires the new dialog:
- From the WinWrap Script Editor menu, select Edit ¦ User Dialog...
- Use the editor to create and position elements on the dialog, then click Save and Exit.
A "Begin/End Dialog" block is automatically populated that defines the structure of the dialog:Begin Dialog UserDialog 400, 119, "MyDialog" ' %GRID:10,7,1,1 Text 20, 14, 310, 14, "This is my new dialog.", .Text1 OKButton 120, 84, 140, 21 Text 20, 35, 350, 14, "This is a check box:", .Text2 CheckBox 20, 56, 280, 21, "On/off", .CheckBox1 End Dialog
Plus a declaration in the format<Variable> As <DialogName>:
Dim dlg As UserDialog
And lastly, a call to that dialog via the VBScript "Dialog" function (similar to "MsgBox"), which opens the dialog at this point in script:
Dialog dlg
Editing an Existing User Dialog
To edit an existing user dialog:
- Highlight the "Begin/End Dialog" block for a specific script function:
- From the WinWrap Script Editor menu, select Edit ¦ User Dialog...
Obtaining User-Entered Data
To obtain data entered by the user, reference the object stated after each item in the Begin/End Dialog block. Each object returns a 0-based index.
For example, this dialog has a check box, radio button group and drop-down list box:
Dim aOptions(3) aOptions(0) = "Item A" aOptions(1) = "Item B" aOptions(2) = "Item C" aOptions(3) = "Item D" Begin Dialog UserDialog 470, 210, "MyDialog" ' %GRID:10,7,1,1 Text 20, 14, 310, 14, "This is my new dialog.", .Text1 CheckBox 20, 35, 280, 21, "Check box", .CheckBox1 OptionGroup .Group1 OptionButton 20, 63, 220, 21, "Option A", .OptionButton1 OptionButton 20, 91, 140, 14, "Option B", .OptionButton2 OptionButton 20, 112, 140, 14, "Option C", .OptionButton3 DropListBox 20, 140, 320, 21, aOptions(), .DropListBox1 OKButton 150, 182, 140, 21 End Dialog Dim dlg As UserDialog Dialog dlg
Get the selected check box value using:
Dim Index As Long
Index = dlg.CheckBox1
0 = Unchecked
1 = Checked
Get the selected radio button option using:
Dim Index As Long
Index = dlg.Group1
0 = Option A
1 = Option B
2 = Option C
Get the selected drop-down list box item using:
Dim Index As Long
Index = dlg.DropListBox1
0 = Item A
1 = Item B
2 = Item C
3 = Item D
Example
You can only define one user dialog per script function, but this example illustrates how you can dynamically change the text inside the user dialog based on conditions such as the module you are in. It features Document Routing and provides a way for the user to choose which module the Batch should go to next. This is only an example, not a recommended use case!
' Project Script Private Sub Batch_Close(ByVal pXRootFolder As CASCADELib.CscXFolder, _ ByVal CloseMode As CASCADELib.CscBatchCloseMode) 'Only execute this script for the main batch If CloseMode = CscBatchCloseFinal Then 'If we are in Document Review or Validation, pop up a user dialog If Project.ScriptExecutionMode = CscScriptModeDocumentReview Or _ Project.ScriptExecutionMode = CscScriptModeValidation Then Dim sText As String Dim sOption1 As String Dim sModuleID1 As String Dim sOption2 As String Dim sModuleID2 As String 'Define the UI and Module IDs associated with the user dialog, ' based on the module we are in Select Case Project.ScriptExecutionMode Case CscScriptModeDocumentReview sText = "After Server 2, where do you want this batch to go?" sOption1 = "Correction" sModuleID1 = "KTM.Correction" sOption2 = "Validation" sModuleID2 = "KTM.Validation" Case CscScriptModeValidation sText = "Where do you want this batch to go next?" sOption1 = "Document Review" sModuleID1 = "KTM.DocumentReview" sOption2 = "Export" sModuleID2 = "KC.Export" End Select 'Define the dialog Begin Dialog UserDialog 490,133,"Batch Routing" ' %GRID:10,7,1,1 OKButton 160,91,140,28 Text 20,7,450,14,sText,.Text1 OptionGroup .Group1 OptionButton 20, 28, 360, 14, sOption1, .OptionButton1 OptionButton 20, 56, 360, 14, sOption2, .OptionButton2 End Dialog 'Declare the dialog ( As ) Dim dlg As UserDialog 'Call the dialog Dialog dlg 'Set the correct module ID to an XValue based on user selection Select Case CStr(dlg.Group1) Case "0" 'First option selected pXRootFolder.XValues.Set("ROUTEBATCH",sModuleID1) Case "1" 'Second option selected pXRootFolder.XValues.Set("ROUTEBATCH",sModuleID2) End Select 'If we are in Validation, perform batch routing If Project.ScriptExecutionMode = CscScriptModeValidation Then If pXRootFolder.XValues.ItemExists("ROUTEBATCH") Then 'Route the batch based on the XValue, then delete the XValue pXRootFolder.XValues.Set("KTM_DOCUMENTROUTING_QUEUE_THISBATCH", _ pXRootFolder.XValues.ItemByName("ROUTEBATCH").Value) pXRootFolder.XValues.Delete("ROUTEBATCH") End If End If 'If we are closing Server 2, perform batch routing ElseIf Project.ScriptExecutionMode = CscScriptModeServer And _ Project.ScriptExecutionInstance = 2 Then If pXRootFolder.XValues.ItemExists("ROUTEBATCH") Then 'Route the batch based on the XValue, then delete the XValue pXRootFolder.XValues.Set("KTM_DOCUMENTROUTING_QUEUE_THISBATCH", _ pXRootFolder.XValues.ItemByName("ROUTEBATCH").Value) pXRootFolder.XValues.Delete("ROUTEBATCH") End If End If End If End Sub
Applies to:
Product | Version | Category |
---|---|---|
KTM | 6.3 | Scripting |
KTM | 6.2 | Scripting |