Results 1 to 3 of 3

Thread: [RESOLVED] ¿How to read text separated by a comma to textbox?

  1. #1

    Thread Starter
    Member Andres128's Avatar
    Join Date
    Jul 2014
    Posts
    49

    Resolved [RESOLVED] ¿How to read text separated by a comma to textbox?

    Hi friends of vbforums, need you help

    I have this text in: mytextfile.txt

    Code:
    012547, 0369875, vbforums
    054789, 5874589, vbforums125
    Now how I can read These three words read separately by coma in textboxes: example, I clic in button1 and:

    Code:
    First line:
    Texbox1.text = "012547"
    Texbox2.text = "0369875"
    textbox3.text= "vbforums"
    Second line:
    textbox4.text="054789"
    textbox5.text="5874589"
    textbox6.text="vbforums125"
    Thank you very much for your help.

    And many greetings community


  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: ¿How to read text separated by a comma to textbox?

    Does this help?
    Code:
    Public Class Form1
    
        ' array to hold 2 List Of Textbox
        Private textBoxGroup(1) As List(Of TextBox)
    
        Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            ' add our text boxes to the textBoxGroup array
            textBoxGroup(0) = New List(Of TextBox) From {TextBox1, TextBox2, TextBox3}
            textBoxGroup(1) = New List(Of TextBox) From {TextBox4, TextBox5, TextBox6}
        End Sub
    
        ' set textboxes from file
        Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
            ' load file by lines to array
            Dim filename As String = "test.txt"
            Dim lines() As String = IO.File.ReadAllLines(filename)
            ' loop thru lines
            For i = 0 To lines.Count - 1
                ' split items in this line by comma char.
                Dim items() As String = lines(i).Split({","c}, StringSplitOptions.RemoveEmptyEntries)
                ' add items to our textboxes
                For n = 0 To items.Count - 1
                    textBoxGroup(i).Item(n).Text = items(n)
                Next
            Next
        End Sub
    
    End Class

  3. #3

    Thread Starter
    Member Andres128's Avatar
    Join Date
    Jul 2014
    Posts
    49

    Re: ¿How to read text separated by a comma to textbox?

    omg Thanks you very much @Edgemeal, this working fantastic!!!

    Thanks you for you time in help me!!!

    Many greeting from Colombia, and have a nice day Brother

    jejej you are VB For Fun

    Thread Resolved

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