|
-
Dec 7th, 2002, 07:33 PM
#1
Thread Starter
Lively Member
Populating a ComboBox
Hi,
I have an array of user defined types i.e. newArray(10) how do I populate a ComboBox with this information?
thanks,
A Student.
-
Dec 7th, 2002, 07:38 PM
#2
Fanatic Member
basically . . .
VB Code:
Sub LoadCombo()
Dim i As Integer
Combo1.Clear
For i = 0 To 9
Combo1.AddItem newArray(i)
Next i
End Sub
but you said it was a user defined type and didn't say what part of the variable you wanted to add
. . . anyway that should get you started
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
-
Dec 7th, 2002, 07:56 PM
#3
Thread Starter
Lively Member
My code goes like this:
[Highlight=VB]
Private Sub Form_Load()
Dim i As Integer
cmbPeople.Clear
For i= 0 To iTotalPeople 'iTotalPeople is a global variable
cmbPeople.AddItem (auPeople(iTotalPeople).Name)
Next i
End Sub
This gives me a 'subscript out of range' error.
Any suggestions?
-
Dec 7th, 2002, 08:01 PM
#4
You need to make sure that the counter in your For loop doesn't pass the upper boundary of the array.
Something like...
VB Code:
Private Sub Form_Load()
Dim i As Integer
cmbPeople.Clear
For i= 0 To UBound(auPeople) 'UBound returns the upper boundary of the array
cmbPeople.AddItem (auPeople(i).Name)
Next i
End Sub
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Dec 7th, 2002, 08:08 PM
#5
Thread Starter
Lively Member
This code only returns one value at a time in the ComboBox. There will be a list however only the name of the last person will appear.
-
Dec 7th, 2002, 08:36 PM
#6
Fanatic Member
What crptcblade was saying you have to remember that your arrays upper bound is not the same as the number of items in the array (iTotalPeople )
If you have 30 people in the array and iTotalPeople = 30 then your code would fail. The array starts at 0 so the subscripts would be 0 to 29 not 0 to 30.
try . . .
VB Code:
For i= 0 To iTotalPeople - 1 'iTotalPeople is a global variable
"Look! Up in the sky! It's a bird! It's a plane! It's Diaper-Head Boy! (there by my name!) Yes, Diaper-Head Boy, who disguised as my son, Seth, fights a never-ending battle for truth, justice and terrorizing my house!
Resistance is futile, you will be compiled . . . Please!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|