Executing Rev statements in a variable
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Executing Rev statements in a variable
The subject is what I want to do. Looks like the do command is the answer.
How are statements separated - return?
Do If statements count as 1 statement or as the number of statements they control?
Are there other ways to do this rather than the do command?
Thanks,
Pete
How are statements separated - return?
Do If statements count as 1 statement or as the number of statements they control?
Are there other ways to do this rather than the do command?
Thanks,
Pete
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Location: Aalst, Belgium
- Contact:
Statements are normally return-separated (though I believe you can also use semicolons to concatenate multiple command onto the same line - but these will still be counted as separate statements.) If my memory hasn't gone astray, then control structures such as (if...end if) and (try...catch...end try) count as 1 towards the scriptLimits.
Depeding on what you want to do, you can solve your problems with a smart combination of the do command, value function, behaviors, frontScripts, library stacks or backScripts - so the main question to provide you with a good answer: what are you trying to accomplish?
Jan Schenkel.
Depeding on what you want to do, you can solve your problems with a smart combination of the do command, value function, behaviors, frontScripts, library stacks or backScripts - so the main question to provide you with a good answer: what are you trying to accomplish?
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Thanks Jan. Yes I should have explained more abut what I'm trying to achieve.
At the risk of you telling me I should buy your product, I'm trying to put together a simple report writer for users to define their own reports.
The report definitions have placeholders in them for data to be retrieved from from an SQLite database. The placeholder resolve to anything from simple retrieval of a value from a column in the current table entry to more complex arithmetic and conditional statements.
I have a repeat loop which looks for each placeholder in a report definition line and replaces it with the database value.
There is a table that holds the definitions of each placeholder, so each time I find a placeholder in the report definition, I look it up in the placeholder table and then need to execute the definition for it. so for example, the definition might be a revDatabaseColumNamed statement at it's simplest up to an if...then...else statement or some arithmetic statements.
Hope that's clearer.
Thanks,
Pete
At the risk of you telling me I should buy your product, I'm trying to put together a simple report writer for users to define their own reports.
The report definitions have placeholders in them for data to be retrieved from from an SQLite database. The placeholder resolve to anything from simple retrieval of a value from a column in the current table entry to more complex arithmetic and conditional statements.
I have a repeat loop which looks for each placeholder in a report definition line and replaces it with the database value.
There is a table that holds the definitions of each placeholder, so each time I find a placeholder in the report definition, I look it up in the placeholder table and then need to execute the definition for it. so for example, the definition might be a revDatabaseColumNamed statement at it's simplest up to an if...then...else statement or some arithmetic statements.
Hope that's clearer.
Thanks,
Pete
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Location: Aalst, Belgium
- Contact:
You may be interested in the merge function as it allows you to evaluate placeholders, including pieces of if-then-else script, and as far as I know, there's no real script limit to them.
Example:
Assuming you stored this in a custom property named 'uTemplate' then your script could look something like:
The merge function is extremely versatile. See also these articles in the revUp newsletter that I wrote a while back:
HTH,
Jan Schenkel.
Example:
Code: Select all
First name: [[tFirstName]]
Last name: <? return tLastName ?>
<? if tComments is not empty then return "Comments:" && tComments
else return "No comments" ?>
Code: Select all
on mouseUp
local tFirstName, tLastName, tComments
put "John" into tFirstName
put "Doe" into tLastName
put "No idea what his real name is..." into tComments
answer merge(the uTemplate of me)
end mouseUp
- The Power of Merge (revUp | Issue 55 | August 18th, 2008)
- The Word of Merge - part 1 (revUp | Issue 61 | November 20th, 2008)
- The Word of Merge - part 2 (revUp | Issue 62 | December 22nd, 2008)
HTH,
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com
Wow! Thanks a lot Jan, this looks very interesting. I just read two of the three articles and really like the MsWord merge technique. Up to now I've been using the Word mail merge function in conjunction with a csv file to do this sort of thing but this looks easier. I'm particularly interested in how to deal with a variable number of lines and will have to research that.
I have managed to get the do command working on relatively simple statements. Appears that a semicolon is the separator between command.
Thanks again.
I have managed to get the do command working on relatively simple statements. Appears that a semicolon is the separator between command.
Thanks again.
Trying to use the merge command as documented in Jan's links above. Here's the code I'm using:
I split the merge and do commands because nothing was happening when i used "do merge". Now I'm getting an error "(Handler: can't find handler) near merge" on the merge statement.
printContract is the customProperty of the object the code executes in and contains:
Any ideas?
Code: Select all
put revMacFromUnixPath(specialFolderPath("Documents") & "/Bandtrak/Report Templates/Contract.doc") into theFile
put the printContract of me into theAppleScript
merge (theAppleScript)
do theAppleScript as "AppleScript"
printContract is the customProperty of the object the code executes in and contains:
Code: Select all
tell application "Microsoft Word"
open [[theFile]]
end tell
Ignore the last post
Never mind, just realised mege is a function!
Pete
Pete
I think I have a real problem this time!
Some of the placeholders in the document I'm merging into are not being replaced. I've checked and double checked the syntax of the placeholders and that the variables are correctly named and have the correct contents in my code but can't spot anything obvious.
Here's some of the rtf file that I'm having the problem with:
After the merge, it looks like this:
Using the debugger, I checked the variables right before the merge and they all have the correct name and valid contents.
Somehow or other the SigState, SigPostCode, and SigCountry placeholders work OK but the others don't.
Any ideas?
Pete
Some of the placeholders in the document I'm merging into are not being replaced. I've checked and double checked the syntax of the placeholders and that the variables are correctly named and have the correct contents in my code but can't spot anything obvious.
Here's some of the rtf file that I'm having the problem with:
Code: Select all
[[SigAddress1]][[SigAddress2]]
[[SigCity]], [[SigState]] [[SigPostCode]]
[[SigCountry]]
Code: Select all
[[SigAddress1]][[SigAddress2]]
[[SigCity]], CA 95472
USA
Somehow or other the SigState, SigPostCode, and SigCountry placeholders work OK but the others don't.
Any ideas?
Pete