Results 1 to 4 of 4

Thread: load different lines into different textboxes

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    load different lines into different textboxes

    hello,
    does anyone know how to load different lines from a file into different textboxes eg. line1 from a textfile goes into text1.text, line 2 from a file goes into text2.text and so on
    thanks

  2. #2
    PowerPoster Keithuk's Avatar
    Join Date
    Jan 2004
    Location
    Staffordshire, England
    Posts
    2,236

    Re: load different lines into different textboxes

    Well it depends on how many TextBoxes you have.
    VB Code:
    1. Dim FileIn As String
    2.  
    3. Open "C:\Your.txt" For Input As #1   ' Open file for input.
    4. Line Input #1, FileIn ' Read line of data.
    5. Text1.Text = FileIn
    6. Line Input #1, FileIn ' Read line of data.
    7. Text2.Text = FileIn
    8. Line Input #1, FileIn ' Read line of data.
    9. Text3.Text = FileIn
    10. Close #1   ' Close file.
    Keith

    I've been programming with VB for 25 years. Started with VB4 16bit Pro, VB5 Pro, VB6 Pro/Enterprise and now VB3 Pro. But I'm no expert, I'm still learning.

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: load different lines into different textboxes

    another way..
    VB Code:
    1. Dim tmp() As String
    2. Open "C:\File.txt" For Input As #1
    3.     tmp() = Split(Input(LOF(1), 1), vbCrLf)
    4. Close #1
    5. 'each line of the file is now in the array tmp()
    6. Text1 = tmp(0)
    7. Text2 = tmp(1)
    8. Text3 = tmp(2)
    9. 'etc...
    10.  
    11. 'or even better
    12. 'Create an array of textboxes
    13. 'Make a new textbox.. call it txtData
    14. 'now copy & paste it back on the form.. it will ask if you want an array
    15. 'yes.. paste as many more as you need..
    16. For x = 0 To txtData.Count - 1
    17.     txtData(x) = tmp(0)
    18. Next
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2005
    Posts
    528

    Re: load different lines into different textboxes

    thanks guys
    i'll use statics one as it is shorter

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