How Do I Call a Program Dynamically By Its Index? (Magic xpa 4.x)
You can call a program based on its index number. You can do this two ways, by using the Call by Expression operation, or by using the function CallProg().
CallProg() is useful when you want the program to execute within an expression, and you want to use the returned value as a parameter to another function.
-
Use F4 to create an operation.
-
Press C for the Call operation. Tab to the next field.
-
Select By Exp for the call type. Tab to the next field.
-
Zoom to create an expression. The expression should be the program’s index number in quotes, followed by the PROG literal. We are calling program 61, so we entered '61'PROG.
(where n is the program index) wherever you want the return value of the program. This could be as an init value, as an expression displayed on a form, or as part of another expression. Or, if the program has no returned value, you can use an Evaluate operation.
You can also use CallProg() in conjunction with the ProgIdx() function, to call the program from within an expression using the program’s public name.
These methods are mainly useful when you want to store the name or number of the program to call. For instance, you could create a table to allow the user to create their own private menu system.
Note: The PROG literal is what allows Magic xpa to keep the program number synchronized if the program happens to get moved within the Program repository. You can use the format CallProg(61) and it will function, but if program 61 gets moved to become program 65, the function will still be calling program 61.
Hint: This method is useful in combination with the ProgIdx() function, which returns the program index based on its public name.
When you are selecting a program number, you do not have to memorize the number. For this, and other items you need to add to expressions, you can use the Program list that's available from the Expression Editor. For the examples above, to select the program number, you would:
-
From the Expression Editor, after selecting the CallProg function, click the program icon from the toolbar or select Programs from the drop-down list. A list of programs will appear on the right side of the Expression Editor.
-
Find the program that you want. You can use Locate (Ctrl+L) or go directly to the Search field, and then type the first letters of the program name, or just scroll, to position on the program you want.
-
Click the Select button.
The program literal will be brought into your expression.
The Online and Rich Client Samples projects (program EL11 and REL11)