vb.net - Issue with some Visual Basic programming code -


basically have design fruit game random fruit generated , child has guess fruit type. if child guesses right, receive message saying congrats , if wrong, receive message saying "try again".

i have done programming don't know going wrong when type name of fruit. because though right, gives message saying wrong.

i have program code when fruit right , message it.

private sub button2_click(byval sender system.object, byval e system.eventargs) handles button2.click         button1.visible = true ' tools need hide when check button cliked         button2.visible = false         picturebox1.visible = false         textbox1.visible = false     if label1.text = "1" , textbox2.text = "banana" ' if both true following result true         picturebox2.image = my.resources.well_done 'my.resources.name 'the well_done picture appears correct         picturebox2.visible = true                                        '- answer , @ same time has visble         label2.text = "congrats! " & textbox2.text & "! correct answer!" 'the msg appears correct answer         label2.visible = true         me.backcolor = color.yellow      ' background colour of form      elseif label1.text = "2" , textbox1.text = "apple" 'similary apple banana , other fruits         picturebox2.image = my.resources.well_done         picturebox2.visible = true         label2.text = "congrats " & textbox2.text & "! correct answer!"         label2.visible = true         me.backcolor = color.green     elseif label1.text = "3" , textbox1.text = "orange"         picturebox2.image = my.resources.well_done         picturebox2.visible = true         label2.text = "congrats " & textbox2.text & "! correct answer!"         label2.visible = true         me.backcolor = color.orange     elseif label1.text = "4" , textbox1.text = "strawberry"         picturebox2.image = my.resources.well_done         picturebox2.visible = true         label2.text = "congrats " & textbox2.text & "! correct answer!"         label2.visible = true         me.backcolor = color.indianred     elseif label1.text = "5" , textbox1.text = "grapes"         picturebox2.image = my.resources.well_done         picturebox2.visible = true         label2.text = "congrats " & textbox2.text & "! correct answer!"         label2.visible = true         me.backcolor = color.green 

the answer question because of casing issue. try using tolower() , make sure strings lower case too.

as side note though, write lot more efficient if created abstract class called fruit , derive different types of fruit (apple, strawberry, etc.) class. create abstract method called tostring() , compare input tostring() method. save having have crap ton of "if"'s in code.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -