This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Pass variable to Macro from toolbar

I have far too many little macros in separate files and run by toolbar buttons.   I would like to add them all to one macro file and pass a variable in choosing the appropriate macro function to run.   Below is what I would like to do but PHP flavored. How can I produce this desired effect in Extra basic?

Passed in like: url.php?picMacro=2

<?php
$picMacro =  $_GET['name'];
switch ($.picMacro) {
  case "1":
    macroFunction1();
    break;
  case "2":
    macroFunction2();
    break;
  case "3":
    macroFunction3();
    break;
  default:
   someFunction();
}
?>

Labels:

Mainframe Access
Parents
  • Suggested Answer

    0  

    Hi Dave, 

    rather that "Run Macro" try "Run Application" (under miscellaneous) and then set the command line to execute

        "path\ebrun.exe" "path\the_macro.ebm" "the_macro_params"

    e.g.
        "C:\Program Files (x86)\Micro Focus\Reflection\ebrun.exe" "%Userprofile%\documents\Micro Focus\EXTRA!\My Macros\Hello.ebm" my function name

    in your macro you can retrieve the macro parameter(s) via the variable command$, in this case Command$ = "my function name"

    The big problem with this approach is that you can not call a "string",
    i.e.
        Call "Hello"

    will not work, it has to be

        Call Hello

    So you will need a Select Case block to call the various function/subroutines,

    e.g.

        Declare Function HELLO()

        Sub Main
            Select Case UCASE(Command$)
                Case "HELLO"
                    call Hello
                Case Else
                    Msgbox "Function not found"
            End Select
        End Sub

        Function HELLO()
            Msgbox "Hi David"
        End Function

    Now having said all of that, I don't currently have Extra! installed, but if you play around with the syntax on the command line (in terms of the double and maybe single quotes), you will get this to work. 

    Note: While you are playing with this you may see rogue instances of ebrun in the task manager (from failed attempts). These may prevent subsequent attempted launches from working, you should kill these ebrun.exes and extra.exe and also ebmngr.exe, so that each attempt is a clean one with no previous attempts getting in the way. 

    As for using the dialog approach that is a completely different can of worms :-) Dialogs can be quite tricky depending on how deep you wish to get into them in terms of Modal/NonModal and event handling

    Tom

  • Verified Answer

    +1   in reply to   

    Hi David,

    Tom and I spoke about this more and have worked it out.  You do want to use "Run Macro". Using Tom's example above the button assignment syntax should be (note that there are no quotes in the "Macro:" command.)

    This will call the "Hello.ebm" macro and pass the parameter "hello"

    The Command$ will pass the parameter to the macro and thus allow you to name the function you want to call in the button.

    So in Tom's sample code above, the button defined in this example will pass hello to the Command$ variable and will call the function HELLO in the macro.

    Note the syntax for this dialog:

    Preferred syntax:
    "mymacro.ebm notepad.exe" will run mymacro.ebm and pass "notepad.exe" on the command line.
    Acceptable syntax (will work, but not recommended):
    "mymacro notepad" will run mymacro.ebm and pass "notepad" on the command line.
    Illegal syntax:
    "mymacro notepad.exe" will attempt to find "mymacro notepad.exe" and will fail.

    Regards,

    Jeff B.

Reply
  • Verified Answer

    +1   in reply to   

    Hi David,

    Tom and I spoke about this more and have worked it out.  You do want to use "Run Macro". Using Tom's example above the button assignment syntax should be (note that there are no quotes in the "Macro:" command.)

    This will call the "Hello.ebm" macro and pass the parameter "hello"

    The Command$ will pass the parameter to the macro and thus allow you to name the function you want to call in the button.

    So in Tom's sample code above, the button defined in this example will pass hello to the Command$ variable and will call the function HELLO in the macro.

    Note the syntax for this dialog:

    Preferred syntax:
    "mymacro.ebm notepad.exe" will run mymacro.ebm and pass "notepad.exe" on the command line.
    Acceptable syntax (will work, but not recommended):
    "mymacro notepad" will run mymacro.ebm and pass "notepad" on the command line.
    Illegal syntax:
    "mymacro notepad.exe" will attempt to find "mymacro notepad.exe" and will fail.

    Regards,

    Jeff B.

Children
  • 0 in reply to   

    I just now saw your response because work has had me all over the place.    I’m going to try that first thing in the morning.  Thank you so much. 

  • 0 in reply to   

    You guys are the absolute greatest. That functions exactly how I initially wished it would. Thank you so much. I tested it with your code and an added function passing first the number one then two and each worked as intended.

    Declare Function HELLO()

    Declare Function GOODBYE()

        Sub Main
            Select Case UCASE(Command$)
                Case "1"
                    call Hello


                Case “2”

                     Call Goodbye

                Case Else
                    Msgbox "Function not found"
            End Select 
        End Sub


        Function HELLO()
            Msgbox "Hi David"
        End Function


        Function GOODBYE()

            Msgbox “Goodbye David”

         End Function