Hi,
I use these two sub procedures to read and write data into a textfile:
Sub readrecord()
'Declare Variables
Dim intcounter As Integer
'Reads how many Records are in file
intNumberofRecords = filereader.ReadLine
ReDim QuestionArray(intNumberofRecords)
intcounter = 0
Do Until filereader.EndOfStream = True
intcounter = intcounter + 1
'reads each line for each variable
QuestionArray(intcounter).strQuestionID = filereader.ReadLine
QuestionArray(intcounter).strQuestion = filereader.ReadLine
QuestionArray(intcounter).strAnswer1 = filereader.ReadLine
QuestionArray(intcounter).strAnswer2 = filereader.ReadLine
QuestionArray(intcounter).strAnswer3 = filereader.ReadLine
QuestionArray(intcounter).strAnswer4 = filereader.ReadLine
lstQuestions.Items.Add(QuestionArray(intcounter).strQuestion)
Loop
End Sub
'write to record sub procedure, where the record is written to file
Sub writerecord()
'declare variables
Dim intcounter As Integer
'add one onto the current number of records
intNumberofRecords = intNumberofRecords + 1
ReDim Preserve QuestionArray(intNumberofRecords)
'finds data
QuestionArray(intNumberofRecords).strQuestionID = txtQuestionID.Text
QuestionArray(intNumberofRecords).strQuestion = txtQuestion.Text
QuestionArray(intNumberofRecords).strAnswer1 = txtAnswer1.Text
QuestionArray(intNumberofRecords).strAnswer2 = txtAnswer2.Text
QuestionArray(intNumberofRecords).strAnswer3 = txtAnswer3.Text
QuestionArray(intNumberofRecords).strAnswer4 = txtAnswer4.Text
fileWriter.WriteLine(intNumberofRecords)
For intcounter = 1 To intNumberofRecords
'writes it
fileWriter.WriteLine(QuestionArray(intcounter).strQuestionID)
fileWriter.WriteLine(QuestionArray(intcounter).strQuestion)
fileWriter.WriteLine(QuestionArray(intcounter).strAnswer1)
fileWriter.WriteLine(QuestionArray(intcounter).strAnswer2)
fileWriter.WriteLine(QuestionArray(intcounter).strAnswer3)
fileWriter.WriteLine(QuestionArray(intcounter).strAnswer4)
Next
'messagebox shows with text
MsgBox("The Question has been Saved")
End Sub
and i was just wondering how i could insert the data into a data grid view using these.
the format of the data is:
QuestionID
Question
Answer1
Answer2
Answer3
Answer3
thanks,
Daniel