I am trying to store words and numbers in a 2D array with the intention of displaying them in a list box however when I execute the program it says 'Error 13 - Type Mismatch' and highlights
Types(2, a) = Theory!TypeHere is the code
CODE
Option Explicit
Option Base 1
Dim QuestionDB As DAO.Database
Dim QuestionTable As DAO.Database
Dim Theory As DAO.Recordset
Dim questionnumber As Integer
Dim filename As String
Dim UserAnswer As String
Dim RealAnswer As String
Dim Chosen As String
Dim Mark As Integer
Dim Text As Integer
Dim Types(2, 15) As Integer
Dim a As Integer
Dim row_index
Dim column_index
Private Sub ArrayDimension()
a = 1
For row_index = 1 To a
For column_index = 1 To 2
Types(row_index, column_index) = 0
Next column_index
Next row_index
End Sub
Private Sub cmdHelp_Click()
Load frmHelpQuestions
frmHelpQuestions.Show
frmQuestion.Hide
End Sub
Private Sub cmdNext_Click()
'This will compare the users' answer and add one to their score (mark)
'It will also clear the labels and load the next ones
Call ArrayDimension
lblHeading.Caption = " "
LabelQuestion.Caption = " "
LabelA.Caption = " "
LabelB.Caption = " "
LabelC.Caption = " "
LabelD.Caption = " "
lblHeading.Caption = "Question " & questionnumber & " out of 15"
If UserAnswer = Theory!Answer Then
Mark = Mark + 1
MsgBox "Well done! That is correct. ", vbInformation, "Correct"
Else
Types(1, a) = questionnumber
Types(2, a) = Theory!Type
a = a + 1
MsgBox Theory!Explanation, vbExclamation, "Incorrect"
End If
Theory.MoveNext
Call Datafill
End Sub
Private Sub cmdRetry_Click()
lblHeading.Visible = True
LabelQuestion.Visible = True
LabelA.Visible = True
LabelB.Visible = True
LabelC.Visible = True
LabelD.Visible = True
OptionA.Visible = True
OptionB.Visible = True
OptionC.Visible = True
OptionD.Visible = True
lblA1.Visible = True
lblA2.Visible = True
LBLA3.Visible = True
lblA4.Visible = True
cmdNext.Visible = True
cmdRetry.Visible = False
cmdResult.Visible = False
lblScore.Visible = False
Theory.MoveNext
questionnumber = 1
Mark = 0
Call Datafill
Call ArrayDimension
End Sub
Private Sub Form_Load()
'This will display the first question number
'It also loads the database
questionnumber = 1
lblHeading.Caption = "Question " & questionnumber & " out of 15"
filename = "G:\Advanced Higher Computing\Project\Program\Questions.mdb"
Set QuestionDB = DAO.OpenDatabase(filename)
Set Theory = QuestionDB.OpenRecordset("QuestionTable", dbOpenDynaset)
Theory.MoveFirst
Call Datafill
End Sub
Private Sub Datafill()
'This will fill each label which the appropriate text from the database
'Until the 15th question has been reached
lblScore.Visible = False
cmdResult.Visible = False
cmdRetry.Visible = False
cmdResult.Visible = False
lblScore.Visible = False
lblHeading.Caption = " "
cmdNext.Visible = True
lblHeading.Caption = "Question " & questionnumber & " out of 15"
LabelQuestion.Caption = Theory!Question
LabelA.Caption = Theory!a
LabelB.Caption = Theory!b
LabelC.Caption = Theory!C
LabelD.Caption = Theory!D
questionnumber = questionnumber + 1
If questionnumber = 17 Then
lblHeading.Visible = False
LabelQuestion.Visible = False
LabelA.Visible = False
LabelB.Visible = False
LabelC.Visible = False
LabelD.Visible = False
OptionA.Visible = False
OptionB.Visible = False
OptionC.Visible = False
OptionD.Visible = False
lblA1.Visible = False
lblA2.Visible = False
LBLA3.Visible = False
lblA4.Visible = False
cmdNext.Visible = False
cmdRetry.Visible = True
cmdResult.Visible = True
lblScore.Visible = True
lblScore.Caption = "You have scored " & Mark & " out of 15"
End If
End Sub
Private Sub cmdResult_Click()
Load frmResults
frmResults.Show
frmQuestion.Hide
End Sub
Private Sub lblExit_Click()
End
End Sub
Private Sub OptionA_Click()
'This will make the users answer equal to A
UserAnswer = "A"
End Sub
Private Sub OptionB_Click()
'This will make the users answer equal to B
UserAnswer = "B"
End Sub
Private Sub OptionC_Click()
'This will make the users answer equal to C
UserAnswer = "C"
End Sub
Private Sub OptionD_Click()
'This will make the users answer equal to D
UserAnswer = "D"
End Sub
Many thanks!