jtchase08
jtchase08

Reputation: 660

Yahtzee 3 of a kind! VB

i'm working on a yahtzee game for my intro to VB class in school. i've gotten through most of the program, and am down to only a few more sets. right now, however, i'm stuck on the three of a kind set, and the four of a kind set. right now i'm working on my 3oak set.

rdb3OAK - a radiobutton the user will check if they plan to put the dice towards 3 of a kind

randnum1-5 - each of the five dice's values

lbl3OAK - the label that the points awarded for 3 of a kind will be shown in

here's the code i have:

        '3 of a kind
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum3 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum3 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum3 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum1 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum3 = randnum4 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum3 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum2 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If
        If rdb3OAK.Checked = True And randnum3 = randnum4 = randnum5 Then
            lbl3OAK.Text = randnum1 + randnum2 + randnum3 + randnum4 + randnum5
            rdb3OAK.Enabled = False
        End If

there's an if statement for each possible combination of three dice equaling the same number. in theory this works, but in practice it does not. i'm not getting any errors at all, so i don't know what is going wrong.

i'm new to programming, so be kind to me!

any help offered would be appreciated!

Upvotes: 0

Views: 827

Answers (1)

BrettFromLA
BrettFromLA

Reputation: 916

Unfortunately, you can't do "a = b = c" like that. You'll need to do "a=b And b=c". For example, change this:

If rdb3OAK.Checked = True And randnum1 = randnum2 = randnum3 Then

To this:

If rdb3OAK.Checked = True And randnum1 = randnum2 And randnum2 = randnum3 Then

I'm a bit rusty on VB, so you may also need to use "==" instead of "=". (In some languages, "=" is assignment and "==" is comparison.)

Upvotes: 1

Related Questions