By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,703 Members | 1,400 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,703 IT Pros & Developers. It's quick & easy.

Array question

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
cLengths.GetUpperBounds()

Chris

"HLong" <an*******@discussions.microsoft.com> wrote in message
news:03****************************@phx.gbl...
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.

Nov 21 '05 #2

P: n/a
"HLong" <an*******@discussions.microsoft.com> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 21 '05 #3

P: n/a
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
Nov 21 '05 #4

P: n/a

Cor,

"Cor Ligthert" <no************@planet.nl> schrieb:
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
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.