|
-
Jun 26th, 2001, 06:09 PM
#1
Should be easy for megatron
heres what I need to figure out
I have 1 combobox 2 text box's
what I need to do is have a file that contains websites names then a three letter extension and the actual url kinda like a favorites list the file could be like this
www.vbforums.com | VBForums | bst
so what I would like is for the user to be able to select the site name from the combobox then populate the textbox's with there corresponding info
Thanks
-
Jun 26th, 2001, 07:00 PM
#2
-
Jun 26th, 2001, 08:41 PM
#3
you need to look at two basic concepts - the use of arrays of UDT's, or the use of the class/collection structure.
UDT's are easier to explain.
Code:
Public Type Site
Address as String
Name as String
Code as String
End Type
Private marrSites() as Site
When you load out of the file, add the lines to the array:
Code:
lIndex = UBound(marrSites)
lIndex = lIndex+ 1
Redim Preserve marrSites(lIndex)
marrSites(lIndex).Address = "www.vbforums.com"
marrSites(lIndex).Name = "vbForums"
marrSites(lIndex).Code = "bst"
Then add the items from the array into the combo, setting the combo items IteData to the index of the array item:
Code:
For lIndex = Lbound(marrSites) To Ubound(marrSites)
Combo1.AddItem marrSites(lIndex).Names
Combo1.ItemData(Combo1.NewIndex) = lIndex
Next lIndex
Then to fill the text boxes when the combo is changed, in the click event ofthe combo put:
Code:
txtName.Text = marrSites(combo1.ItemData(combo1.ListIndex)).Name
txtAddress.Text = marrSites(combo1.ItemData(combo1.ListIndex)).Address
txtCode.Text = marrSites(combo1.ItemData(combo1.ListIndex)).Code
Hope that provides a pointer inthe right direction
- gaffa
-
Jun 26th, 2001, 08:46 PM
#4
OK.. I'm pretty bored at the moment so let's see what I can whip up
Dim Z as integer, A$, Extracted() as string
Z = Freefile(1)
Open "[The Source File To Read From]" for input as #Z
Do
Line input #1,A$
Extracted() = Split(A$,"|")
Combo1.Additem Extracted(0)
Combo2.Additem Extracted(1)
Combo3.additem Extracted(2)
Loop until EOF(Z)
Close #Z
Split() just splits the line it has read from the file into multiple parts, for example it would split "www.vbforums.com|VBForums|bst"
into part 0 - "www.vbforums.com", part 1 - "VBForums", and part 2 - "bst". Note also that if you use the '|' character in other places in the line it will screw this order up. You can use other characters apart from '|' as well. 
Note how it refers to combo1, combo2, and combo3? I suggest having three combo boxes and loading all the data into them at the one time.. make combo2 and combo3 invisible if you want, and then add this code to combo1.. plz note I don't use combo boxes very often and I am not on a computer with VB installed so it may not be called Combo1_Change() ...
Private Sub Combo1_Change()
Combo2.ListIndex = Combo1.ListIndex
Combo3.ListIndex = Combo1.Listindex
Text2.Text = Combo2.Text
Text3.Text = Combo3.Text
End Sub
Hope this helps!
- Aurilus
-
Jun 26th, 2001, 09:04 PM
#5
Aurilus,
The change event of a combo fires when you change the text in a combo like you do in a text box. The click event fires when the user changes the selected item by clicking on the little down arrow.
I just noticed you're a local (in Victoria). Where abouts in Vic are you?
- gaffa
-
Jun 26th, 2001, 10:02 PM
#6
PowerPoster
Looks like it was easy for a couple of ppl...read this and never do it again
http://www.vbforums.com/showthread.p...638#post403831
-
Jun 26th, 2001, 10:15 PM
#7
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
|