|
-
Apr 5th, 2000, 11:47 PM
#1
Thread Starter
Lively Member
Hi all! I've searched thru the archives but couldn't find anything on my problem. This is SO embarassing! but I can't get this Do Loop to do what I want it to!
I’m (still) working on a test for new employees, consisting of 15 questions. The employee can check a “mark” checkbox to review any questions he has doubts about after finishing the test.
What I want to do is when the “REVIEW” command button is clicked, is to cycle thru the array of 15 questions and present the first question that has been “marked”. Then when he clicks on it again, he goes to the next “marked” question, and so on…continuing around the whole test if necessary. My code so far is this:
Do While TestArray(QuestionNumber, 5) <> "Y" ‘ ELEMENT for marked checkbox, Y means its checked
QuestionNumber = QuestionNumber + 1
Loop
Textbox2.text = TestArray(QuestionNumber, 2)
Textbox3.text = TestArray(QuestionNumber, 3)
Textbox4.text = TestArray(QuestionNumber, 4)
Textbox5.text = TestArray(QuestionNumber, 5)
Check1.Value = vbChecked
QuestionNumber = QuestionNumber + 1
What I WANT to happen is that the user will “cycle” thru the test seeing every q uestion he has marked, from the first to the last. BUT I keep getting out of bounds error, i.e. QuestionNumber ends up being higher than 15 so it bombs out! Any ideas from you DO Loop experts(obviously, which I am not <sg>).
-
Apr 6th, 2000, 01:04 AM
#2
why are you using a do loop to go through an array of known size? that is what for...next loops are for
Code:
For i = 0 to 15 'or 1 to 15 depending on your program
'perform tests on the array(i, 5) element
Next i
[Edited by wossname on 04-06-2000 at 02:05 PM]
-
Apr 6th, 2000, 01:41 AM
#3
Thread Starter
Lively Member
because...
>why are you using a do loop to go through an array of known size? that is what for...next loops are for
Because the For Next loop won't keep track of the question number in between executions of the review command button!
example: the user has marked questions 4, 7, and 10
the first time the review button is clicked, the do loop should run from questionnumber 1 to 4 before "falling" out and showing question 4. THEN when the review button is clicked again, the do loop should run until the questionnumber is 7 and so on. You CAN'T do this with a For Next loop AFAIK. The user HAS to have the ability to, in effect, stop the program while he reviews his marked questions, then start it again. But thanks for the answer!
-
Apr 6th, 2000, 02:56 AM
#4
Addicted Member
Instead of checking the value of your question for your loop condition use a boolean variable that you set whithin your loop.
done = false
Do While (not done and QuestionNumber < 15)
if TestArray(QuestionNumber, 5) = "Y" then
done = true
endif
loop
You may have to modify this slightly but I believe the general concept should work 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|