Re: How do I get this program to ask more than one question?
- Posted by DanM Jan 04, 2009
- 2587 views
I had difficulty getting your program to run correctly for the first question,
as it blanked both question and answers in about 5-10 seconds.
I think your problem with not working for subsequent questions was in
"Next_Question", where you ran thru repaint the three windows THREE TIMES,
which looks unnecessary.
But since I couldn't figure out why it was blanking for me, I just rewrote it
as follows, using LABELS instead of CHILD WINDOWS. That doesn't give the look
you had, but it does work. (the one thing I for some reason couldn't get to work
right was blanking the "Okay" button after it was pressed, so as to just make it
visible when an answer was selected, dunno why it wouldn't stay invisible)
oh, and you'll want to use a spell checker in your final version:
APPROXAMENTALY should be approximately (I had to use spell checker to get
it right here).
-- code generated by Win32Lib IDE v0.20.1 include Win32Lib.ew without warning -------------------------------------------------------------------------------- -- Window Win constant Win = createEx( Window, "Main Window", 0, Center, Center, 800, 500, 0, 0 ) constant Group12 = createEx( Group, "", Win, 16, 8, 764, 60, 0, 0 ) constant LText11 = createEx( LText, "", Group12, 12, 8, 732, 44, 0, 0 ) setFont( LText11,"Arial",12,Normal+Bold) constant Group20 = createEx( Group, "", Win, 24, 308, 752, 112, 0, 0 ) constant LText23 = createEx( LText, "", Group20, 20, 68, 476, 32, 0, 0 ) constant LText22 = createEx( LText, "", Group20, 20, 24, 452, 28, 0, 0 ) constant Group13 = createEx( Group, "", Win, 20, 88, 760, 188, 0, 0 ) constant Okay = createEx( PushButton, "Next Question", Group20, 504, 48, 88, 28, 0, 0 ) setVisible( Okay, w32False ) constant ans2 = createEx( Radio, "", Group13, 28, 64, 148, 20, 0, 0 ) constant ans1 = createEx( Radio, "", Group13, 28, 24, 148, 20, 0, 0 ) constant ans3 = createEx( Radio, "", Group13, 28, 104, 148, 20, 0, 0 ) constant ans4 = createEx( Radio, "", Group13, 28, 144, 148, 20, 0, 0 ) --------------------------------------------------------- -------------------------------------------------------------------------------- atom correct object record sequence Data,text,key,test,keyindex,right,wrong,question,answer1,answer2,answer3,answer4,rightans integer ct,recs,line,ans, qcount,fields,RecNum question=repeat(0,5) answer1=repeat(0,5) answer2=repeat(0,5) answer3=repeat(0,5) answer4=repeat(0,5) right=repeat(0,5) qcount=5 fields = 9 Data = repeat(0,fields) constant Ver = "Version 1.0", App = "Handler Demo" ----------------------------------------------------------------------------- -- @ LOAD QUESTIONS -- Final program will load questions and answers from disk file ----------------------------------------------------------------------------- procedure LoadQuestions() question[1]="WHO IS BURIED IN GRANT'S TOMB?" question[2]="5 + 5 = ?" question[3]="HOW MANY TEETH DOES AN ADULT HUMAN HAVE?" question[4]="WHAT IS THE CAPITAL OF THE STATE OF FLORIDA?" question[5]="APPROXAMENTALY HOW MILES IS IT TO THE SUN?" answer1[1]="GRANT" answer2[1]="LINCON" answer3[1]="NOBODY" answer4[1]="WASHINGTON" answer1[2]="5" answer2[2]="10" answer3[2]="25" answer4[2]="50" answer1[3]="36" answer2[3]="35" answer3[3]="32" answer4[3]="40" answer1[4]="MIAMI" answer2[4]="ORLANDO" answer3[4]="JACKSONVILLE" answer4[4]="TALLAHASSEE" answer1[5]="90,000,000" answer2[5]="89,000,000" answer3[5]="93,000,000" answer4[5]="91,000,000" right[1]="A" right[2]="B" right[3]="C" right[4]="D" right[5]="C" end procedure ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- -- @ INITIALIZE PROGRAM (moved into onActivate Win) ------------------------------------------------------------------------------- ------------------------------------------------------------------------------- procedure DisplayQuestion () setText(LText11, question[RecNum]) setText(ans1, answer1[RecNum]) setText(ans2, answer2[RecNum]) setText(ans3, answer3[RecNum]) setText(ans4, answer4[RecNum]) setVisible(Okay, w32False) end procedure ------------------------------------------------------------------------------- -- @ ACTIVATE PROGRAM -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- procedure Win_onActivate (integer self, integer event, sequence params)--params is () LoadQuestions() RecNum = rand(qcount) DisplayQuestion() end procedure setHandler( Win, w32HActivate, routine_id("Win_onActivate")) -------------------------------------------------------------------------------- procedure Accept (integer self, integer event, sequence params)--params is () -- find out which radio button was picked --puts(1, "\nACCEPT routine accessed") ans=0 if isChecked(ans1) then ans=2 end if if isChecked(ans2) then ans=3 end if if isChecked(ans3) then ans=4 end if if isChecked(ans4) then ans=5 end if -- convert letter of right answer to a number correct=0 if equal (right[RecNum],"A") then correct=2 rightans=answer1[RecNum] end if if equal (right[RecNum],"B") then correct=3 rightans=answer2[RecNum] end if if equal (right[RecNum],"C") then correct=4 rightans=answer3[RecNum] end if if equal (right[RecNum],"D") then correct=5 rightans=answer4[RecNum] end if if not equal(ans, correct) then setText(LText22, "The correct answer is") setText(LText23, rightans) else setText(LText22, "YES!") end if setVisible(Okay, w32True) end procedure setHandler( {ans1,ans2,ans3,ans4}, w32HClick, routine_id("Accept")) -------------------------------------------------------------------------------- procedure Okay_onClick (integer self, integer event, sequence params)--params is () RecNum = rand(qcount) --key=keyindex[RecNum] setCheck({ans1,ans2, ans3, ans4}, 0) DisplayQuestion() setVisible(Okay, w32False) -- <-- this SHOULD make the okay button invisible, but doesn't? setText(LText22, "") setText(LText23, "") end procedure setHandler( Okay, w32HClick, routine_id("Okay_onClick")) WinMain( Win,Normal )
hope this helps. Dan