我正在尝试创建一个系统,允许用户将考试问题添加到文件中以供日后检索。我已声明了包含以下字段的记录:
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
然后我有一个表单,允许用户将细节添加到各种文本框中;问题,答案等等,还包括一个允许用户在图片框中选择和显示图像的工具。
要将详细信息添加到文件,我创建了一个按钮(btnAdd),其中包含以下代码:
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
我收到以下错误消息:
"Object reference not set to an instance of an object"
执行以下行时:
.fldPicture.Image = PictureBox1.Image
有什么建议吗?