vbMarkO Posted August 24, 2006 Posted August 24, 2006 (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 August 24, 2006 by vbMarkO Quote Visual Basic 2008 Express Edition!
Cags Posted August 24, 2006 Posted August 24, 2006 Instead of a count property arrays of this type have a length property. licArr.LengthIncidently you can probably add the strings to the combobox whilst avoiding the need to know the length.cboLicense.AddRange(licArr) Quote Anybody looking for a graduate programmer (Midlands, England)?
vbMarkO Posted August 24, 2006 Author Posted August 24, 2006 Thanx, I chose the addrange method and it worked just great. This is Resolved vbMarkO Quote Visual Basic 2008 Express Edition!
Leaders snarfblam Posted August 24, 2006 Leaders Posted August 24, 2006 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 Quote [sIGPIC]e[/sIGPIC]
jayy66 Posted August 31, 2006 Posted August 31, 2006 You could try licArr.Items.Count That worked for me. Quote
Leaders snarfblam Posted August 31, 2006 Leaders Posted August 31, 2006 On an array? Or an arraylist/generic list? We are talking about normal arrays. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.