# Filling Combo Boxs with Arrays

I need to be able to fill three combo boxes with data from a text file. The data in the combo boxes needs to change depending on the item selected in the previous list.

The data comes in the following format

A TextA
B TextB
C TextC
(up to Z TextZ)
A0 TextA0
A1 TextA1
A2 TextA2
(up to A9 TextA9)
AA TextAA
AB TextAB
AC TextAC
(up to AZ TextAZ)
A Text
B Text
C Text
(up to Z TextZ)
B0 TextB0
B1 TextB1
B2 TextB2
(up to B9 TextB9)
BA TextBA
BB TextBB
BC TextBC
(up to BZ TextBZ)

and so on until the end of the alphabet

The first 26 items need to be put into the first combo box. When the user selects an item from the first combo then the second combo needs to be filled with the data that corresponds to the first letter of the item selected in the first combo i.e if "A TextA" is selected then the second combo needs to be filled with all the items from the list start with the letter "A", if "B TextB" is selected the fill the second combo with all the items starting with the letter "B" and so on

The third combo box needs to be filled with the data that follows the items in the second box e.g if the user selects the first item in the first combo box ("A TextA") then the third combo box needs to be filled with the 26 A-Z items that follow "AZ TextAZ"

Can anybody help me do this please.
###### Who is Participating?

Senior Tech ConsultantCommented:
oops, hope should be,

For x = lStart To lStart+26
sList2(x - lStart) = sTmpArray(x)
Next x

lStart = lStart + 26 + 1
For x =  lStart to lStart+36
sList3(x - lStart) = sTmpArray(x)
Next x
0

Commented:
as im at work i dont have vb on my computer but this will show you how to put it together,

you can build of this code

http://www.freevbcode.com/ShowCode.Asp?ID=189

hope this helps

cheers

andy
0

Commented:
try this one aswell,

this has a good explaination and full downloadable code for you to build from

hope this helps

cheers
andy
http://www.planetsourcecode.com/xq/ASP/txtCodeId.22727/lngWId.1/qx/vb/scripts/ShowCode.htm
0

Commented:
HI!

Here's a file over the net for you:

http://www.vb-helper.com/Howto/filelist.zip

Description: Load a ListBox using the lines in a file (3K)

Simply change the listbox to a combobox.

To fill the other combobox with the items, you may want to use the InStr() function to loop and check for an occurance of a string from the entire combobox1.

That's it!

0

Author Commented:
The problem is not loading the files. I can easily load the first 26 lines into the first listbox

I was more looking to storing the lists in arrays. I'm sorry but I think my question was not specific enough.

The first 26 items in the list start sequentially with the letters of the alpahbet e.g
A ListItem1
B ListItem2
C ListItem3 ........

The next 36 items in the list start with the character A, followed by 26 items  from A-Z. The next 36 start with the character B, followed by 26 items from A-Z. The next 36 with the character C, followed by 26 items from A-Z and so on.

The first 26 items will fill list 1

So if the user selects the first item in list 1 which is
A ListItem1

then list 2 needs to be filled with
A0
A1
A2.....
AZ
(thats lines 27 to 63)

list 3 needs to be filled with
A
B
C....
(thats lines 64 to 90

If the user selects the second entry in listbox 1 then list box 2 needs to be filled with

B0
B1
B2...
BZ
(thats lines 91-127

List box 3 needs to be filled with
A
B
C...
(thats lines 128-154

so what we end up with is that list2 and 3 are subsets of whatever is selected in list1 and the final result to the user is a 3 character code made up of the first character of each selected list item

I can do this so far with the following code

Dim i As Integer
Dim x As Integer
Static y As Integer
Dim sTmpArray() As String
Dim sList2A(35) as String
Dim sList2B(35) as String
Dim sList3A(25) as String
Dim sList3B(25) as String

(Code here which loads the entire list into sTmpArray)

For i = 0 To 25
Next i

(Code here which removes the contents of list1 from the array)

For x = 0 To 35
sList2A(x) = sTmpArray(x)
y = y + 1
Next x

For x = 0 To 25
sList2B(x) = sTmpArray(y + x)
Next x

y = y + x

For x = 0 to 35
sList3A(x) = sTmpArray(y)
y = y + 1
Next x

For x = 0 to 25
0

Author Commented:
The problem is not loading the files. I can easily load the first 26 lines into the first listbox

I was more looking to storing the lists in arrays. I'm sorry but I think my question was not specific enough.

The first 26 items in the list start sequentially with the letters of the alpahbet e.g
A ListItem1
B ListItem2
C ListItem3 ........

The next 36 items in the list start with the character A, followed by 26 items  from A-Z. The next 36 start with the character B, followed by 26 items from A-Z. The next 36 with the character C, followed by 26 items from A-Z and so on.

The first 26 items will fill list 1

So if the user selects the first item in list 1 which is
A ListItem1

then list 2 needs to be filled with
A0
A1
A2.....
AZ
(thats lines 27 to 63)

list 3 needs to be filled with
A
B
C....
(thats lines 64 to 90

If the user selects the second entry in listbox 1 then list box 2 needs to be filled with

B0
B1
B2...
BZ
(thats lines 91-127

List box 3 needs to be filled with
A
B
C...
(thats lines 128-154

so what we end up with is that list2 and 3 are subsets of whatever is selected in list1 and the final result to the user is a 3 character code made up of the first character of each selected list item

I can do this so far with the following code

Dim i As Integer
Dim x As Integer
Static y As Integer
Dim sTmpArray() As String
Dim sList2A(35) as String
Dim sList2B(35) as String
Dim sList3A(25) as String
Dim sList3B(25) as String

(Code here which loads the entire list into sTmpArray)

For i = 0 To 25
Next i

(Code here which removes the contents of list1 from the array)

For x = 0 To 35
sList2A(x) = sTmpArray(x)
y = y + 1
Next x

For x = 0 To 25
sList2B(x) = sTmpArray(y + x)
Next x

y = y + x

For x = 0 to 35
sList3A(x) = sTmpArray(y)
y = y + 1
Next x

For x = 0 to 25
sList3B(x) = sTmpArray(y + x)
Next x

For i = 0 to 35
Next i

For i = 0 to 25
Next i

cboList1.ListIndex = 0
cboList2.ListIndex = 0
cboList3.ListIndex = 0

End Sub

Sub cboList1.Click()

Dim i As Integer

cboList2.Clear
cboList3.Clear

Select Case Left\$(sboList1, 1)
Case "A"
For i = 0 To 35
Next i

For i = 0 To 25
Next i
Case "B"
For i = 0 To 35
Next i

For i = 0 To 25
Next i
End Select

cboList2.ListIndex = 0
cboList3.ListIndex = 0

End Sub

As I said this works but so far I have only just coded to trap for "A" and "B" and there are 24 more letters of the alphabet to go and if I continue on in this way that a lot of repitive coding and a lot of arrays.

Surely there is a simplier way (one that eludes me at this time) - maybe multi dimensioned arrays????

0

Author Commented:
Oops - please ignore my first comment as I hit the submit button before I finished the comment

0

Senior Tech ConsultantCommented:
Try like this:

Dim lStart, lEnd

lStart = Asc(Left(sboList1.Text,1)) - 65

lStart = (lStart * 64) + 27

For x = lStart To lStart+26
sList2(x) = sTmpArray(x)
Next x

lStart = lStart + 26 + 1
For x =  lStart to lStart+36
sList3(x) = sTmpArray(y)
Next x

For i = 0 To 35
Next i

For i = 0 To 25
Next i

You don't need multiple arrays, if I had understood properly. You only need 2 arrays to fill the last 2 lists.

Hope this helps.
0

Senior Tech ConsultantCommented:
A slight change in assigning to arrays, please check this:

For x = lStart To lStart+26
sList2(x - lStart) = sTmpArray(x - lStart)
Next x

lStart = lStart + 26 + 1
For x =  lStart to lStart+36
sList3(x - lStart) = sTmpArray(y - lStart)
Next x

0

Author Commented:
I had to do a bit of tweaking but got it in the end

Thanks

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.