Results 1 to 3 of 3

Thread: Listbox woes...

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Albany, OR, United States
    Posts
    10

    Post

    I'm farily new to the VB programming scene
    so please don't laugh at me if this questions seems too simple to you...it's been driving me insane!

    The problem is this: (I'll try to explain this the best I can, but it probably won't be very good)
    I have a form with a listbox on the left, and some text boxes on the the right. When I first load up the form it retrieves some data from a text file and adds the name of the person for whome this data is for into the listbox. I then am able to click on the name in the listbox, and have the data that goes along with the name show up in the text boxes on the right. I'm using variable arrays to do this ie It's using the index number of the items in the listbox to decided which variables should go where. THE PROBLEM IS, since I have the listbox sorted alphabetically I'm having the wrong information show up for the different names.
    (Ex. The data for John Doe is showing up when I click on Jane Doe)

    Well I hope this was clear enough...if it wasn't, please let me know, because I've spent countless hours trying to figure it out. I must fix it! =)

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    When you fill the Listbox you could assign an Incremental value to the ItemData Property of the Item, then use this as the Index for the Array, ie.

    Code:
    Private iIndex As Long
    Private sDataArray() As String
    
    Private Sub Form_Load()
        'Load Text File
        While LOF(iFileNum)
            'Get the Persons Name from the File Here
            List1.AddItem sName
            List1.ItemData(List1.NewIndex) = iIndex
            ReDim Preserve aDataArray(iIndex)
            sDataArray(iIndex) = "Whatever"
            iIndex = iIndex + 1
            'Loop until all Names are added
        Wend
    End Sub
    
    Private Sub List1_Click()
        Text1 = sDataArray(List1.ItemData(List1.ListIndex))
    End Sub

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]
    Certified AllExperts Expert

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2000
    Location
    Albany, OR, United States
    Posts
    10

    Post

    Thank you for your response...
    I appreciate it!

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