Page 1 of 1

Read/Split

Posted: Fri Jun 06, 2014 7:46 am
by Dummy1912
Hello,

can anyone give us a great sample for reading a file and split the all lines with a char?

so the files will has for example:
0|test|test

and we wanna split it to add them in separated textboxen

we have this but no idea how to use it with a file to read
so this must be used aswell.
anyone please?
Code: Select all
Dim data As String = Nothing
                Using reader As StreamReader = New StreamReader(ReadFile)
                    Do While Not reader.EndOfStream
                        data &= vbNewLine & reader.ReadLine
                    Loop
                End Using

                For Each codePart As String In data.Split("|")
                    If (codePart.Trim).Length > 0 Then
'here it will be all transfered to split them in text boxen
End If
thank you

Re: Read/Split

Posted: Fri Jun 06, 2014 8:23 am
by XTechVB
You mean something like this?
Code: Select all
        Using OPF As OpenFileDialog = New OpenFileDialog()
            If (OPF.ShowDialog() = Windows.Forms.DialogResult.OK) Then
                For Each TextLine As String In IO.File.ReadAllText(OPF.FileName).Split("|")
                    If (TextLine.Trim().Length > 0) Then
                        'Do what ever you want with the line
                    End If
                Next
            End If
        End Using

Re: Read/Split

Posted: Fri Jun 06, 2014 8:51 am
by Dummy1912
hello #XTechVB

well it seems it does nothing :(
i mean it doesn't add them into the text boxen
Code: Select all
For Each TextLine As String In IO.File.ReadAllText(OPF.FileName).Split("|")
                    If (TextLine.Trim().Length > 0) Then
                         AddTextbox(TextLine.Trim)
                         'Do what ever you want with the line
                    End If
                Next

Code: Select all
Public Sub AddTextbox(ByVal text As String)
Dim index As Integer = 0
        Dim Array_ As TextBox() = New TextBox() {Me.e1, Me.e2, Me.e3}
Dim box As TextBox
        For Each box In Array_
            box.Text = text(index)
 index += 1
            Application.DoEvents()
        Next


Re: Read/Split

Posted: Fri Jun 06, 2014 9:01 am
by XTechVB
Can you post the full code for the "AddTextbox" function? or send it via pm?

Re: Read/Split

Posted: Fri Jun 06, 2014 12:16 pm
by Dummy1912
Thanks #XTechVB
i fix it
was my fault with your code :lol:
+rep