Just starting out? Need help? Post your questions and find answers here.
gddeluca
New User
Posts: 9 Joined: Sun Apr 19, 2015 5:25 pm
Post
by gddeluca » Thu Dec 05, 2024 9:47 pm
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
normeus
Enthusiast
Posts: 475 Joined: Fri Apr 20, 2012 8:09 pm
Contact:
Post
by normeus » Thu Dec 05, 2024 10:15 pm
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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
gddeluca
New User
Posts: 9 Joined: Sun Apr 19, 2015 5:25 pm
Post
by gddeluca » Thu Dec 05, 2024 10:28 pm
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.
infratec
Always Here
Posts: 7662 Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany
Post
by infratec » Thu Dec 05, 2024 10:29 pm
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 #
gddeluca
New User
Posts: 9 Joined: Sun Apr 19, 2015 5:25 pm
Post
by gddeluca » Thu Dec 05, 2024 10:40 pm
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.