Magemaster
New member
- Joined
- Aug 6, 2009
- Messages
- 3
- Programming Experience
- 1-3
Hi,
I've built a quiz program that uses several arrays to store questions and answers. For debugging purposes I've inserted several msgboxes, when I remove them I get the same question in all of the question slots(same with answers) I spent a lengthy amount of time googling, and decided I needed to post.
Form2_load calls generateQuestion. If the msgbox is inside generateQuestion, the program works, if it is right after generateQuestion it works.
Code
Thanks in advance.
I've built a quiz program that uses several arrays to store questions and answers. For debugging purposes I've inserted several msgboxes, when I remove them I get the same question in all of the question slots(same with answers) I spent a lengthy amount of time googling, and decided I needed to post.
Form2_load calls generateQuestion. If the msgbox is inside generateQuestion, the program works, if it is right after generateQuestion it works.
Code
VB.NET:
Private Sub Form2_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x As Integer = 0
Dim y As Integer = 0
ReDim Questions(CInt(Home.txtNoQ.Text))
ReDim Answers(CInt(Home.txtNoQ.Text))
ReDim Presidents(CInt(Home.txtNoQ.Text))
lblQuestion2.Visible = False
txtAnswer2.Visible = False
lblQuestion3.Visible = False
txtAnswer3.Visible = False
lblQuestion1.Visible = False
txtAnswer1.Visible = False
btnSkip.Visible = False
bSubmit.Visible = False
btnYes.Visible = False
' btnYes.enalbed = False
btnNo.Visible = False
lblResults.Visible = False
'MsgBox("beginning form2 activation")
' MsgBox("begining the loop") ''filling the question array
While (x < CInt(Home.txtNoQ.Text))
y = generateRandom(1, 5) 'generate the topic
''check the topic
While (Home.questions(y) = 0)
y = generateRandom(1, 5)
End While
'fill the array with questions
generateQuestion(x, y)
MsgBox(CStr(x) & " " & CStr(y)) ''if msgbox is here the program works
x = x + 1
End While
lblQuestion1.Visible = True
txtAnswer1.Visible = True
btnSkip.Visible = True
bSubmit.Visible = True
Begin_Quiz()
'Home = Nothing
lblQuestion1.Visible = False
txtAnswer1.Visible = False
lblQuestion2.Visible = False
txtAnswer2.Visible = False
lblQuestion3.Visible = False
txtAnswer3.Visible = False
btnSkip.Visible = False
bSubmit.Visible = False
PictureBox1.Visible = False
btnYes.Visible = True
btnNo.Visible = True
lblResults.Visible = True
End Sub
VB.NET:
Private Sub generateQuestion(ByVal index As Integer, ByVal topic As Integer)
Dim pname As String
president = generateRandom(Home.txtBegin.Text, Home.txtEnd.Text)
pname = Home.ds.Tables("presidents").Rows(president).Item(1)
Presidents(index) = president
Select Case topic
Case 1
Questions(index) = "Who is this?"
Answers(index) = pname
Case 2
Questions(index) = "What year was " + pname + " elected?"
Answers(index) = Home.ds.Tables("presidents").Rows(president).Item(3)
Case 3
Questions(index) = "How many terms did " + pname + " serve?"
If (IsDBNull(Home.ds.Tables("presidents").Rows(president).Item(5))) Then
Answers(index) = 1
Else
Answers(index) = 2
End If
Case 4
If (IsDBNull(Home.ds.Tables("presidents").Rows(president).Item(5))) Then
Questions(index) = "Who was " + pname + "'s Vice President?"
Answers(index) = Home.ds.Tables("presidents").Rows(president).Item(4)
Else
Questions(index) = "Who were " + pname + "'s Vice Presidents?"
Answers(index) = Home.ds.Tables("presidents").Rows(president).Item(4) + " and " + Home.ds.Tables("presidents").Rows(president).Item(6)
End If
Case 5
Questions(index) = "What party was " + pname + " in when he was elected?"
Answers(index) = Home.ds.Tables("presidents").Rows(president).Item(2)
End Select
' Home.Label1.Text = (Questions(index))
End Sub
Thanks in advance.