Results 1 to 4 of 4

Thread: [RESOLVED] IF Function Problem

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Resolved [RESOLVED] IF Function 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:
    if textbox6.text > 21 then 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:
    if textbox6.text > 21 then and textbox1.text = 11 then textbox1.text = 1
    if textbox6.text > 21 then and textbox2.text = 11 then textbox2.text = 1
    if textbox6.text > 21 then and textbox3.text = 11 then textbox3.text = 1
    if textbox6.text > 21 then and textbox4.text = 11 then textbox4.text = 1
    if textbox6.text > 21 then 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 crazy

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,422

    Re: IF Function Problem

    you're confusing your datatypes. numerical datatypes can be greater than, but string datatypes can't. also your if statements are wrong:

    Code:
    if textbox6.text > 21 then and textbox1.text = 11 then textbox1.text = 1
    should be:

    vb Code:
    1. if cint(textbox6.text) > 21 and cint(textbox1.text) = 11 then textbox1.text = "1"

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    50

    Re: IF Function Problem

    See again it works for the first box but when I try and repeat it, the program freezes???

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

    Re: IF Function 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

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