Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

detemine existence of a dynamic array

Status
Not open for further replies.

PeterMac

Programmer
Mar 9, 2001
51
CA
Hey:

I have some cool code that builds a dynamic array based on what I find in the database. But if I get EOF from the database then I don't need the array and it is not created. Now I just need to test to see if that dynamic array exists or not and I don't know how.

I have tried this... but it is (seemingly) ignored...

If ISNULL(aSubcat) then
'meaning there are no sub-categories...
 
i suppose you must use the ubound() function:

The UBound function returns the upper limit for the number of elements in an array (the elements can be empty).

br
Gerard
 
Subscript out of range: 'UBound' is the message that I get in my code, so I want to test to see if the array even exists so that I won't have to get into that part of the code... thanks anyway... any other thoughts?

P
 
I ALWAYS
Dim array() as ???
my dynamic arrays (required in VB.Net), THEN
Redim array(0) and then store from index 1 on. That way, the array always has a Ubound that equals the count. If you can't do that then ALWAYS
Dim array() as type
and to check for existence
Code:
I = -1
On error resume next
   I = Ubound(array)
On error goto 0
If I < 0 then
....does not exist
End if
An alternative is to use a boolean indicator that you set when you actually out data in the array.
 
You can use the IsArray function:

If IsArray(aSubcat) Then

or the Vartype function:

If Vartype(aSubcat)>=8192 Then

FWIW, could you not have used the GetRows method of the ADO recordset? It provides the same functionality as the &quot;cool piece of code&quot; you describe. Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top