Some more options for variables

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.

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.
You can use %FBPROJECT% or %FBPROJECTDIR%, to get the parent directory.

Invert Behavior:
I don't seem to see this option on the property page. I'm using 4.2.305.
Ah, yes. Sorry, that was an FB 5 addition. For 4.2, the solution is to put an "Else" action immediately below the If action, and then put the child actions under the Else.


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
I'll put it on our to-do list.

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.
FinalBuilder 5 has some new string manipulation actions which could probably do what you need. For 4.2, script is probably the easiest and most flexible solution.

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.
Because the condition is a script, you don't need the %s - all FinalBuilder variables are accessible directly. ie: MsgBox(MyVar).

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 :slight_smile:

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

Posted By Steve Bennett on 05 Dec 2006 4:48 PM
[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

Posted By Tate Needham on 03 Dec 2006 6:22 PM
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 will try that, thanks for the idea.

Posted By Steve Bennett on 05 Dec 2006 4:48 PM
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
I do that for the actual builds, but I'm talking about files for the build script. For example I want to load build settings out of an INI file, which will be in the same folder as the FBP file. Or another example is I want to call a child FBP from my current FBP, and the child is in the same folder (or even in a child folder) from the main FBP folder. So to use an absolute path for these files, I need to know the absolute path to the main FBP file, then append the relative path to get the final path. Thanks anayway for the suggestion though.

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