Page 1 of 1
revPrintField and <% %> substitution
Posted: Tue Jan 29, 2013 8:56 pm
by mmiele
Hi all,
I'm guessing if it is possible to put the content of a variable into a report using the <% %> substituition engine of the revPrintField command. In other words, if I have a field named "myReport" containing:
name: <%MyName%>
if I
Code: Select all
put "Mario" into myName
revPrintField the name of field "myReport"
what I get is
name: myName
and not
name: Mario
The same if I use <%value(myName)%> even if myName is a global var.
Anyone knows a way?
thanks in advance,
Re: revPrintField and <% %> substitution
Posted: Tue Jan 29, 2013 10:46 pm
by Simon
Seems the revPrintField only supports a few "special values" as variables.
Code: Select all
put "Mario" into myName
put myName into fld "myReport" --Add this line to fill the field
revPrintField the name of field "myReport"
Not sure of the way you are using this so I can't help much more.
Simon
Re: revPrintField and <% %> substitution
Posted: Wed Jan 30, 2013 2:49 am
by mmiele
What I want to do is to fill a print template with values coming from variables. I hoped to avoid to write some code by myself using the <% %> substitution.
Re: revPrintField and <% %> substitution
Posted: Wed Jan 30, 2013 3:38 am
by Simon
Hi mmiele,
Yes, I understand you would like to use variables that is clear but
You can also use the special value <%pageNumber%> in the field: this value is replaced with the page number.
and the date are the only vars the dictionary. Other functions like <%mouseLoc()%> do work.
Custom functions for a <%nameIn()%>:
Code: Select all
function nameIn
put "tom" into tName
return tName
end nameIn
Don't work.
Code: Select all
put "Mario" into field "myReport
revPrintField the name of field "myReport"
Is just 2 lines of code. Same as your initial posting.
Simon
Re: revPrintField and <% %> substitution
Posted: Sun Feb 03, 2013 8:22 pm
by mmiele
An handler to do the task:
Code: Select all
on subsInFld @myArray,myFieldID,strForEmpty -- replaces each marker <%key%>
-- with the content of myArray["key"] in the field wich ID is myFieldID.
-- If myArray["key"] is empty, it replaces the marker with the optional strForEmpty.
put the HTMLText of fld id myFieldID into theText
put the keys of myArray into klist
repeat for each line kk in klist
put empty into t1
if myArray[kk] is not empty then
replace ("<%" & kk & "%>") with myArray[kk] in theText
else
replace ("<%" & kk & "%>") with strForEmpty in theText
end if
end repeat
set the HTMLText of fld id myFieldID to theText
end subsInFld
This way you can create a RTF or HTML template using an external application, load it into the RTFtext or the HTMLText of a field and fill it with your data (possibly coming from a DB).
Re: revPrintField and <% %> substitution
Posted: Sun Feb 03, 2013 9:38 pm
by Bernard
Might the merge() function do what you require?
http://docs.runrev.com/Function/merge
Let your field "Field1" contain this:
hello [[MyName]]
In your script do this:
Code: Select all
put the text of field "Field1" into tTemplate -- we'll put this back later
put "Roger Rabbit" into MyName
put merge(the text of field "Field1") into field "Field1"
revPrintField field "Field1"
set the text of field "Field1" to tTemplate.
This should result in
hello Roger Rabbit
being printed.
None of this tested, just typed in here.