2 Replies - 1885 Views - Last Post: 27 October 2009 - 10:37 AM Rate Topic: -----

#1 Lost123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 22
  • Joined: 22-October 09

if...then..else statement to case

Posted 26 October 2009 - 10:10 AM

how would you change this if..then...else to a case statement? i've done simpler ones but this one i dont seem to be able to do it..
		If intUserAnswer = intCorrectResponses Then
			picFace.Image = picHappy.Image
			intCorrectResponses = intCorrectResponses + 1
			txtAnswer.Text = String.Empty
			Call GenerateAndDisplayIntegers()
		Else
			picFace.Image = picNeutral.Image
			intIncorrectResponses = intIncorrectResponses + 1
			MessageBox.Show(strMSG, "Math Practice", MessageBoxButtons.OK, MessageBoxIcon.Information)
			txtAnswer.SelectAll()
		End If
		txtAnswer.Focus()
		lblCorrect.Text = Convert.ToString(intCorrectResponses)
		lblIncorrect.Text = Convert.ToString(intIncorrectResponses)
	End Sub




this is what i have i know its wrong Im just really stuck

Select Case intUserAnswer = intCorrectResponses
		picFace.Image = picHappy.Image
		intCorrectResponses = intCorrectResponses + 1
		txtAnswer.Text = String.Empty
		Call GenerateAndDisplayIntegers()
			Case Else
				picFace.Image = picNeutral.Image
				intIncorrectResponses = intIncorrectResponses + 1
				MessageBox.Show(strMSG, "Math Practice", MessageBoxButtons.OK, MessageBoxIcon.Information)
				txtAnswer.SelectAll()
		End Select
		txtAnswer.Focus()
		lblCorrect.Text = Convert.ToString(intCorrectResponses)
		lblIncorrect.Text = Convert.ToString(intIncorrectResponses)
	End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: if...then..else statement to case

#2 MajorWalrus  Icon User is offline

  • D.I.C Head

Reputation: 10
  • View blog
  • Posts: 115
  • Joined: 22-April 09

Re: if...then..else statement to case

Posted 26 October 2009 - 10:44 AM

I don't see the need, really. With one case and an else case you'll end up with the same thing as an If/Then statement.

???

But to answer your question:

Select Case intUserAnswer 
   Case intCorrectResponses
		picFace.Image = picHappy.Image
		intCorrectResponses = intCorrectResponses + 1
		txtAnswer.Text = String.Empty
		Call GenerateAndDisplayIntegers()
	Case Else
				picFace.Image = picNeutral.Image
				intIncorrectResponses = intIncorrectResponses + 1
				MessageBox.Show(strMSG, "Math Practice", MessageBoxButtons.OK, MessageBoxIcon.Information)
				txtAnswer.SelectAll()
End Select
txtAnswer.Focus()
lblCorrect.Text = Convert.ToString(intCorrectResponses)
lblIncorrect.Text = Convert.ToString(intIncorrectResponses)

Was This Post Helpful? 1
  • +
  • -

#3 MacAnimeGirl  Icon User is offline

  • D.I.C Regular

Reputation: 9
  • View blog
  • Posts: 282
  • Joined: 30-September 08

Re: if...then..else statement to case

Posted 27 October 2009 - 10:37 AM

Using the If...Then...Else statement is better than the Case Select statement, at least in this scenario.

Case statements are usually for, and better with several instances you are wanting to test.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1