For..Next loop running away.

Penfound

Active Member
Licensed User
Longtime User
I do love this game. I had a working app until I decided to add a little more functionality, as you do. Essentially the code below fetches record from a DB, which it does. When running in debug mode with a break I can see the QuestionID changing but it only displays the first chosen record and then jump to the loadlayouttopanel.

It is supposed to wait until the user has clicked on a radio button before reaching next.

I know it is probably simply but my brain is fried - can you help?

Cheers
Penfound

Sub DisplayQuestion
Dim curQuestions As Cursor
Dim QuestionID As Int
Dim CorrectAnswer As String
Dim SQLText As String
Dim TheSelectedRecord As Int
Dim QuestionCounter, SelectedQuestion As Int
For QuestionCounter = 1 To RequestedNumber
LoadLayoutToPanel("questionnaire")
QuestionID = PickAQuestion
SQLText = "SELECT * FROM Questions WHERE ID ='" & QuestionID & "'"
curQuestions = SQLQuestions.ExecQuery(SQLText)
curQuestions.Position = 0
lblQuestion.Text = curQuestions.GetString("Question")
CorrectAnswer = curQuestions.getint("Answer")
Select Case CorrectAnswer
Case 1
RadioButton1.Text = curQuestions.GetString("A1")
RadioButton1.Tag = "Correct"
RadioButton2.Text = curQuestions.GetString("A2")
RadioButton2.Tag = "Wrong"
RadioButton3.Text = curQuestions.GetString("A3")
RadioButton3.Tag = "Wrong"
Case 2
RadioButton1.Text = curQuestions.GetString("A1")
RadioButton1.Tag = "Wrong"
RadioButton2.Text = curQuestions.GetString("A2")
RadioButton2.Tag = "Correct"
RadioButton3.Text = curQuestions.GetString("A3")
RadioButton3.Tag = "Wrong"
Case 3
RadioButton1.Text = curQuestions.GetString("A1")
RadioButton1.Tag = "Wrong"
RadioButton2.Text = curQuestions.GetString("A2")
RadioButton2.Tag = "Wrong"
RadioButton3.Text = curQuestions.GetString("A3")
RadioButton3.Tag = "Correct"
End Select
lblID.Text = "No. " & QuestionID
lblScore.Text = "Score: " & s
Dim tmpTime As String
tmpTime = ShowTime/1000
lblTime.Text = tmpTime & " secs."
Next
LoadLayoutToPanel("Scoresheet")

End Sub
 

Penfound

Active Member
Licensed User
Longtime User
I solved it! Obviously for next loops re not suitable in this situation!

Changed it for If then else with a global counter updated outside of the sub.
 
Upvote 0
Top