Welcome to Dream.In.Code
Getting VB Help is Easy!

Join 136,443 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 2,312 people online right now. Registration is fast and FREE... Join Now!




2D Array

 
Reply to this topicStart new topic

2D Array

GrahamPaul
19 Dec, 2007 - 01:34 PM
Post #1

New D.I.C Head
*

Joined: 9 Dec, 2007
Posts: 9


My Contributions
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!Type

Here 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!
User is offlineProfile CardPM
+Quote Post

ahmad_511
RE: 2D Array
19 Dec, 2007 - 03:21 PM
Post #2

D.I.C Regular
Group Icon

Joined: 28 Apr, 2007
Posts: 351



Thanked: 8 times
Dream Kudos: 400
My Contributions
is the Type field in Theory table a number? and integer?
if it's string and looks like a number, you should use Val or Cint to convert it into Integer number
CODE

Types(2, a) = Cint(Theory!Type)


This post has been edited by ahmad_511: 19 Dec, 2007 - 03:22 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 02:13PM

Live VB Help!

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month