Reading Data back into Text Boxes from a text file

  • 13 years ago

     Hi all,

    I'm sure that most of you will find this really easy.

    I have a form that has 6 text boxes on it.  I have been able to read the data to a text file (test.txt) without too many problems.  What I want to do now is Open the Txt file and read the data back into the relevant text box's.  Everything I have found so far seems to read the data into 1 text box.

    Any help would be greatly appreciated

    Tim 

  • 13 years ago

    Hi Tim,

    I'm not sure if this can solve your problem.

    To write to a text file you need to write this code (I'm sure you know this very well):

        Open App.Path & "\test.txt" For Output As 1
            Print #1, Text1.Text; " ~ "; Text2.Text; " ~ "; Text3.Text; " ~ "; Text4.Text; " ~ "; Text5.Text; " ~ "; Text6.Text
        Close #1

    In between two text box I put '~' in order for me to easily split the text afterward

    Next you said you want to read it and put it back to it relevant text box, here what I've done:

    Dim s
    Dim textfile As String
    Dim strArray() As String

    Open App.Path & "\try1.txt" For Input As 1
    Do While Not EOF(1)
        Line Input #1, textfile
        strArray = Split(textfile, " ~ ")
        For s = 0 To UBound(strArray)
        If Not Trim(strArray(i)) = "" Then
        Text1.Text = strArray(i)
        Text2.Text = strArray(i + 1)
        Text3.Text = strArray(i + 2)
        Text4.Text = strArray(i + 3)
        Text5.Text = strArray(i + 4)
        Text6.Text = strArray(i + 5)
        End If
        Next
    DoEvents
    Loop
    Close #1

    Hope this can solve your problem.

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The most exciting phrase to hear in science, the one that heralds new discoveries, is not 'Eureka!' but 'That's funny...'” - Isaac Asimov