Topic
  • 4 replies
  • Latest Post - ‏2019-08-19T21:33:12Z by llandale
Christopher Cote
Christopher Cote
67 Posts

Pinned topic How to open dialog box from button click

‏2019-06-21T19:15:25Z |

I have a script that currently has a dialog with a button that, when clicked, starts running the main function of the script which is to loop through all Formal modules and counts the number of times each attribute (both object and module level) is used.  Now, though, I would like this button to display a selection dialog to allow the user to choose which attributes they want to search for.  I figured that I could create a function that calls this dialog, but it doesn't appear to be working.  Here is a segment of my code that I've written:

DB attrTypeBox = centered("Attribute");
string question = "Which attributes do you want displayed?";
string choices[] = {"Object", "Module"};
DBE attrPrint = label(attrTypeBox, "Attributes to print: ");
DBE attrRadio = radioBox(attrTypeBox, "", choices, 0);
string attrSelected = "";
void getData(DBE dbe) {
    //Perform main function to get the data needed for Excel worksheet.
}

void selAttrs(DBE btn) {
    infoBox("Hello");
    int i = get attrRadio;
    string attrSelected = choices[i];
    hide attrTypeBox;
    getData(btn);
}

void selectAttrs(DBE btn) {
    apply(attrTypeBox, "Display Attributes", selAttrs);
}

void buildDialog() {
    dbMain = create(SCRIPT_NAME, styleCentered|styleFixed);
    ...
    ...
    dbeRunBtn = button(dbMain, "Run", selectAttrs);
    dbeRunBtn->"top"->"inside"->dbeFrame;
    //The same is used for left, right and bottom to place the button}

Hopefully, this gives enough information to answer my question.  As it stands now, I never get the infoBox that says Hello, so I know I'm not getting into the selAttrs function.

  • Christopher Cote
    Christopher Cote
    67 Posts

    Re: How to open dialog box from button click

    ‏2019-06-24T14:53:23Z  

    Here's an update to my issue:  When I try to run this script now, I don't even get the original dialog box.  Instead, I get an error that says "incorrect arguments for function (apply)" on the code in line 20 above.  I don't understand why I'm getting this error since attrTypeBox is a global variable and the function selAttrs is just above.  So what am I doing wrong?

     

    Chris

  • smarti.sj
    smarti.sj
    32 Posts

    Re: How to open dialog box from button click

    ‏2019-06-25T12:52:41Z  

    Here's an update to my issue:  When I try to run this script now, I don't even get the original dialog box.  Instead, I get an error that says "incorrect arguments for function (apply)" on the code in line 20 above.  I don't understand why I'm getting this error since attrTypeBox is a global variable and the function selAttrs is just above.  So what am I doing wrong?

     

    Chris

    Hi Chris

     

    Bear with me still nursing my coffee.. is this what you are trying to do?

    DB dbMain
    DBE dbeRunBtn
    DB attrTypeBox = centered("Attribute");
    string question = "Which attributes do you want displayed?";
    string choices[] = {"Object", "Module"};
    DBE attrPrint = label(attrTypeBox, "Attributes to print: ");
    DBE attrRadio = radioBox(attrTypeBox, "", choices, 0);
    string attrSelected = "";

    void getData(DB dbe) {
        //Perform main function to get the data needed for Excel worksheet.
     ack "Done."
    }

    void selAttrs(DB btn) {
        infoBox("Hello");
        int i = get attrRadio;
        string attrSelected = choices[i];
        hide attrTypeBox;
        getData(btn);
    }

    void selectAttrs(DBE btn) {
        apply(attrTypeBox, "Display Attributes", selAttrs);
     show attrTypeBox
     }


        dbMain = create("My Box", styleCentered|styleFixed);

        dbeRunBtn = button(dbMain, "Run", selectAttrs);
     
     show dbMain
        //dbeRunBtn->"top"->"inside"->dbeFrame;
        //The same is used for left, right and bottom to place the button
     

    Sara

  • Christopher Cote
    Christopher Cote
    67 Posts

    Re: How to open dialog box from button click

    ‏2019-07-15T15:38:28Z  

    Yes, I believe that is what I'm trying to do.   I'm trying to have a button start the procedure instead of starting as soon as you select it from the menu.

     

    Chris

  • llandale
    llandale
    3088 Posts

    Re: How to open dialog box from button click

    ‏2019-08-19T21:33:12Z  

    Looking at the original code, showing lines 1 through 30.

    Line 20 "apply" should create an apply button at the bottom of the dialog.  This only makes sense while building the dialog, before it is "realize"d or "show"n.  Putting it into a callback doesn't make sense at all.  I'm surprised you don't get a run time error when you push the "Run" button.
    Line 27: change "selectAttrs" to "selAttrs" and it should work.

    Line 17 "selectAttrs" function is no longer needed.
    Line 7 "getData" doesn't need to have a parameter of type "DBE".  If you tried, you would find that "dbe == dbeRunBtn" is true; but I cannot see why that function would care about the button handle.

    -Louie