Macro concatenate doesn't work with variable?
Posted: Sat May 04, 2024 2:15 am
I was looking at this topic -> https://www.purebasic.fr/english/viewtopic.php?t=84189
And I wanted to try and help, but this test code doesn't work if I use a variable ("n") instead of a literal number like "1".
I assumed the macro would take the numeric value of "n" to concatenate it to the "MyLabel_" text? But it's just literally using the text "n" instead?
The reason for my confusion is because in this example, the macro IS using the numeric value of "n" to double it:
So, what the? 
And I wanted to try and help, but this test code doesn't work if I use a variable ("n") instead of a literal number like "1".
I assumed the macro would take the numeric value of "n" to concatenate it to the "MyLabel_" text? But it's just literally using the text "n" instead?
Code: Select all
Macro DynamicRestore(n)
MyLabel_#n
EndMacro
n=Random(3,1)
Restore DynamicRestore(1) ; Change "1" to "n" and it doesn't work?
Read.s label$
Debug label$
End
DataSection
MyLabel_1: : Data.s "MyLabel_1"
MyLabel_2: : Data.s "MyLabel_2"
MyLabel_3: : Data.s "MyLabel_3"
EndDataSection
Code: Select all
Macro test(n)
n*2
EndMacro
n=50
Debug test(n) ; Outputs 100
