Dialog box to update DXL variable

I am new to all this DXL malarky and am finding dialog boxes to be most frustrating! I am trying to create a dialog box with a simple text entry that could be called each time the code loops. I want:

  • either the dialog box title or the text entry label to change each time the dialog box is displayed, being seeded from a DXL variable;
  • the text entry itself to be seeded with a DXL variable;
  • the dialog box to be closed and a DXL variable to be updated when the user clicks on the "OK" button (the only button).

How on earth do I achieve that?

Any and all help gratefully received.

Thanks.
Dangthrimble - Sat Mar 12 08:22:07 EST 2011

Re: Dialog box to update DXL variable
Mathias Mamsch - Sat Mar 12 16:32:48 EST 2011

You use global variables for the dialog return value and parameters for the changed dialog elements. For the OK and cancel/close you use different button callbacks, which will set the global variable. Example:
 

bool gbInputBoxOK_ = true 
 
string makeInputBox(string sTitle, string sLabel, string fldLabel, bool &bResult) {
    void cb_cancel(DB x) { gbInputBoxOK_ = false; hide x }
    void cb_ok    (DB x) { gbInputBoxOK_ = true ; hide x }
 
    DB diag = centered sTitle
    left diag
         // use the function parameters to create the contents of 
         // the dialog box
         label (diag, sLabel)  
         DBE fld = field (diag, fldLabel, "", 40, false) 
    close (diag, false, cb_cancel) 
    ok (diag, "Cancel", cb_cancel) // on cancel we will set gbInputBoxOK=false
    ok (diag, "OK", cb_ok)         // on OK we will set gbInputBoxOK = true
    block diag; release diag
    // so the developer calling this function won't need to know about the 
    // gbInputBoxOK_ variable, we pass the result by reference back to the caller
    bResult = gbInputBoxOK_        
    string sResult = get fld
    destroy diag
    if (gbInputBoxOK_) return sResult else return ""
}
 
int i; for i in 0:3 do { 
   bool bOK = false
   string val = makeInputBox("parameter " i "", "Please enter:", "I" i "", bOK) 
   if (bOK) print "The user entered: " val "\n" else print "Cancelled by user!\n"
}

 


Hope that helps, regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

Re: Dialog box to update DXL variable
Dangthrimble - Sat Mar 12 18:20:41 EST 2011

Mathias Mamsch - Sat Mar 12 16:32:48 EST 2011

You use global variables for the dialog return value and parameters for the changed dialog elements. For the OK and cancel/close you use different button callbacks, which will set the global variable. Example:
 

bool gbInputBoxOK_ = true 
 
string makeInputBox(string sTitle, string sLabel, string fldLabel, bool &bResult) {
    void cb_cancel(DB x) { gbInputBoxOK_ = false; hide x }
    void cb_ok    (DB x) { gbInputBoxOK_ = true ; hide x }
 
    DB diag = centered sTitle
    left diag
         // use the function parameters to create the contents of 
         // the dialog box
         label (diag, sLabel)  
         DBE fld = field (diag, fldLabel, "", 40, false) 
    close (diag, false, cb_cancel) 
    ok (diag, "Cancel", cb_cancel) // on cancel we will set gbInputBoxOK=false
    ok (diag, "OK", cb_ok)         // on OK we will set gbInputBoxOK = true
    block diag; release diag
    // so the developer calling this function won't need to know about the 
    // gbInputBoxOK_ variable, we pass the result by reference back to the caller
    bResult = gbInputBoxOK_        
    string sResult = get fld
    destroy diag
    if (gbInputBoxOK_) return sResult else return ""
}
 
int i; for i in 0:3 do { 
   bool bOK = false
   string val = makeInputBox("parameter " i "", "Please enter:", "I" i "", bOK) 
   if (bOK) print "The user entered: " val "\n" else print "Cancelled by user!\n"
}

 


Hope that helps, regards, Mathias

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

I am really impressed with the speed of the response there; if only all forums were as responsive! I will give your code a go on Monday. Thanks.

Jonathan

Re: Dialog box to update DXL variable
Dangthrimble - Mon Mar 14 09:28:46 EDT 2011

Used this within my script and it works a treat with minor tweaks to suit. Thanks again.