Rhinoscipt (visual basic): problems with defining public array

Hi there

I’m having a hard time defining a public array in rhino script:

Option Explicit

Public arrImpressions()
Public arrKlicks()
Public arrCTR()
Public arrCPC()

This works the first time I run the code, but the second time I get a runtime error… The only way to resolve this is to quit rhino and restart.

What do I do wrong here?


Maybe try this:

 Private _arrImpressions() As array

 Public Property arrImpressions() As Array
                Return _arrImpressions()
            End Get
            Set(ByVal value As Array)
                _arrImpressions = value
            End Set
        End Property

works for me in vb.net

That’s unfortunately not it… I’m working in monkey editor where this kind of basic doesn’t work… I just looked into rhinoscript101 where defining a global variable is described exactly like this.

I just haven’t found an example with a global array variable… any help would be appreciated.
I have a faint memory that I once solved this problem already though I can’t remember how : )

I usually use Private myVariableName (not Public) for defining a global variable… Seems to work for an array() as well…


hm that’s weird. I just tried that, to the same effect. The first time it works. When I try to execute the script for a second time I get the error type mismatch.

I don’t get it…

Another interesting effect:

Once I get the error, if I change the script from Public to Private (or vice versa) it works again…
Is it possible rhino script still has the variables buffered from the last time?

I don’t know if the following is exactly kosher, but it seems not to error out in multiple use:

Option Explicit
If Not IsArray(stuff) Then Private stuff()
Private add
If IsEmpty(add) Then add = 0
Call Test()
Sub Test()
	ReDim stuff(0)
	stuff(0) = "stuff" & Cstr(add)
	Call Rhino.Print(stuff(0))
	add = add + 1
End Sub

Run it several times…


this should work:

Option Explicit

On Error Resume Next
Public arrImpressions()
Public arrKlicks()
Public arrCTR()
Public arrCPC()

hey manuel

thanks for the suggestion, this works!

Is there a reason you are choosing to use RhinoScript instead of python for this? Just wondering.

From the RhinoScript help file:

All script subroutines, functions, classes and global variables that are loaded into the loaded into the memory of the VBScript interpreter will remain in memory for the duration of the modeling session, unless the “Reinitialize script engine when opening new models” scripting option is enabled. This can be problematic when developing scripts that declare global constants or class definitions for these types of expressions can only be loaded once during a scripting session. When you try load a script that contains these types of declarations, you will receive a “Name redefined” VBScript runtime error.

To work around this limitation, you can simply open a new model if the “Reinitialize script engine when opening new models” scripting option is enabled. But, opening new models is not always a practical solution.

You can also run the ResetRhinoScript command. Note, when either one of these techniques is used, all script subroutines, functions, classes and variables loaded during the scripting session will be erased.

Note, the ResetRhinoScript command should only be used during the development and debugging of scripts. It should not be used a method for cleaning up after scripts for this command will erase all scripting data, not just your scripting data. Also, this command does not auto-complete on the Rhino command line.

steve, there is no particular reason I use basic over python. I’m simply more familiar with basic and I generally like the language better. One advantage of python for me would be that I could use rhino3d for osx with python.

One other reason might be that so far I haven’t found an editor as nice as monkey. But please enlighten me, are there any real advantages of python over basic?

About that ResetRhinoScript command… How do I call it?

There are a couple of issues I have with the EditPythonScript editor in Rhino, but overall, I find it is as good as EditScript (Monkey) or better… The detail in the debugger is fantastic, especially once you are working in RhinoCommon. The major problem is that it is not available for Mac yet.


you’re right of course editScript is almost as nice as monkey. But the code is definitely more readable in monkey, especially because you can collapse methods…

In the same way you can collapse Functions and Subroutines in Monkey, you can collapse function definitions and classes in the Python editor…

VB is more verbose than Python, so readability overall is more like English… Python is a bit more abstract. But readability in the editor is also a function of how you write your code…


VB is more verbose, true, which is probably why I like it more. I might try python in the future, though. Am I right that python will be the language which will be more supported in the future?

Both will be supported equally as far as I know. Python of course allows you to access RhinoCommon functions whereas VBScript Rhinoscript does not (VB.net does, though); and of course, VBScripts will not run on Mac…


I’m bumping this old thread because I have the same question about using global arrays in Rhinoscript: It seems like it can’t be done without disabling error checking, is this correct?

The “On Error Resume Next” just disables error checking without dealing with the problem of how to use an array with a global scope in Rhinoscript, isn’t that right?

I have written a set of Rhinoscripts which automate the generation of CNC toolpaths using madCAM and I am able to calculate the maximum cut depths for each tool.

It would be really handy to have a global array of tool lengths which can be modified by my various tool path scripts whenever they generate a deeper cut for that tool than the previous script.

Hi everyone,

Same as LeoPerdersen, I also face the same issue with global arrays. To my knowledge, the rhinoscript 101 edition dos not deal with this issue, and it would be great to have a chapter on this !

For the time being I will try and use Helvetosaur solution.

One question though : can runtime user data be of any help to store public arrays ?


Hi Dale,

Do you have any documentation that gets more into details with exactly what you are explaining in this post ?

Just like the Rhinocript 101 but focused around dialoging between svereal scripts and storing global variables ?

Thaks for your help,