Solved

Filling Combo Boxs with Arrays

Posted on 2001-07-09
10
361 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
 

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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now