Jump to content

Conditional Statement Question

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
9 replies to this topic

#1
yourmom615

yourmom615

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
Hello,

I am taking an Intro to VB.NET (08) and we are working out a game.

One of the buttons I have assigned this code...

If DieThrowOneInteger = 1 Then

        Else : DieThrowTwoInteger = 1

            MessageBox.Show("You threw a one so you lost all your points for this turn.")

        End If

Basically, I am trying to get two buttons to display the messageBox when the values of the Integers of the two buttons become a 1. Instead when I run the code every value is triggering the messageBox.

If possible please explain what doing incorrectly. Thanks for any assistance in advance and if further
explaination is need please SMACK ME!!!!

Edited by Alexander, 21 October 2010 - 08:40 PM.
Please use [code] tags rather than blue text


#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
I am not sure what you want to do, do you want to test both integers at once?
If DieThrowOneInteger = 1 And DieThrowTwoInteger = 1 Then
    MessageBox.Show("You threw a one so you lost all your points for this turn.")
End If

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
yourmom615

yourmom615

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
Yes and No, the first part I want to display the message whenever the value of either one of the die is equall to a 1.

Later I want to display another message when both dice are 1's at the same time.

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Can you do something like this in vb?
If DieThrowOneInteger = 1 || DieThrowTwoInteger = 1 Then

|| is boolean OR in most languages.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#5
yourmom615

yourmom615

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
That worked great! Thanks so much... I am still learning and I tried many different ways before posting this question.

So to get the same result for both dice (snake eyes, 1 and 1) the code should look something like......

If DieThrowOneInteger = 1 Or DieThrowTwoInteger = 1 Then
MessageBox.Show("You threw a one so you lost all your points for this turn.")
Else DieThrowOneInteger = 1 And DieThrowTwoInteger = 1 Then
MessageBox.Show("You Rolled Snake Eyes, All Point are lost.")
End If

Unfortunately, this did not work for the second message box statement. After debugging underneath the last Then is stating "End of statement expected". I have no idea how to fix this. Thanks for the help above.

Best Regards,
Your Mom615

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
The logic in that throws the first message box regardless if it is two or one, because it won't check in case they both are first. You may want to try something like this:
'check for both
If DieThrowOneInteger = 1 And DieThrowTwoInteger = 1 Then
MessageBox.Show("You Rolled Snake Eyes, All Point are lost.")
'check for one
Else If DieThrowOneInteger = 1 Or DieThrowTwoInteger = 1 Then
MessageBox.Show("You threw a one so you lost all your points  for this turn.")
End If
I think that should work.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
You need to use Else If rather than just else.

Also, I'm not 100% that it will ever get to the second statement, as one of the first statement is true, I don't think it checks the second part.. it just returns true (I could be wrong on this, havn't tried).

Try this code though:
If DieThrowOneInteger = 1 And DieThrowTwoInteger = 1 Then
MessageBox.Show("You Rolled Snake Eyes, All Point are lost.")
ElseIf DieThrowOneInteger = 1 Or DieThrowTwoInteger = 1 Then
MessageBox.Show("You threw a one so you lost all your points for this turn.")
End If

My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs

#8
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
^^ Nullw0rm beat me to it!
My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs

#9
yourmom615

yourmom615

    Learning Programmer

  • Members
  • PipPipPip
  • 33 posts
sol1,

I tried this as well and it still doesn't act the way I am intending. Do you know if there is any other way to get message boxes to appear, without using IF THE statements?

#10
so1i

so1i

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 312 posts
What about it isn't acting the way you wanted?
My Company - My Homepage - My Twitter - My Google+ - My LinkedIn

"Things don’t have to change the world to be important.” - Steve Jobs