PDA

View Full Version : Macro with Special Characters


HippyCraig
06-15-2010, 12:16 PM
I have a script that needs to modfiy a setup project. Its updating the default install location.

The value I want to enter is the following:
[ProgramFilesFolder][Manufacturer]\\[ProductName]

I have doubled up the special characters when the value of the macro is set, but when I place the values back into the file its getting evaluated to many times. First when its set, then when I use a regex to place it back in the file. I have had to more than double up on the special characters. See attached file

Any advice?

HippyCraig
06-15-2010, 12:24 PM
Watching the values of the characters as the script runs, the \ doesnt change throughout all the calls but the [ or the ] has to be doubled and doubled again.

kinook
06-16-2010, 05:28 PM
[ and ] in Visual Build denote a script expression (see http://www.kinook.com/VisBuildPro/Manual/specialchars.htm). [[ and ]] specify literal square bracket characters. The value of the TMP_DL_VD_PATH macro ([ProgramFilesFolder][Manufacturer]\[ProductName]\CHANGE) is being evaluated in multiple places, requiring a doubling for each evaluation:
1) When assigning the TMP_DL_VD_PATH macro value in the Subroutine Call step 'Modify Client Setup'
2) When expanding the %TMP_DL_VD_PATH% reference in the 'Modify Folder Section->Modify Search Results' subroutine step
3) When expanding the %TMP_SEARCH_RESULTS% reference in the Apply Modified Search step

HippyCraig
06-17-2010, 07:45 AM
But the part I am having an issue with is why is the [[ behaing this way but the \\ are not? I would expect as they were passed between values to not be evaulated becuase they are doubled as with the \\?

kinook
06-17-2010, 07:50 AM
That is required by the regex engine (in both the Modify and Apply steps) to treat as a literal \ character.
http://zez.org/article/articleprint/11/

HippyCraig
06-17-2010, 07:54 AM
Right thats my point, if I only have to double the slashes once and it works through all these calls then why do I have to triple the amount of times doubling for the [[.

According to you statement about the three diffenent evaluations, that I would have to triple the [[ as well as the \\. Why do the regex litirals get evaluated diffently then the scipt literals?

kinook
06-17-2010, 08:13 AM
It appears that the first regex replace does not require escaping?

You can prevent the first evaluation of [ ] by unchecking 'Expand macros in parameter values before calling subroutine' in the Subroutine Call step (but then you can't reference macros like %PROJDIR% in other parameters; another option would be to use the Set Macro action for the TMP_DL_VD_PATH macro [with 'Don't expand' checked]).

You can prevent the 2nd evaluation of [ ] by replacing

%TMP_DL_VD_PATH%

with

" & vbld_TempMacros()("TMP_DL_VD_PATH") & "

HippyCraig
06-17-2010, 09:09 AM
I found some interesting behavoir:

1. If I double the [ once so that the value of a macro is [[Program Files]] when assigning it to another macro it gets evaluated to [Program Files], which is what I expect.

2. But if I have an inital value in one macro [Program Files] and when I assigen it to another macro it still evaluates to [Program Files].

This is all before the value is writen to a file I was checking the temporary macro values as it progressed, is that supposted to happen or should it be evaluated in the second example when its assigned to another macro.

kinook
06-17-2010, 09:18 AM
It depends on how you're assigning the value (for instance, within a VBScript variable assignment, special VBP chars aren't evaluated, but when expanding a reference like %MACRO_NAME% in a step field, they are). Attach your project.

HippyCraig
06-17-2010, 09:27 AM
There are two scripts both the same execpt for in the the 'Modify Folder Section->Modify Search Results' One has the first replace commented out and the other does not. But they both evaluate to the same result.

But if I use the % doesnt evealuate teh same way as the [ or the ].

kinook
06-17-2010, 10:30 AM
The %TMP_DL_VD_PATH% reference is expanded before the code is fed to the script engine and executed (and the macro value modified).
http://www.kinook.com/VisBuildPro/Manual/specialchars.htm

HippyCraig
06-17-2010, 10:36 AM
But what about the other example were the code was commented and I get the same result?

kinook
06-17-2010, 10:45 AM
The script code does not affect the expanded value of %TMP_DL_VD_PATH% that is fed to the script engine (since the value is expanded *before* the script code is executed).

HippyCraig
06-17-2010, 11:36 AM
So i understand this it will evaluate the macro's and escape characters but will not evaluate the script code untill it, in my example is writen to the file. that would explain why I can comment out the two lines of code and both would work, is that correct?

kinook
06-17-2010, 11:00 PM
Close. When the Modify Search Results steps builds, the sequence is:
1) Recursively expand any macro references (i.e., %TMP_DL_VD_PATH%) and script expressions ([code]) in the script code field.
2) Execute the script code. The code modifies the TMP_DL_VD_PATH macro, but the macro reference above has already been replaced with the previous macro value.

The next step replaces text in the file with the contents of the macro value TMP_SEARCH_RESULTS.

HippyCraig
06-18-2010, 08:15 AM
Thanks for all the help!