Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

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...

 

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

 

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

Edited by vbMarkO
Visual Basic 2008 Express Edition!
Posted
Instead of a count property arrays of this type have a length property.
licArr.Length

Incidently you can probably add the strings to the combobox whilst avoiding the need to know the length.

cboLicense.AddRange(licArr)

Anybody looking for a graduate programmer (Midlands, England)?
  • Leaders
Posted

Just to offer an alternative for anyone who stumbles in, there is also always the for each loop.

Dim Things As String() = {"cow", "jumps", "over", "moon"}

For Each Thing As String In Things
   SomeComboBox.Add(Thing)
Next

[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...