Solved

Filling Combo Boxs with Arrays

Posted on 2001-07-09
10
363 Views
Last Modified: 2009-12-16
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.
0
Comment
Question by:mutrus
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:andysalih
ID: 6267965
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
 
LVL 3

Expert Comment

by:andysalih
ID: 6267969
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
 
LVL 8

Expert Comment

by:glass_cookie
ID: 6267993
HI!

Here's a file over the net for you:

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

glass cookie : )
0
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 

Author Comment

by:mutrus
ID: 6268390
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

Sub Form_Load()
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
    cboList1.AddItem sTmpArray(i)
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 Comment

by:mutrus
ID: 6268438
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

Sub Form_Load()
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
    cboList1.AddItem sTmpArray(i)
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
    cboList2.AddItem sList2A(i)
Next i

For i = 0 to 25
   cboList3.AddItem sList3A(i)
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
            cboList2.AddItem sList2A(i)
        Next i

        For i = 0 To 25
            cboList3.AddItem sList3A(i)
        Next i
    Case "B"
        For i = 0 To 35
            cboList2.AddItem sList2B(i)
        Next i

        For i = 0 To 25
            cboList3.AddItem sList3B(i)
        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????

help please




0
 

Author Comment

by:mutrus
ID: 6268450
Oops - please ignore my first comment as I hit the submit button before I finished the comment

0
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6268514
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
    cboList2.AddItem sList2(i)
Next i

For i = 0 To 25
    cboList3.AddItem sList3(i)
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
 
LVL 9

Expert Comment

by:Valliappan AN
ID: 6268520
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
 
LVL 9

Accepted Solution

by:
Valliappan AN earned 200 total points
ID: 6268523
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
 

Author Comment

by:mutrus
ID: 6271758
I had to do a bit of tweaking but got it in the end

Thanks

0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question