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.
Printable View
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.
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
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?
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
:)
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.
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