Counting members in array? (<=>not the length)

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
Hi,
is there any way that I can count the number of elements in an array? methods Length & Get Upperbounds return the length of the array (=how many elements could I place in the array), not how many places are allready taken....

Niko
 

Wirloff

Member
Joined
Mar 2, 2005
Messages
19
Location
Belgium
Programming Experience
1-3
No such method with arrays :s

I'm afraid there's no such method to use with arrays :(...
I know trying to solve it with indexof method (and look for empty elements..)but I still wonder if there is no other way..:s
 

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,524
Location
Lansing, MI; USA
Programming Experience
10+
VB.NET:
Dim Element as String  'Assuming this is a string array
Dim intCounter as Integer = 0

For Each Element in strArray
  intCounter += 1
Next Element
and when it's done there ya go, the number of elements in your array have been counted

to not count empty elements:
VB.NET:
 Dim Element as String  'Assuming this is a string array
 Dim intCounter as Integer = 0
 
 For Each Element in strArray
  If Element <> "" Then
	   intCounter += 1
  End If
 Next Element
 
Last edited:

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
Personally I'd use an arraylist.

TPM
 
Top Bottom