revPrintField and <% %> substitution

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

revPrintField and <% %> substitution

Postby mmiele » Tue Jan 29, 2013 7:56 pm

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,
mmiele
 
Posts: 55
Joined: Sun Jan 21, 2007 12:25 pm
Location: Naples, Italy

Re: revPrintField and <% %> substitution

Postby Simon » Tue Jan 29, 2013 9:46 pm

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
I used to be a noob but then I learned how to spell teh correctly and now I'm an expert!
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 2329
Joined: Sat Mar 24, 2007 1:54 am
Location: Palo Alto, Guildford, Lausanne

Re: revPrintField and <% %> substitution

Postby mmiele » Wed Jan 30, 2013 1:49 am

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.
mmiele
 
Posts: 55
Joined: Sun Jan 21, 2007 12:25 pm
Location: Naples, Italy

Re: revPrintField and <% %> substitution

Postby Simon » Wed Jan 30, 2013 2:38 am

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
I used to be a noob but then I learned how to spell teh correctly and now I'm an expert!
Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
 
Posts: 2329
Joined: Sat Mar 24, 2007 1:54 am
Location: Palo Alto, Guildford, Lausanne

Re: revPrintField and <% %> substitution

Postby mmiele » Sun Feb 03, 2013 7:22 pm

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 ("&lt;%" & kk & "%&gt;") with myArray[kk] in theText
      else
         replace ("&lt;%" & kk & "%&gt;") 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).
mmiele
 
Posts: 55
Joined: Sun Jan 21, 2007 12:25 pm
Location: Naples, Italy

Re: revPrintField and <% %> substitution

Postby Bernard » Sun Feb 03, 2013 8:38 pm

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.
Bernard
 
Posts: 182
Joined: Sat Apr 08, 2006 9:14 pm
Location: London, England


Return to Talking LiveCode

Who is online

Users browsing this forum: No registered users and 2 guests