Results 1 to 7 of 7

Thread: Should be easy for megatron

  1. #1
    egiggey
    Guest

    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

  2. #2
    egiggey
    Guest
    Anyone ?

  3. #3
    gaffa
    Guest
    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

  4. #4
    Aurilus
    Guest
    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

  5. #5
    gaffa
    Guest
    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

  6. #6
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    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

  7. #7
    egiggey
    Guest
    Looks like it was easy for a couple of ppl...read this and never do it again
    actualy chris megatron has only answer one question of mine before the reason I did the thread this way was to challenge people to prove me wrong both gaffa and Aurilus gave damn good replies but after 5 or six times asking the same question and never getting a response I chose this tactic and look whta I got two very goos responses so if it anyoyes you for me to do this I apologize but I have to have this project done by wed morning and this was my last effort to get help on the only part of this project that has had me stuck for over 2 weeks. A quick question How long have you been programming in vb? I know I only have for 6 months and the only time I post here is when I absolutly cannot figure it out. (Rant Rant)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width