2 Replies - 556 Views - Last Post: 10 November 2009 - 08:30 AM Rate Topic: -----

#1 pdkharkar  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 63
  • View blog
  • Posts: 345
  • Joined: 19-January 09

if else conditions

Posted 10 November 2009 - 07:53 AM

Hello
I am creating a simple mathematical game in VB.NET for kids!!
the game checks for some simple calculations!!
I am having the problem regarding the if else block in the code
here is my code!!
PLease Help as soon as you can!
Public Class Form1

	Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint

	End Sub

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

	End Sub

	Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
		Dim rno As New Random()

		TextBox1.Text = rno.Next(1, 10)
		TextBox2.Text = rno.Next(1, 10)

	End Sub

	Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
	   
	End Sub

	Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
		Dim result As New Integer
		result = TextBox1.Text + TextBox2.Text
		If TextBox3.Text = result Then
			Label1.Text = "Congratulations You are Right"
		ElseIf TextBox3.Text <> result Then
			Label1.Text = "Sorry ! You are wrong!! Try Again!!!"
		ElseIf TextBox3.Text = "" Then
			Label1.Text = "Please submit the anser"
		End If
	End Sub
End Class



Is This A Good Question/Topic? 0
  • +

Replies To: if else conditions

#2 TEH  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 152
  • Joined: 30-January 08

Re: if else conditions

Posted 10 November 2009 - 08:00 AM

I think it just need the .ToInt after the textbox_.text.

For example textbox3.Text.ToInt

That tells to program that there is a numerical-value in textbox other than string as usually.

I haven't tested that so this is just one guess.
Was This Post Helpful? 0
  • +
  • -

#3 TEH  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 29
  • View blog
  • Posts: 152
  • Joined: 30-January 08

Re: if else conditions

Posted 10 November 2009 - 08:30 AM

Sorry for my last answer.
I tested it now and figured out that you need to convert these values to integer and change that
	ElseIf TextBox3.Text = "" Then
			Label1.Text = "Please submit the anser"


to the first line of condition so it doesn't do anything if you wasn't give it a value.

change your button5.click to following:

  Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
		Dim result As Integer
		Dim value1 As Integer
		Dim value2 As Integer
		value1 = CInt(TextBox1.Text)
		value2 = CInt(TextBox2.Text)
		If TextBox3.Text = Nothing Then
			Label1.Text = "Please submit the anser"
		Else
			result = value1 + value2
			If CInt(TextBox3.Text) = result Then
				Label1.Text = "Congratulations You are Right"
			ElseIf CInt(TextBox3.Text) <> result Then
				Label1.Text = "Sorry ! You are wrong!! Try Again!!!"

			End If
		End If
	End Sub
End Class


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1