How do I count this array?

vbMarkO

Centurion
Joined
Aug 19, 2005
Messages
157
I added string items to an array then tried to do a for loop to count the number of items so I could add the items to a combobox

This is what I have...

Visual Basic:
Dim licArr() As String = {"Item1", "Item2", "Item3" -
                                 "Item4", "Item5", "Item6"}
' Now I want to count the number of items added to this array

For i As Integer = 0 To licArr.Count - 1 ' However there is no .Count available
' It wont let me do this  WHY?
' and how can I get this done?
'          WHat I hope to do is this
cboLicense.Items.Add(licArr(i))


Next

So what am I doing wrong... why isnt their a .count option for this string array?

I guess I could do this like this but I still want to know how to count that array if possible

Visual Basic:
For i As Integer = 0 To 4
  cboLicense.Items.Add(licArr(i))  ' This will work fine I know but
' but I was wondering how I might make it doing a count incase I need to add
' more Items later
Next

vbMarkO
 
Last edited:
Instead of a count property arrays of this type have a length property.
Visual Basic:
licArr.Length
Incidently you can probably add the strings to the combobox whilst avoiding the need to know the length.
Visual Basic:
cboLicense.AddRange(licArr)
 
Just to offer an alternative for anyone who stumbles in, there is also always the for each loop.
Visual Basic:
Dim Things As String() = {"cow", "jumps", "over", "moon"}
 
For Each Thing As String In Things
    SomeComboBox.Add(Thing)
Next
 
Back
Top