# VBScript: set Variables with Underscore

**URL:** https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204
**Category:** Bugs
**Created:** [April 4, 2022, 5:15pm UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204 "2022-04-04T17:15:26Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![service](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@service](https://www.finalbuilder.com/forums/u/service)
#### Post date: [April 4, 2022, 5:15pm UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/1 "2022-04-04T17:15:27Z")

</div>

In the FinalBuilder itself there are no problems with $(\_abc) and the “Set Variable” action,

but in VBScript such a variable cannot be set.

According to the code completion, there is an FBVariables.\_abc,  
but that’s not true. Luckily there has FBVariables.GetVariable(“\_abc”).

But how can this variable to be set?

```auto
x = FBVariables._abc ' does not compile, error message see below 
x = FBVariables.GetVariable("_abc")

```

> Error Executing script : BeforeAction  
> Compilation error in Microsoft VBScript  
> invalid symbol  
> Line: 2  
> Char : 18  
> Error in BeforeScript : VBScript, This Action did not execute.

My attempts (can’t find anything else in the code completion, nor anything in the forum or google)

```auto
FBVariables._abc = x
FBVariables.GetVariable("_abc") = x
FBVariables.SetVariable("_abc", x)
FBVariables.SetVariable "_abc", x

Action.EnvironmentVariables.Values("_abc") = x ' this does work, but only for current MSBuild-Action

```

The codes with FBVariables.GetVariable and FBVariables.\_abc, in a function in GlobalScript, the execution also breaks off without an error message.  
No error message apart from

> Error in BeforeScript : VBScript, This Action did not execute.

First thought it was due to SkipAction and had been looking there for ages. 😫

---

<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: [April 4, 2022, 10:15pm UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/2 "2022-04-04T22:15:22Z")

</div>

The VBScript language does not allow ‘special’ characters in variables.

This works for me

```vbscript
dim x
Action.SetVariable "_test", "abc"
x = FBVariables.GetVariable("_test")
alert(x)

```

Not sure why we don’t have `Action.GetVariable` - we should since actions can implement their own variable namespace (only a few actions do that, like the group). The good news is FBVariables does expose variables via the Action’s variable namespace. Likewise we probably should have `FBVariables.SetVariable` for consistency.

---

<div class="post-metadata">

### Author: ![service](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@service](https://www.finalbuilder.com/forums/u/service)
#### Post date: [April 6, 2022, 5:04pm UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/3 "2022-04-06T17:04:26Z")

</div>

Unfortunately, Action.SetVariable only sets the variable within the action.  
After the action, the variable has its old value again. This is somewhat unfavorable, since the value should be used for many subsequent actions.

I found a preliminary “solution” → a second variable  
**\_test** as macro with `%dummy_test%`  
**dummy\_test** for write access in VBScript

---

<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: [April 6, 2022, 10:10pm UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/4 "2022-04-06T22:10:59Z")

</div>

> [@service](#):
>
> Unfortunately, Action.SetVariable only sets the variable within the action.

I’m not able to reproduce that here.

[VBScript\_UnderScore.fbp8](https://www.finalbuilder.com/forums/uploads/short-url/mUc1CR1utDdMuO3uzvDyMfg1pZ3.fbp8) (1.3 KB)

In the attached project, the value set in the script is preserved and available in the next action.

---

<div class="post-metadata">

### Author: ![service](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@service](https://www.finalbuilder.com/forums/u/service)
#### Post date: [April 7, 2022, 11:01am UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/5 "2022-04-07T11:01:17Z")

</div>

Crap, it works in your script.  
I was hoping it was because the SetVariable was in a function in ProjectGlobalScript, but unfortunately your script works with that too.

---

<div class="post-metadata">

### Author: ![service](https://www.finalbuilder.com/forums/letter_avatar_proxy/v4/letter/s/46a35a/32.png) [@service](https://www.finalbuilder.com/forums/u/service)
#### Post date: [April 7, 2022, 11:34am UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/6 "2022-04-07T11:34:21Z")

</div>

Ah, I found the reason.  
The variable is defined as a macro.

It wasn’t the underscore at all. Even with FBVariable.xyz=… it doesn’t work.

Why is it not possible to change the content?  
But OK, the SetVariable action doesn’t have such macros in the select list.

Maybe you could throw an error message here when trying to change such macro variables?

---

<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: [April 8, 2022, 4:27am UTC](https://www.finalbuilder.com/forums/t/vbscript-set-variables-with-underscore/7204/7 "2022-04-08T04:27:43Z")

</div>

> [@service](#):
>
> Maybe you could throw an error message here when trying to change such macro variables?

We have considered this in the past, however doing so might cause people’s builds to start failing. We’ll look at this for FB9.
