how to break For...next Statement loop
hello guys please help me to get out of this problem
im making quiz project but im stuck for loop
example(i have 60 array form loop.. i i can't stop the loop if the user get 5 wrong or get 40 correct..
here is the sample code
Code:
intNumberOfForms = 40
frmQuizArray = Shuffle(intNumberOfForms - 1)
For i = 0 To intNumberOfForms - 1
Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
frm.Show vbModal
Set frm = Nothing
Next i
i want to break it or insert this code but does not work.. sorry im realy noob
Code:
If quiz.markWrong = 5 then
formfail.show
elseif quiz.markCheck = 40 then
formpassed.show
else
quiz.markWrong = quiz.markWrong
quiz.markCheck = quiz.markCheck
End if
Re: how to break For...next Statement loop
Use a Exit For when you want to exit the for loop... so like this..
Code:
intNumberOfForms = 40
frmQuizArray = Shuffle(intNumberOfForms - 1)
For i = 0 To intNumberOfForms - 1
Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
frm.Show vbModal
Set frm = Nothing
If quiz.markWrong = 5 then
formfail.show
Exit For
elseif quiz.markCheck = 40 then
formpassed.show
Exit For
End if
Next i
Re: how to break For...next Statement loop
Quote:
Originally Posted by
GremlinSA
Use a
Exit For when you want to exit the for loop... so like this..
Code:
intNumberOfForms = 40
frmQuizArray = Shuffle(intNumberOfForms - 1)
For i = 0 To intNumberOfForms - 1
Set frmQuiz = Forms.Add("frmQuiz" & frmQuizArrArray(i))
frm.Show vbModal
Set frm = Nothing
If quiz.markWrong = 5 then
formfail.show
Exit For
elseif quiz.markCheck = 40 then
formpassed.show
Exit For
End if
Next i
sir thanks i try my best to understand it.. its working but sometimes its showing a debug. (object unloaded) did i mistaken using if.. else.. statement methods
Re: how to break For...next Statement loop
On what line do you get the error, and under what conditions?
Re: how to break For...next Statement loop
And you should not be using one form for each question. Place all 40 questions on one form and I think your results will be easier to accomplish and the people taking this quiz will be less likely to get lost in the forms.