I am trying to create a system that allows the user to add exam questions to file for later retrieval. I have declared a record with the following fields:
Structure recQuestion
Public fldQuestion As String
Public fldAnswer As String
Public fldPicture As PictureBox
Public fldExamName As String
Public fldExamNumber As Integer
Public fldMark As Integer
End Structure
Public oneExamQuestionRecord As recQuestion
I then have a form which allows the user to add the details to the various textboxes; the question, the answer and so on and also includes a facility to allow the user to select and display an image in the picturebox.
To add the details to file I have created a button (btnAdd) with the following code:
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Dim testFileName As String = CurDir() & "/testFile.dat"
With oneExamQuestionRecord
.fldAnswer = txtAnswer.Text
.fldExamName = txtExamTitle.Text
.fldExamNumber = CInt(txtExamNumber.Text)
.fldMark = CInt(txtMark.Text)
.fldPicture.Image = PictureBox1.Image
.fldQuestion = txtQuestion.Text
End With
I get the below error message:
"Object reference not set to an instance of an object"
when the below line is being executed:
.fldPicture.Image = PictureBox1.Image
Any suggestions?