vb.net - Simple Quiz in VB -
i taking vb general education class totally non related major. struggling here 1 of our assignments. assignment create simple quiz consisting of 3 questions, , program supposed calculate score , percentage of participant. have written following code far, doesn't execute right. can me please? thing can't figure out how make 1 of textboxs' case insensitive. great!
private sub btnsubmit_click(sender object, e eventargs) handles btnsubmit.click dim firstanswer integer = 2 dim secondanswer string = "barak obama" dim thirdanswer string = "florida" dim correctanswer double = 0 dim num1 double = cdbl(lblcorrectanswer.text) dim percent double percent = num1 / 3 * 100 if txtsum.text = firstanswer , txtpresident.text = secondanswer , txtimpoertantques.text = thirdanswer lblcorrectanswer.text = correctanswer + 3 txtsum.backcolor = color.green txtsum.forecolor = color.white txtpresident.backcolor = color.green txtpresident.forecolor = color.white txtimpoertantques.backcolor = color.green txtimpoertantques.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtsum.text = firstanswer , txtimpoertantques.text = thirdanswer lblcorrectanswer.text = correctanswer + 2 txtsum.backcolor = color.green txtsum.forecolor = color.white txtimpoertantques.backcolor = color.green txtimpoertantques.forecolor = color.white txtpresident.backcolor = color.red txtpresident.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtsum.text = firstanswer lblcorrectanswer.text = correctanswer + 1 txtsum.backcolor = color.green txtsum.forecolor = color.white txtpresident.backcolor = color.red txtpresident.forecolor = color.white txtimpoertantques.backcolor = color.red txtimpoertantques.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtsum.text = firstanswer , txtpresident.text = secondanswer lblcorrectanswer.text = correctanswer + 2 txtsum.backcolor = color.green txtsum.forecolor = color.white txtpresident.backcolor = color.green txtpresident.forecolor = color.white txtimpoertantques.backcolor = color.red txtimpoertantques.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtpresident.text = secondanswer , txtimpoertantques.text = thirdanswer lblcorrectanswer.text = correctanswer + 2 txtpresident.backcolor = color.green txtpresident.forecolor = color.white txtimpoertantques.backcolor = color.green txtimpoertantques.forecolor = color.white txtsum.backcolor = color.red txtsum.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtpresident.text = secondanswer lblcorrectanswer.text = correctanswer + 1 txtpresident.backcolor = color.green txtpresident.forecolor = color.white txtsum.backcolor = color.red txtsum.forecolor = color.white txtimpoertantques.backcolor = color.red txtimpoertantques.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" elseif txtimpoertantques.text = thirdanswer lblcorrectanswer.text = correctanswer + 1 txtimpoertantques.backcolor = color.green txtimpoertantques.forecolor = color.white txtsum.backcolor = color.red txtsum.forecolor = color.white txtpresident.backcolor = color.red txtpresident.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" else lblcorrectanswer.text = correctanswer = 0 lblprecent .text = 0 txtsum.backcolor = color.red txtsum.forecolor = color.white txtpresident.backcolor = color.red txtpresident.forecolor = color.white txtimpoertantques.backcolor = color.red txtimpoertantques.forecolor = color.white end if if txtsum.text = nothing or txtpresident.text = nothing or txtpresident.text = nothing messagebox.show("error! please enter aswer.") end if
there 3 questions there must 3 if...elseif...else or if..else. should not include scoring of other questions inside elseif because once program returns true in either of if or elseif in conditions if..else terminates , not execute rest of elseif..
it should example,
if txtsum.text=.... elseif else end if if txtpresident.text=... else end if if txtimpoertantques.text=... else end if
rest assured, execute wanted... or this...
private sub btnsubmit_click(byval sender system.object, byval e system.eventargs) handles btnsubmit.click dim firstanswer integer = 2 dim secondanswer string = "barak obama" dim thirdanswer string = "florida" dim correctanswer double = 0 dim num1 double = cdbl(lblcorrectanswer.text) dim percent double percent = num1 / 3 * 100 if txtsum.text = nothing or txtpresident.text = nothing or txtpresident.text = nothing messagebox.show("error! please enter aswer.") 'when empty rest won't executed 'instead, program prompts user enter answer else if txtsum.text = firstanswer correctanswer = correctanswer + 1 'added points txtsum.backcolor = color.green txtsum.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" end if if txtsum.text = firstanswer correctanswer = correctanswer + 1 'added points txtsum.backcolor = color.green txtsum.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" end if if txtimpoertantques.text = thirdanswer correctanswer = correctanswer + 1 'added points txtimpoertantques.backcolor = color.green txtimpoertantques.forecolor = color.white lblprecent.text = percent.tostring("##.00") & "%" end if lblcorrectanswer.text = correctanswer 'displays total score end if 'end of empty field validation end sub
Comments
Post a Comment