I have a few requests regarding variables:
First, could you make it so that FinalBuilder is able to use the same generated variables as on the command line. The ones I’m specifically interested in are %DATE%, %TIME%, %CD%, and %RANDOM%. Not only does FinalBuilder not recognize the variables internally, but it won’t let you call them even from a command line. For example if you create a DOS command and make it “ECHO %DATE%” the action will fail because FB didn’t recognize the variable.
Second, could you make the “If Variable Defined” have an optional NOT modifier? I want to check if a variable is defined, and if not then I want to define it. Currently I have to use IF-Defined in a Try-Catch block and this just looks ugly, both in the script and in the log.
Third, could there be a way to parse and/or iterrate a string? When writing batch files I use the FOR /f command to parse though CSV and other such formatted text. Could there be a similiar type of action item for FinalBuilder?
Hi Mike,
I’ll put your request for automatically generated variables onto our to-do list.
To use a DOS Command which echoes the DATE generated variable, double-escape it as ECHO %%DATE%%. FinalBuilder will expand the %%s back to %.
To use “If Not Variable Defined”, check the “invert behaviour” checkbox on the property page. I’ll rename this to something a little more intuitive.
At the moment, the easiest way to parse a string in FinalBuilder is probably to read it in using Read Text File and then use some JScript to split it up, ie:
var LinesArray = DATA.split("\r\n");
for(var j = 0;j < LinesArray.length; j++) {
var CSVFields = LinesArray[j].split(",");
for(var i = 0; i < CSVFields.length; i++) {
// Do something with data from line j, CSV field i
}
}
There is also the File Contents iterator to iterate through the lines of a text file. Would a CSV File Iterator option be of any use?
Regards,
Angus
We could look into adding a CSV Iterator action. Would that be of some use?
Generated variables:
Sounds good. The one I forgot to mention that I also use frequently in batch files is “%~dp0” which always points to the location of the running batch file. I used this to specify files with paths relative to the batch file, so that if I move the folder containg the batch I don’t have to re-write a bunch of hard-coded paths. I have not yet figured out an easy way to do this same thing in Final Builder - can you add a generated variable that points to the Full Path of the current project file? Then I could use the Variable Set action to trim it to what I need.
Invert Behavior:
I don’t seem to see this option on the property page. I’m using 4.2.305.
CSV:
Yes I think it would be useful. The way that DOS does it is sets a bunch of sequential variables. For example:
FOR /f “delims=, tokens=1-5 eol=;” %A in (MyData.CSV) do …
Would generate %A through %E for each line (5 tokens)
Also note the “EOL=;” option allows you use “;” as a comment marker
Also:
I would like a sub-string function (could be a part of the Set Variable action, in the modifiers list) that would make parsing fixed-format tables easier.
And why can’t I pass a variable to a script in the Execution Condition line on the property page? If I put for example MsgBox(’%MyVar%’) it shows that string literally.
I don't seem to see this option on the property page. I'm using 4.2.305.
Yes I think it would be useful. The way that DOS does it is sets a bunch of sequential variables. For example:
FOR /f "delims=, tokens=1-5 eol=;" %A in (MyData.CSV) do ...
Would generate %A through %E for each line (5 tokens)
Also note the "EOL=;" option allows you use ";" as a comment marker
I would like a sub-string function (could be a part of the Set Variable action, in the modifiers list) that would make parsing fixed-format tables easier.
Hth.
- Angus
So is there currently any way to generate a random number/string from FB4?
In DOS I usually do this at the beginning of my batch:
SET WorkingDir=%TEMP%%RANDOM%
And then work out of %WorkingDir%, so that I can have multiple instances of a batch running without them thrashing each other’s files.
Mike - it’s on the todo list
If you want a pseudo random string, then you can use the Generate GUID action (and maybe pick out some of the characters).
.t8
[quote]The one I forgot to mention that I also use frequently in batch files is “%~dp0” which always points to the location of the running batch file. I used this to specify files with paths relative to the batch file, so that if I move the folder containg the batch I don’t have to re-write a bunch of hard-coded paths. I have not yet figured out an easy way to do this same thing in Final Builder - can you add a generated variable that points to the Full Path of the current project file? Then I could use the Variable Set action to trim it to what I need.[/quote]I define a variable, %BuildRoot% (with a value like D:\Builds), and include that at the start of every directory reference. I wouldn’t want to build anywhere related to the FinalBuilder directory.Steve
[quote]The one I forgot to mention that I also use frequently in batch files is "%~dp0" which always points to the location of the running batch file. I used this to specify files with paths relative to the batch file, so that if I move the folder containg the batch I don't have to re-write a bunch of hard-coded paths. I have not yet figured out an easy way to do this same thing in Final Builder - can you add a generated variable that points to the Full Path of the current project file? Then I could use the Variable Set action to trim it to what I need.[/quote]I define a variable, %BuildRoot% (with a value like D:\Builds), and include that at the start of every directory reference. I wouldn't want to build anywhere related to the FinalBuilder directory.Steve
Hi Steve
FinalBuilder has some built in System Variables that will give you what you want - FBPROJECT and FBPROJECTDIR
Yeah, but I don’t want to build anything in c:\documents and settings\my documents…Also, perhaps I have the opposite desire to Mike: I don’t want the build directory to change if I happen to move the location of the FB project :)(though now I’m wondering if I should rethink some of this…)Steve
Mike - it's on the todo list :)
If you want a pseudo random string, then you can use the Generate GUID action (and maybe pick out some of the characters).
.t8
I define a variable, %BuildRoot% (with a value like D:\Builds), and include that at the start of every directory reference. I wouldn't want to build anywhere related to the FinalBuilder directory.Steve
Oh, I completely misunderstood, please ignore me :)Steve
To get around FB not reading CSV files, I’m parsing them in DOS. However, I don’t know if there is a way to pass a variable from a called DOS command back up to FB? I’m assuming that SETX won’t even work because FB only checks variables on first load?
So I guess my only option is to have the DOS command write it’s output to an INI file, and then have FB do a Read Variable From INI Action immediately after.
So the DOS command would look something like this:
FOR /f “delims=, tokens=1-3” %%A in ("%CSVLine%") do ECHO [FBVariables]>%TempINI%&ECHO Col1=%%A>>%TempINI%&ECHO Col2=%%B>>%TempINI%&ECHO Col3=%%B>>%TempINI%
Not pretty, but that’s the DOS command to parse a 3-column CSV line [%CSVLine%] into an INI file [%TempINI%] that can then be read and parsed by FB.
You can use a find/replace hack. Write into some output file (not as fancy as a .ini file). Find/replace the first token (or only token). In the script “OnFindReplace” or whatever it’s called, set a varialbe to the found value.Works! :)Steve