# Some more options for variables

**URL:** https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751
**Category:** Feature Requests
**Created:** [November 6, 2006, 6:40am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751 "2006-11-06T06:40:08Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [November 6, 2006, 6:40am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/1 "2006-11-06T06:40:08Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [November 7, 2006, 11:40am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/2 "2006-11-07T11:40:36Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [November 9, 2006, 6:07am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/3 "2006-11-09T06:07:17Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![angus](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/a/b3f665/32.png) [@angus](https://www.finalbuilder.com/forums/u/angus)
#### Post date: [November 12, 2006, 11:23am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/4 "2006-11-12T11:23:12Z")

</div>

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

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [December 1, 2006, 6:47am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/5 "2006-12-01T06:47:14Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![tate](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/t/e19b73/32.png) [@tate](https://www.finalbuilder.com/forums/u/tate)
#### Post date: [December 4, 2006, 1:22am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/6 "2006-12-04T01:22:30Z")

</div>

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

---

<div class="post-metadata">

### Author: ![stevage](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/bc8723/32.png) [@stevage](https://www.finalbuilder.com/forums/u/stevage)
#### Post date: [December 5, 2006, 11:48am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/7 "2006-12-05T11:48:20Z")

</div>

[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

---

<div class="post-metadata">

### Author: ![Vincent](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/vincent/32/938_2.png) [@Vincent](https://www.finalbuilder.com/forums/u/Vincent)
#### Post date: [December 6, 2006, 12:23pm UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/8 "2006-12-06T12:23:38Z")

</div>

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

---

<div class="post-metadata">

### Author: ![stevage](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/bc8723/32.png) [@stevage](https://www.finalbuilder.com/forums/u/stevage)
#### Post date: [December 6, 2006, 12:42pm UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/9 "2006-12-06T12:42:42Z")

</div>

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

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [December 6, 2006, 1:19am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/10 "2006-12-06T01:19:51Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![stevage](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/bc8723/32.png) [@stevage](https://www.finalbuilder.com/forums/u/stevage)
#### Post date: [December 6, 2006, 1:27am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/11 "2006-12-06T01:27:30Z")

</div>

Oh, I completely misunderstood, please ignore me :)Steve

---

<div class="post-metadata">

### Author: ![deleted\_user](https://www.finalbuilder.com/forums/user_avatar/www.finalbuilder.com/deleted_user/32/937_2.png) [@deleted\_user](https://www.finalbuilder.com/forums/u/deleted_user)
#### Post date: [December 6, 2006, 3:27am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/12 "2006-12-06T03:27:20Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![stevage](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/bc8723/32.png) [@stevage](https://www.finalbuilder.com/forums/u/stevage)
#### Post date: [December 6, 2006, 3:59am UTC](https://www.finalbuilder.com/forums/t/some-more-options-for-variables/3751/13 "2006-12-06T03:59:38Z")

</div>

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
