Macro coding question

Just starting out? Need help? Post your questions and find answers here.
gddeluca
New User
New User
Posts: 9
Joined: Sun Apr 19, 2015 5:25 pm

Macro coding question

Post 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   
normeus
Enthusiast
Enthusiast
Posts: 475
Joined: Fri Apr 20, 2012 8:09 pm
Contact:

Re: Macro coding question

Post 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
google Translate;Makes my jokes fall flat- Fait mes blagues tombent à plat- Machte meine Witze verpuffen- Eh cumpari ci vo sunari
gddeluca
New User
New User
Posts: 9
Joined: Sun Apr 19, 2015 5:25 pm

Re: Macro coding question

Post 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.
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Macro coding question

Post 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 :wink:

You need the DoubleQuote Macro that you can use the expand #
gddeluca
New User
New User
Posts: 9
Joined: Sun Apr 19, 2015 5:25 pm

Re: Macro coding question

Post 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.
Post Reply