Posts: 121
Threads: 33
Joined: Jun 2007
Hi,
I'm trying to create a simple utility macro to receive a list of variable names and incorporate them into formatted lines for output/logging, like so :
..so I can just copy and paste the QM output into a macro.
I have been unsuccessful in my attempts to escape the char sequence "%s" so it shows up
as is in the QM output. In other words, I need a plain text version of "%s" (i.e. not processed) to appear where indicated in the below macro.
Macro
str outform
if(!inp(outform "" "" "[]")) ret
ARRAY(str) a=outform
int i
for(i 0 a.len) out "out ''%s = <need to insert escaped percent+s here>'' %s" a[i] a[i]
Thanks,
S
Posts: 1,000
Threads: 253
Joined: Feb 2008
I think what you are looking to do is this...
_s.format("out %s = <need to insert escaped percent+s here>'" a[i]
out _s
Posts: 121
Threads: 33
Joined: Jun 2007
Thanks VIg, but either I don't understand how that will help or I didn't explain my problem very well...
If you run the short macro I've pasted above and enter a word in the input box (in this example I used "var1"), the text written to the QM output window would look like this:
out "var1 = <need to insert escaped percent+s here>" var1
This is close to what I need, except instead of the "<need to insert escaped percent+s here>" part, I actually want the characters "%s". The "<need to...>" part is there just to show where I need help.
In other words, if it was done correctly, upon running the macro and entering the word "var1" in the input box, the text printed to the QM output window should look exactly like this:
out "var1 = %s" var1
Is that any clearer?
Thanks!
Posts: 1,000
Threads: 253
Joined: Feb 2008
This works...
Function
Function16
str outform
if(!inp(outform "" "" "[]")) ret
ARRAY(str) a=outform
int i
for(i 0 a.len)
,_s.format("out [34]%s = _s[34] %s" a[i] a[i])
,_s.findreplace("_" "%")
,out _s
I'm not sure why .format doesn't just let [37] be a % without using it as part of the function...it caught me up for a bit. Find replace will do the trick...you can use more complicated combinations of characters to make sure it replaces what it is supposed to.
Posts: 11,929
Threads: 138
Joined: Dec 2002
Posts: 1,000
Threads: 253
Joined: Feb 2008
Function
Function16
str outform
if(!inp(outform "" "" "[]")) ret
ARRAY(str) a=outform
int i
for(i 0 a.len)
,_s.format("out [34]%s = %%s[34] %s" a[i] a[i])
,out _s
Der...in the help file!
Posts: 121
Threads: 33
Joined: Jun 2007
Posts: 121
Threads: 33
Joined: Jun 2007
Quote:Der...in the help file!
Where, please? Damned if I didn't spend over an hour trying everything I could find that seemed relevant on escaping, char codes. That''s been my major problem - I know what I want but don't always know enough terminology to know where to find it.
Posts: 473
Threads: 33
Joined: Aug 2007
Look under "VARIANT members table", is this what you wanted?
Taking on Quick Macros one day at a time
Posts: 121
Threads: 33
Joined: Jun 2007
As if I wasn't feeling low enough because of how little I know, along comes the VARIANT members table : (
Actually I was wondering where it is explained that "%%s" is an escape for %s (after having really tried to figure that one out myself for quite a while...)
But, as a wise forum member says, "...one day at a time."
Posts: 1,000
Threads: 253
Joined: Feb 2008
%% for % is briefly mentioned in Format String of help
Quote:Tips
The mostly used format fields are %i for integers and %s for strings.
To include variables in format fields, at first format the format-string with these variables. Use %% for %.
To insert this function, can be used the Text dialog from the floating toolbar.