Page 1 of 1
Macro coding question
Posted: Thu Dec 05, 2024 9:47 pm
by gddeluca
I'm trying to create a macro which will call a Procedure and pass it the value of one of the macro operands as a literal (i.e. within quotes)
But so far I cannot find a syntax which works.
Here's a short sample. I want to Call the SQL procedure passing the 'Field' macro operand surrunded by quotes -- as a string literal.
Code: Select all
Declare SQL(Field.S)
Macro SetEnv(Field, value)
ENV\Field = value
SQL(#DQUOTE$ # Field # #DQUOTE$)
EndMacro
Structure ENVData
StrField.S
EndStructure
ENV.ENVData
ENV\StrField = "Hello"
SetEnv(StrField, "GoodBye")
Debug Env\StrField
Procedure SQL(field.S)
Debug "SQL: " + field
EndProcedure
Re: Macro coding question
Posted: Thu Dec 05, 2024 10:15 pm
by normeus
Lately I am having a hard time understanding the questions, here is what I think you want:
Code: Select all
Macro DoubleQuote
"
EndMacro
Declare SQL(Field.S)
Macro SetEnv(Field, value)
ENV\Field = value
SQL(DoubleQuote#Field#DoubleQuote)
EndMacro
Structure ENVData
StrField.S
EndStructure
ENV.ENVData
ENV\StrField = "Hello"
SetEnv(StrField, "GoodBye")
Debug Env\StrField
Procedure SQL(field.S)
Debug "SQL: " + field
EndProcedure
Norm
Re: Macro coding question
Posted: Thu Dec 05, 2024 10:28 pm
by gddeluca
Exactly what I want.
Is there a reason to have the macro to create a " ??
I tried variations with #DQUOTE$, ~"\"", etc using both + and # to concatenate strings - all failed.
Many thanks.
Re: Macro coding question
Posted: Thu Dec 05, 2024 10:29 pm
by infratec
Yes, it's a bit tricky:
Code: Select all
Declare SQL(Field.S)
Macro DoubleQuote
"
EndMacro
Macro SetEnv(Field, value)
ENV\Field = value
SQL(DoubleQuote#Field#DoubleQuote)
EndMacro
Structure ENVData
StrField.S
EndStructure
ENV.ENVData
ENV\StrField = "Hello"
SetEnv(StrField, "GoodBye")
Debug Env\StrField
Procedure SQL(field.S)
Debug "SQL: " + field
EndProcedure
This works too, but looks even more ugly:
Code: Select all
Macro SetEnv(Field, value)
ENV\Field = value
SQL(DoubleQuote#Field#")
EndMacro
Ups second winner is first looser
You need the DoubleQuote Macro that you can use the expand #
Re: Macro coding question
Posted: Thu Dec 05, 2024 10:40 pm
by gddeluca
Thanks. Just getting into PureBasic (coming from PowerBasic) so right now I'm mostly experimenting how I might be able to port some of the data structures for my app. It was heavily into using Objects with PowerBasic, but that's out. I looked at a posting of a possible way to do Objects in PureBasic, but, Boy! they were really kludgy. Just didn't seem worth the effort.