get a checkmark to appear

juggernot

Well-known member
Joined
Sep 28, 2006
Messages
173
Programming Experience
Beginner
Okay, I've got my math program working. now I'm trying to get a checkmark to appear if you have the write answer.
The code I've got so far is:
VB.NET:
If me.TextBox1 = Val(me.Label1.Text) + Val(me.Label2.Text) then me.PictureBox1.Visible
Can someone tell me the correct code to do this?
 
Last edited by a moderator:
Presumably you only want to show the image when the user has entered the correct value. So, in the TextBox1 TextChanged method you could have:
VB.NET:
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] Val([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.Text) = Val([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Label1.Text) + Val([/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].Label2.Text) [/SIZE][SIZE=2][COLOR=#0000ff]Then [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].PictureBox1.Visible = [/SIZE][SIZE=2][COLOR=#0000ff]True[/COLOR][/SIZE]

This of course leads to the problem that every charactor entered changes the value of the textbox, so in typing "123" the user would get the "bad" image twice before finally seeing the good image.


Better might be to have them type their value you, then click a "Check Answer" button, or to have the image only display once the value is finally right..
 
Last edited by a moderator:
I got the checkmarks and x's to work! YAY! BTW I am using a check answers button.
I've also added more questions and a timer
This time I've got a couple questions:
-Is there anyway to avoid the error i get when I leave a field blank. It says something about "" not being a valid value for 'double'
 
For the "" not being valid, you just need to stop the user from submitting an empty answer. For your CheckAnswerButton_Click action put something like the following.

VB.NET:
[SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] Button1_Click([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] Button1.Click[/SIZE]
[SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].TextBox1.Text = [/SIZE][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Then[/COLOR][/SIZE]
[SIZE=2]MessageBox.Show([/SIZE][SIZE=2][COLOR=#800000]"Invalid. Empty is not an answer"[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2][COLOR=#0000ff]Exit[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]Else[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]'Do Math Stuff[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
 
Back
Top