Older Version
Newer Version
cogburn
May 23, 2012
**Program that allows practice reading a metric ruler.** I got some more help from the LB forum guys to put together this program. It allows the user to read and input the observed length of a rectangle. It gives the user 5 different rectangles to measure and it gives instant feedback as well as it saves a copy of the results to a file.****CautionCaution on the use of theprogram.** **Makeprogram. Make sure that the file address is suitable for your computer. I worked off of a jump drive so the file was opened, written to, and saved on the g:\ drive. If you are working only on yourc:**\ **drivec:**\** drive or some other drive, please change the file address code in the program to reflect the drive to which you are using to save theresults.** ***results. * Otherwise, it is a straightforward program [[code format="lb"]] [[code]] 'This program attempts to give students practice reading a rule. '*** Must set file parameters for your particular situation '*** example "g:\record.txt" vs "c:\record.txt" '***************************************************** 'set graphics window parameters '*****************************************************nomainwin opennomainwin open "g:\record.txt" for append as #1closeclose #1kill"g:\record.txt"kill"g:\record.txt"UpperLeftXUpperLeftX = 500UpperLeftYUpperLeftY = 150WindowWidthWindowWidth = 640WindowHeightWindowHeight = 760graphicboxgraphicbox #w.g, 10, 10, 600, 500statictextstatictext #w.s, "Enter your measurement in the box and click 'Save' button", 10, 600, 600, 30textboxtextbox #w.tb1, 10, 550, 600, 32buttonbutton #w.b1, "Save", [entered], LR, 300, 50, 60, 30openopen "Measuring Practice" for window as #w#w,#w, "trapclose [quit]"#w.tb1#w.tb1 "!font arial 16 bold"#w.s#w.s "!font arial 12"#w.tb1#w.tb1 "!setfocus"'***************************************** 'draw'***************************************** 'draw the ruler borders'***************************************** #w.g,'***************************************** #w.g, "goto 50 400"#w.g,#w.g, "down"#w.g,#w.g, "goto 50 450"#w.g,#w.g, "goto 550 450"#w.g,#w.g, "goto 550 400"#w.g,#w.g, "goto 50 400"'******************************************* 'add'******************************************* 'add the centimeter and .5 centimeter markings'******************************************* [skip1] x'******************************************* [skip1] x = 50yy = 400zz = 425forfor j = 1 to 19xx = x + 25#w.g,#w.g, "goto ";x;" ";y#w.g,#w.g, "down"#w.g,#w.g, "goto ";x;" ";z#w.g,#w.g, "up"nextnext jxx = 50yy = 400zz = 410#w.g,#w.g, "up"#w.g,#w.g, "goto ";x;" ";zforfor i = 1 to 100xx = x + 5#w.g,#w.g, "goto ";x;" ";y#w.g,#w.g, "down"#w.g,#w.g, "goto ";x;" ";z#w.g,#w.g, "up"nextnext i'************************************************** x'************************************************** x = 95yy = 430dd = 1#w.g,"down" #w.g,#w.g,"down" #w.g, "place ";x;" ";yforfor j = 1 to 8dd = d+1xx = x + 50#w.g,#w.g, "place ";x;" ";ynextnext j#w.g,#w.g, "flush"#w.g,#w.g, "up"'******************************************************* 'Draw'******************************************************* 'Draw a rectangle above the ruler and store length as cm'*******************************************************'*******************************************************forfor b = 1 to 5#w.g,#w.g, "goto 50 400"#w.g,#w.g, "down"xx = 550:y = 350#w.g,#w.g, "goto 50 400"#w.g,#w.g, "down"x=int(rnd(1)*450)x=int(rnd(1)*450) + 100:y=350cmcm = (x-50)/50ii = 2roundedrounded = int(cm*10^i +0.5) / 10^iwaitwait'************************************************* 'allow'************************************************* 'allow guess and compare with actual length of bar'*************************************************'*************************************************[entered] #w.tb1[entered] #w.tb1 "!contents? reply$"guessguess =val( reply$)ifif ( rounded -0.1 <guess) and ( rounded +0.1 >guess) then#w.tb1#w.tb1 "GOOD ANSWER"else #w.tb1else #w.tb1 "The correct answer was "; rounded; " cm, not "; guessendend iftimertimer 3000, [continue]wait [continue]wait [continue] '<- when time is up, execution branches heretimertimer 0#w.s#w.s "Measurement # "; b+1#w.tb1#w.tb1 ""#w.tb1#w.tb1 "!setfocus"'************************************************* 'write'************************************************* 'write to file'*************************************************'*************************************************[save] open[save] open "g:\record.txt" for append as #1 'create a new file on diskcloseclose #1nextnext b [grade]openopen "g:\record.txt" for input as #2correctcorrect = 0whilewhile eof (#2) = 0inputinput #2, guess, roundedIF rounded - .1 < guess AND rounded + .1 > guess THEN correct = correct + 1 ELSE correct = correct END IF wend #w.tb1 "% correct = ";(correct/5)*100 timer 3000, [finish] wait [finish] '<- when time is up, execution branches here timer 0 [quit] close#2 close #w endIF rounded - .1 < guess AND rounded + .1 > guess THEN correct = correct + 1 ELSE correct = correct END IF wend #w.tb1 "% correct = ";(correct/5)*100 timer 3000, [finish] wait [finish] '<- when time is up, execution branches here timer 0 [quit] close#2 close #w end [[code]] [[code]]