Variable Scope

J

JimS

I have an event procedure for a form control that steps through selected rows
of a list box and does some actions. One of the columns is multi-valued (1 or
more values separated by semicolons). I use the split() function to put the
column into an array and rifle through its values.

My issue is the array's scope. I declare it inside an if statement deeply
within a larger loop that steps through the rows.

Will the variable go out of scope (I want it to...) when it steps to the
next row in the outer "for each" loop?

If not, how do I reinitialize it so its lower and upper bounds are reset?
Does the assignment to the value of the split() function do that
intrinsically?
 
R

Rick Brandt

JimS said:
I have an event procedure for a form control that steps through
selected rows of a list box and does some actions. One of the columns
is multi-valued (1 or more values separated by semicolons). I use the
split() function to put the column into an array and rifle through
its values.

My issue is the array's scope. I declare it inside an if statement
deeply within a larger loop that steps through the rows.

Will the variable go out of scope (I want it to...) when it steps to
the next row in the outer "for each" loop?

If not, how do I reinitialize it so its lower and upper bounds are
reset? Does the assignment to the value of the split() function do
that intrinsically?

A variable declared anywhere in a VBA procedure always has procedure level
scope regardless of where in the procedure it is declared. In fact, a
variable declared inside an If-block is still instantiated even if the the
"if" test is false.

Each usage of Split() should reset the size of the array automatically.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top