[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:
Dim sFileText As String
Dim iFileNo As Integer
iFileNo = FreeFile
'open the file for writing
Open App.Path & "\collectedData.txt" For Output As #iFileNo
'please note, if this file already exists it will be overwritten!
'write some example text to the file
Print #iFileNo, CollectData1.text
'close the file (if you dont do this, you wont be able to open it again!)
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!
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
Re: Write the items in 2 textboxes onto a single line in a textfile?