|
-
Apr 3rd, 2011, 11:49 AM
#1
Thread Starter
Member
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
-
Apr 3rd, 2011, 12:09 PM
#2
Re: IF AND THEN ELSE problem
-
Apr 3rd, 2011, 12:11 PM
#3
Thread Starter
Member
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
-
Apr 3rd, 2011, 12:19 PM
#4
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?
-
Apr 3rd, 2011, 12:21 PM
#5
Re: IF AND THEN ELSE problem
Doesn't look like it was marked resolved to me.
-
Apr 3rd, 2011, 12:22 PM
#6
Re: IF AND THEN ELSE problem
Hi,
You can try this;
vb Code:
If TextBox6.Text > 21 And TextBox1.Text = 11 Then
TextBox1.Text = 1
End If
If TextBox6.Text > 21 And TextBox2.Text = 11 Then
TextBox2.Text = 1
End If
If TextBox6.Text > 21 And TextBox3.Text = 11 Then
TextBox3.Text = 1
End If
If TextBox6.Text > 21 And TextBox4.Text = 11 Then
TextBox4.Text = 1
End If
If TextBox6.Text > 21 And TextBox5.Text = 11 Then
TextBox5.Text = 1
End If
-
Apr 3rd, 2011, 12:23 PM
#7
Thread Starter
Member
Re: IF AND THEN ELSE problem
Oh my apologies I thought I did i'll redo it
-
Apr 3rd, 2011, 12:41 PM
#8
Thread Starter
Member
Re: IF AND THEN ELSE problem
No that doesn't work unfortunately?
-
Apr 3rd, 2011, 12:53 PM
#9
Re: IF AND THEN ELSE problem
 Originally Posted by martyloo
No that doesn't work unfortunately?
Hi,
In my application it does work in this button click event:
vb.net Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If TextBox6.Text > 21 And TextBox1.Text = 11 Then
TextBox1.Text = 1
End If
If TextBox6.Text > 21 And TextBox2.Text = 11 Then
TextBox2.Text = 1
End If
If TextBox6.Text > 21 And TextBox3.Text = 11 Then
TextBox3.Text = 1
End If
If TextBox6.Text > 21 And TextBox4.Text = 11 Then
TextBox4.Text = 1
End If
If TextBox6.Text > 21 And TextBox5.Text = 11 Then
TextBox5.Text = 1
End If
End Sub
Can explain a little more what's wrong and witch error you got.
-
Apr 3rd, 2011, 01:16 PM
#10
Thread Starter
Member
Re: IF AND THEN ELSE problem
Ok i think i have something working now, i'll finish it off and let you know
-
Apr 3rd, 2011, 02:14 PM
#11
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.
-
Apr 3rd, 2011, 02:18 PM
#12
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|