VB Script- Constant Global Variables
Andrei from United States  [3 posts]
5 years

I want to figure out a way to be able to assign a global variable in a VB script that remains in Roborealm memory from one main module loop iteration to the next.

Specifically I have a simple VB script like this in my main module:

size = 2
ReDim array(size)

if GetVariable("SCRIPT_COUNT") < 10 then

   ' Here I populate array with dummy values, but really I'm reading a .csv
   ' file and populating the array with read-in values

   array(0) = 1
   array(1) = 2
   array(2) = 3

   SetArrayVariable "ARRAY", array


   array = GetVariable("ARRAY")

end if

So running this VB script I get the error, "error(17): Type mismatch", this is due to the "array = GetVariable("ARRAY")" line, because the ARRAY global variable only remains defined while SCRIPT_COUNT is less than 10, then it vanishes & GetVariable has nothing to fetch...

How do I permanently declare a GLOBAL VB script variable that remains through out repeated module execution?

I need to save computational time, because reading a large .csv EVERY TIME to populate constant array values in a VB script is redundant and wastes unnecessary computational time. So I want to read in the values upon initial script execution & have them saved in global variables to be used upon the next VB script cycle.

I would really appreciate any insight on this issue, or a different way to save computational time when reading and declaring constant global values.

Thank you,
Vispacem from Germany  [2 posts] 5 years
Hi Andrei,

I just started with RR and I'm right now fuzzying araund with VB script - so, I'm not an expert... ;-)

...but: your code shows
"array = GetVariable("ARRAY")", I think
"array = GetArrayVariable("ARRAY")"
is the correct syntax for reading an array.

Just my five cents...

Good luck,

Andrei from United States  [3 posts] 5 years
Hi Vispacem,

Thank you for your reply. Yes, you are correct I should have used GetArrayVariable("ARRAY") instead. I actually had that syntax in my VB script but I mistyped it into my question on this forum.

So using the proper syntax, GetArrayVariable("ARRAY") , I still get an error. I pasted the code below that I'm using in my VB script. I still get the runtime error: "error (24) : Type mismatch"

If anyone has any ideas or suggestions I will greatly appreciate it if you share them.

Thank you,

'****************** VB SCRIPT *****************

size = 4
ReDim arr(size)

script_ctr = GetVariable("SCRIPT_COUNT")

if script_ctr < 10 then

    arr(0) = 1
    arr(1) = 2
    arr(2) = 3
    arr(3) = 4
    arr(4) = 5
    SetArrayVariable "ARR", arr
    SetVariable "SCRIPT_CTR", script_ctr


        'ReDim Arr(size) <- Tried doing this but didn't help
    arr = GetArrayVariable("ARR")
end if

'error (24) : Type mismatch
Steven Gentner from United States  [1413 posts] 5 years

script_ctr = GetVariable("SCRIPT_COUNT")

if script_ctr < 10 then

    size = 4
    ReDim tst(size)

    tst(0) = 1
    tst(1) = 2
    tst(2) = 3
    tst(3) = 4
    tst(4) = 5
    SetArrayVariable "ARR", tst
    SetVariable "SCRIPT_CTR", script_ctr

    arr = tst


    arr = GetArrayVariable("ARR")

end if

Anonymous 5 years

We tried your suggestion however the vbscript program is still giving an "error (18) : Type mismatch" which is the "arr=tst" assignment
Steven Gentner from United States  [1413 posts] 5 years
Perhaps you can attach what you tried (i.e. upload the robofile here) so that we can see what might not be working ... what I attached seems fine assuming you are using the latest version.


This forum thread has been closed due to inactivity (more than 4 months) or number of replies (more than 50 messages). Please start a New Post and enter a new forum thread with the appropriate title.

 Forum Index