Do Until Error

Zaeed

Registered Annoyance
Local time
Tomorrow, 01:47
Joined
Dec 12, 2007
Messages
383
Array Out Of Bounds Error

is it possible to run a do loop until an error arrises?

My situation is this, I have an array that is set from a function, the size of the array varies.
What I want to do is run a loop that increments through the array until it hits an out of bounds error.

can it be done?
 
Last edited:
hmm, it seems that wasnt my problem...

On the load form, it runs the function that gets an array
If changes are made to a control that is set from the array, and the user hits cancel, then the array is used to undo changes made to the table.

Whats happening is array(0) is faulting with the 'subscript out of bounds' error

the array is defined as Private array() as string above all subs.
I know that it is not empty since it is used to fill a control on Load

any ideas?
 
Last edited:
My situation is this, I have an array that is set from a function, the size of the array varies.
What I want to do is run a loop that increments through the array until it hits an out of bounds error.
RuralGuy is exactly right; put a conditional line with your DO statement that checks the upperbound:
Code:
Upperbound(ArrayName, dimension)
Is this thread a carryover from the last one of yours about that dynamic array problem inside a recordset?

I'll make you a deal Zaeed....you provide a solution to my Windows Timer Event, and I'll write you a personalized tutorial on the usage of recordsets with Access. Deal? :)
 
ROFL... I'll look into it

this is a new problem Adam :)

The problem doesnt seem to be to do with an upperbound.

My function getLocation returns an array based on parameters.
My form when loading runs this function and gets an array back, the first element of the array is a string used for display i.e. a, b, c then array(1) = a, array(2) = b, etc
I have a control that gets set to array(0), this works fine
If a change is made to that control (the control links of to another form so please don't suggest isDirty) and the user then clicks Cancel, I use the array to reset the table that the array is based on.

My issue is when the cancel sub runs, it pings array(0) as being out of bounds. This only happens though if a change is made to the control. Tis most weird.
 
Last edited:
just fishing generally, but if the array is declared private, perhaps it is out of scope in the proc that is producing the error, and there really isnt an array(0)

offhand i'm not sure how arrays are passed as parameters, but i thought there was something unusual about byref/byval staus of an array parameter that might cause issues

if it says out of bounds, then it must be, mustnt it
 
but it shouldn't be.
The array in the form is declared outside of the subs, then initialized within the Load sub.
array = getLocations(param1, param2)

msgbox(array(0))
this works fine within the Load sub, but to do the same thing (msgbox) in the Cancel sub gives the out of bounds error

As for it being Private, unless it is different for VBA, I assume that variable is accessible for the entire form.
 
Ok, I fixed it by declaring the array in a module as a public variable.
Most odd.

btw, i'm waiting Adam
 
Global Public Variables need to be declared in standard modules and not in a form's class module. I believe that is what you were struggling against.
 
Yeah, I was coding like I was using Java. VBA seems to be a bit different in how it handles Instance Variables.
 
Yeah, and DOS is different too... :rolleyes:

Oh, and Zaeed, do you think you are entitled to that tutorial of mine now? Those links you sent to me have not proven useful (yet). I'm still in the process of working through it...

If I get it solved, you might just be hearing from me about those instructions (since I'm such a great writer). :)
 

Users who are viewing this thread

Back
Top Bottom