how to test if an array has been dimensioned

D

djc

I have a dynamic array that could be used in several different places. I
need to test if it has been dimensioned yet using the ReDim statement before
taking an action in several places.

I know I could declare the array as a variant and use the IsEmpty() function
but I really only need an array of short strings. I understand variants
would take up much more memory. How could I do this if the array is of type
string? len(arrayVar())? len(arrayVar(0))? It may not be dimensioned yet
though.

please enlighten me.
 
R

Ronald W. Roberts

djc said:
I have a dynamic array that could be used in several different places. I
need to test if it has been dimensioned yet using the ReDim statement before
taking an action in several places.

I know I could declare the array as a variant and use the IsEmpty() function
but I really only need an array of short strings. I understand variants
would take up much more memory. How could I do this if the array is of type
string? len(arrayVar())? len(arrayVar(0))? It may not be dimensioned yet
though.

please enlighten me.

Look at UBound and LBound in help.

Ron
 
D

djc

<embarassed> oh ya. </embarassed> Thanks!


Ronald W. Roberts said:
Look at UBound and LBound in help.

Ron
--
Ronald W. Roberts
Roberts Communication
(e-mail address removed)
To reply remove "_at_robcom_dot_com"
 
D

djc

using Ubound on an array before redimming it with a number gives a
'subscript out of range' runtime error.
1) do I have to just use this and test for the error condition?

2) I have no option Base statement so all my arrays should start with
subscript 0. Why then did this work:
dim TestArray()

ReDim TestArray(1) 'should be array for 1 value at subscript 0
TestArray(0) = ";lakjdfkjd"
TestArray(1) = ";lakjdkfjasdkfj"

this (above) worked with no errors? should have been out of range right?

3) if array is dimmed or redimmed as ArrayName(10) the ubound should return
10 right? and it should be subscripts 0 - 9 right????

I need to be able to test if my array was used yet on a formload event and
take different courses of action depending on that. (its a publicly dimmed
array var) Having problems and confusing myself on things I thought I new 8
years ago about VB and arrays!

guidance anyone?


That should be a subcript out of range error but it worked????
 

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