Array question

  • Thread starter Thread starter HLong
  • Start date Start date
H

HLong

I have an array defined as Dim cLengths() as long. How
could I test to see if the array is not empty. When I try

For I=0 to Ubound(cLengths)
.......
Next I

It gives me an error if it is empty.
 
HLong said:
I have an array defined as Dim cLengths() as long. How
could I test to see if the array is not empty. When I try

For I=0 to Ubound(cLengths)
.......
Next I

It gives me an error if it is empty.

\\\
If IsArray(Lengths) Then
...
End If
///
 
HLong,

I never use that Ubound

I use forever in an inedexed loop for an array or a collection

for i as integer = 0 to array.length - 1 or collection.count -1
.....................
Next

I hope this helps,

Cor
 
Cor,

Cor Ligthert said:
I never use that Ubound

I use forever in an inedexed loop for an array or a collection

for i as integer = 0 to array.length - 1 or collection.count -1
....................
Next

This won't solve the problem. Still, a 'NullReferenceException' is thrown
if the array variable doesn't point to an array object. Consequently you'll
have to check if an array has been assigned prior to iterating over the
array's items and determining its length:

\\\
If IsArray(Lengths) Then
...
End If
///

- or -

\\\
If Not Lengths Is Nothing Then
...
End If
///
 

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

Back
Top