Results 1 to 5 of 5

Thread: Using a combobox to read data from a .txt file

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    2

    Using a combobox to read data from a .txt file

    I have a list of my members details in a .txt file. (name, address, tel no, etc)
    I am able to view their names through a combobox.
    How would i be able to view a specific members details in text boxes by selecting their name through the combobox?
    Any help will be much appreciated, thankyou.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Using a combobox to read data from a .txt file

    Welcome to the forums.

    So, you select a name from the combo box. Then what should happen? What details do you want to view? How do you want to view them? From where are the details coming?

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2007
    Posts
    2

    Re: Using a combobox to read data from a .txt file

    Ok so you select a name from the combo box and click a button so i can edit the member, then a new form opens with multiple text boxes. I have multiple members details stored in members.txt. When i click on a persons name their details should appear in this new form in the corresponding txt boxes. I want to be able to view all the information on the file(first name, last name, date of birth, address, contact number). The names in the combo box are generated from this .txt file.
    Last edited by John108; Dec 5th, 2007 at 04:21 AM.

  4. #4
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Using a combobox to read data from a .txt file

    Here is some code to get you started. I think a list box might work better than a combo box and you only need one form. Build a text box to hold the membership data and the an array of five text boxes to view the data elements:
    Code:
    Dim MyData() As String, ListSize As Integer
    Dim LineDataArray() As String
    
    Private Sub Form_Load()
    ListSize = 2 ' One smaller than membership list
    ReDim MyData(ListSize)
    MyData(0) = "John, Jones, 1978, 13022 Franklin Street, 12345"
    MyData(1) = "Mary, Smith, 1979, 10232 Washington Street, 14895"
    MyData(2) = "Pete, Brown, 1986, 12321 Jefferson Street, 89523"
    Text1.Text = ""
    For I = 0 To ListSize
        Text1.Text = Text1.Text & MyData(I) & vbCrLf
        LineDataArray = Split(MyData(I), ",")
        List1.AddItem LineDataArray(0) & LineDataArray(1)
    Next
    List1.ListIndex = List1.ListCount - 1 ' Select most recent member
    End Sub
    
    Private Sub List1_Click()
    LineDataArray = Split(MyData(List1.ListIndex), ",")
    For I = 0 To UBound(LineDataArray)
        Text2(I).Text = Trim$(LineDataArray(I))
    Next
    End Sub
    Each time you click on a different name in the list box, a different member's data is revealed in the text box array.
    Doctor Ed

  5. #5

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