I'm trying to figure out how to feed a variable to a macro and use it to assemble it into another variable name inside the macro. The ting is , I would like call the macro inside a loop like below but the parameter used in the concantenated variable name in the macro is the literal value of the variable not its content even if it would seem that it should work? Is there any way to do this?
Macro TestD(number)
Debug "Macro input parameter:" + number
Debug "Variable value :" + Str(i#number)
EndMacro
i1=2
i2=4
i3=6
; Works
TestD(1)
TestD(2)
TestD(3)
; Does not work
For i=1 To 3
Testd(i)
Next
You are trying to reference a variable with a dynamic value (one that is determine at runtime). Macros only function at compile time.
Another option is to use an array instead that you store your values in and index as you need them. If you need more diverse names to be accessed you can declare those variables with 'Runtime' and use the appropriate functions to access them from the Runtime library.
Last edited by Demivec on Sun Jan 31, 2016 11:35 pm, edited 1 time in total.
A macro is a compiler function.
Your For-loop is a run time function, so the macro cannot know the value of "i" and the macro is translate to:
Debug "Variable value :" + Str(ii)
because, the "i" is insert for "#number"
There is no chance to to get i1, i2 and i3 from a macro which called only one time (on the compiler!) in your loop.
Thanks for the replies!
But the thing that is confusing me, seeing the outputted results, it seems that the macro indeed can use the incremented value in this part