Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HOW TO reference a function name with variables?
#1
Morning to All!

Here is what I need to do per my macro & exe.
I see that there are problems with: "For example, with mac, if function name is variable, QM cannot know what function will be used, and displays a warning. Then use #exe."
If I need to include a 'function' that is referenced per variables THEN how do you suggest doing this?

Let's say the function is:

function_01_name

and I want to use a variable for the "01"

So I have something like,

mac F"function_{ID}_name"

How do I include this in an 'exe' macro (per "#exe" I guess?) (See my details below per what I tried.)

Thanks for your help & more details below!!!

Kent

*************************************

I am building a 'quasi-object' macro that I can easily instantiate into a new but slightly different macro or function.

For each instantiation of the Macro, the function names will change, for Example:

Macro #1 will have functions named as:
function-1_01
function-2_01

and Macro #2 will have functions named as:
function-1_02
function-2_02

I therefore want to be able to call the functions by using variables, such as:

str var1="_01"
mac F"function-1{var1}"

And call the variable.

How can you call a variable when using variables?

Here is what I resorted to:

str x="Oc_"
str y="_FrMatter_BeforeAll_DialogVARs_PreGlobal"
str nextFUNC=F"{x}{thisID}{y}"
out nextFUNC ;;for testing only
str fn = F"{nextFUNC}";;"MyFunction"
int r
r = call(fn)

Note:
-the function that I want to call is named: Oc_ID_510271_01_FrMatter_BeforeAll_DialogVARs_PreGlobal
-the "ID_510271_01" is what changes when I create a new macro from my object (this is the {thisID} variable above

I have successfully used the form above to call a variable BUT HERE IS THE KICKER, if I export it will not work.
Oh! I just saw the message about 'addfunction'

So, what do you suggest?
#2
I suggest to not use multiple functions with variable names. Use single function with parameters.

But if really need:
Macro Macro2742
Code:
Copy      Help
;/exe
#exe addfunction "f_0"
#exe addfunction "f_1"
#exe addfunction "f_2"

int i
for i 0 3
#opt nowarnings 1
,call F"f_{i}"
,;;or, if need multiple threads:
,;mac F"f_{i}"
#opt nowarnings 0
Function f_0
Code:
Copy      Help
out 0
Function f_1
Code:
Copy      Help
out 1
Function f_2
Code:
Copy      Help
out 2
#3
OK, shall experiment & THANK YOU!

Kent
#4
Gintaras,

Been trying to think through your reply. I JUST WANT TO BE SURE that we are on the same page.

I have a macro that has 15 functions that I want to create an 'exe' from (it may actually have 75 or more functions.)

I want to create a copy the above macro and all functions and make a new macro via 'exe'

THE ONLY DIFFERENCE is that the function names will have a different 'ID#" extension

Example
ParentMacroName_01
function1_01
function2_01
... (all the way to)
function15_01

THEN WHEN I COPY or create a new macro to exe, it becomes

ParentMacroName_02
function1_02
function2_02
... (all the way to)
function15_02


The parent macro, will get the ID, the '01' or '02' in each case from an 'ini' file.

Obviously the new macro will be looking for the old ID such as 'function15_01' but it is now named 'function15_02'

I don't want to have to manually change this ID, since some macros actually have 75 functions w. the new ID.

SO, I would like to have the ID be instantiated via a variable, that it gets from an 'ini-file'.

SO, are you saying that you still think that a 'single function with parameters' is the best way to do this?
#5
Quote:I want to create a copy the above macro and all functions and make a new macro via 'exe'

It is not possible in exe. If you want to automate copying of functions, it is possible with newitem, but not in exe.
#6
Ouch! -and yet thanks for your help! I've got to go a different direction then. Thanks again!

Kent
#7
Morning and back to this topic on a philosophical basis. As I have said, I AM NOT a programmer!!! -but having the ability to 'reference a function name via variables' seems like something that would be very powerful and of great use, that is when you create an 'exe'.

MY QUESTION =

Is this something that in fact would be technically very difficult to implement when creating 'exe's's?

OR

Is it just not that needed by QM users?

Just curious? & Thanks!
#8
Very difficult to implement, because QM script text is compiled to a "bytecode" before executing, it is not interpreted/executed directly. That bytecode is added to exe. Exe does not have a compiler.
#9
Ahhh! = what I supposed/figured! Thanks!


Forum Jump:


Users browsing this thread: 2 Guest(s)