Results 1 to 3 of 3

Thread: [RESOLVED] Write the items in 2 textboxes onto a single line in a textfile?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Resolved [RESOLVED] Write the items in 2 textboxes onto a single line in a textfile?

    Hi there everyone. The students have been loving the vb programs on the smartboard so I thought I would make a program to help with attedance. The way it works is students come in and move their name to the sign in box and so on.

    Anyway what I need to do to finish is be able to record the data from two text boxes and store it on a single line in a single textfile.

    I usually use this code for writing from a textbox to a textfile.

    VB Code:
    1. Dim sFileText As String
    2.     Dim iFileNo As Integer
    3.       iFileNo = FreeFile
    4.           'open the file for writing
    5.       Open App.Path & "\collectedData.txt" For Output As #iFileNo
    6.     'please note, if this file already exists it will be overwritten!
    7.           'write some example text to the file
    8.       Print #iFileNo, CollectData1.text
    9.           'close the file (if you dont do this, you wont be able to open it again!)
    10.       Close #iFileNo

    As you can see I record the attendance records from CollectData1.text, but would like to record a second piece of data from a textbox called CollectData2.text, but both will be saved to a single line in a textfile.


    Would anyone be able to tell me how to write from 2 textboxes at once to the same file on the same line? Thanks so much!

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Write the items in 2 textboxes onto a single line in a textfile?

    Just separate the two by a comma in the Print statement
    Code:
    Print #iFileNo, CollectData1.Text, CollectData2.Text
    It may be easier to read the file back if you also put a comma in between the two values in the file itself
    Code:
    Print #iFileNo, CollectData1.Text; ","; CollectData2.Text
    So if CollectData1 was 'Fred Bloggs' and CollectData2 was '09:00' then it would look like
    Fred Bloggs,09:00
    in the file

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    May 2006
    Posts
    2,295

    Re: Write the items in 2 textboxes onto a single line in a textfile?

    Fantastic, thank you!

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