Results 1 to 12 of 12

Thread: IF AND THEN ELSE problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    IF AND THEN ELSE problem

    I am having trouble with a blackjack game I am creating

    I have buttons 1 - 13 (A-K)
    I have 5 Textboxes which when the above buttons are pressed displays the values in the textboxes.

    I also have one more textbox which adds up the values of the above 5 textboxes to give your Black Jack Total.


    The problem I have is if an Ace (11) is in one of the textboxes and the Total Value exceeds 21 i need to have the Ace (11) change its value to 1 instead.

    textbox 1 - 5 will be the card values
    textbox6.text will be the total Value

    I have tried......

    Code:
    Code:
    if textbox6.text > 21 and textbox1.text = 11 then textbox1.text = 1
    This seems to work fine however it only solves the problem of an Ace (11) appearing in textbox1.text so i tried to repeat the code with the other boxes...

    Code:
    Code:
    if textbox6.text > 21 and textbox1.text = 11 then textbox1.text = 1
    if textbox6.text > 21 and textbox2.text = 11 then textbox2.text = 1
    if textbox6.text > 21 and textbox3.text = 11 then textbox3.text = 1
    if textbox6.text > 21 and textbox4.text = 11 then textbox4.text = 1
    if textbox6.text > 21 and textbox5.text = 11 then textbox5.text = 1
    However this does not work and my program freezes?

    Can anybody give me some code to resolve the problem. Not really bothered what the problem is just need a solution its driving me cra

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: IF AND THEN ELSE problem

    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF AND THEN ELSE problem

    Thanks mate now im gonna get no help.

    I marked that one as resolved because no body was replying

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: IF AND THEN ELSE problem

    See this thread http://www.vbforums.com/showpost.php...51&postcount=8 for some good advice on dealing with cards.

    The first problem you need to address is your checks. What if "B" is in textbox1? Is that greater than 21?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: IF AND THEN ELSE problem

    Doesn't look like it was marked resolved to me.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  6. #6
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: IF AND THEN ELSE problem

    Hi,

    You can try this;

    vb Code:
    1. If TextBox6.Text > 21 And TextBox1.Text = 11 Then
    2.             TextBox1.Text = 1
    3.         End If
    4.         If TextBox6.Text > 21 And TextBox2.Text = 11 Then
    5.             TextBox2.Text = 1
    6.         End If
    7.         If TextBox6.Text > 21 And TextBox3.Text = 11 Then
    8.             TextBox3.Text = 1
    9.         End If
    10.         If TextBox6.Text > 21 And TextBox4.Text = 11 Then
    11.             TextBox4.Text = 1
    12.         End If
    13.         If TextBox6.Text > 21 And TextBox5.Text = 11 Then
    14.             TextBox5.Text = 1
    15.         End If
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF AND THEN ELSE problem

    Oh my apologies I thought I did i'll redo it

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF AND THEN ELSE problem

    No that doesn't work unfortunately?

  9. #9
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: IF AND THEN ELSE problem

    Quote Originally Posted by martyloo View Post
    No that doesn't work unfortunately?
    Hi,

    In my application it does work in this button click event:

    vb.net Code:
    1. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    2.         If TextBox6.Text > 21 And TextBox1.Text = 11 Then
    3.             TextBox1.Text = 1
    4.         End If
    5.         If TextBox6.Text > 21 And TextBox2.Text = 11 Then
    6.             TextBox2.Text = 1
    7.         End If
    8.         If TextBox6.Text > 21 And TextBox3.Text = 11 Then
    9.             TextBox3.Text = 1
    10.         End If
    11.         If TextBox6.Text > 21 And TextBox4.Text = 11 Then
    12.             TextBox4.Text = 1
    13.         End If
    14.         If TextBox6.Text > 21 And TextBox5.Text = 11 Then
    15.             TextBox5.Text = 1
    16.         End If
    17.  
    18.     End Sub

    Can explain a little more what's wrong and witch error you got.
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF AND THEN ELSE problem

    Ok i think i have something working now, i'll finish it off and let you know

  11. #11
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: IF AND THEN ELSE problem

    Could we at least pretend that we know the difference between strings and integers?

    Make

    Option Strict On

    the first line of your program and you will see how bad it is.

    At a minimum it should look like this

    Code:
            If CInt(TextBox6.Text) > 21 AndAlso CInt(TextBox1.Text) = 11 Then
                TextBox1.Text = "1"
            End If
    though it does nothing for the case where the user enters something other than numbers into a textbox. See Integer.TryParse, please.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF AND THEN ELSE problem

    why does it have to be like that? what is the difference they both appear to do the same function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width