Fox and Hound game

kayleeh

New Member
Joined
Dec 3, 2014
Messages
5
I need help I need to know how to store this set of numbers in an array and to compare them to another variable. I am getting a subscript out of range error, and I just do not understand why at all. The trouble I am having is getting the values to store in the array and compare. Maybe it's my syntax. Please help and fast!

Code:
Private Sub MoveHound_Click()
Dim hmfr As Variant 'variable for position of fox move forward right
Dim hmfl As Variant 'variable for position of fox move forward left
bluearray = Array(9, 10, 11, 17, 18, 19, 25, 26, 27) 'odd row array
purplearray = Array(6, 7, 8, 14, 15, 16, 22, 23, 24) 'even row array
orangearray = Array(5, 13, 21) 'left array
redarray = Array(12, 20, 28) 'right array
yellowarray = Array(1, 2, 3) 'top row array
greenarray = Array(30, 31, 32) 'bottom row array
cornertop = 4 'top corner value
cornerbottom = 29 'bottom corner value
'PROCESS
'finding hound selection
If HoundMove.H1.Value = True Then 'if hound 1 is selected
    'finding direction selection
    If HoundMove.ForwardRight.Value = True Then 'if the forward right option is selected
        If hp(1) = bluearray Or hp(1) = yellowarray Then 'checking the value of fs against the values of the bluearray for a match
            hmfr = hp(1) + 5 'equation for the place of the new move
                FoxHound.Controls("B" & hp(1)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(1)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(1) = hmfr 'storing the new hound position
        ElseIf hp(1) = purplearray Or hp(1) = orangearray Then 'checking the value of fs against the values of the purplearray for a match
            hmfr = hp(1) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(1)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(1)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(1) = hmfr 'storing the new hound position
        Else 'if the place that the hound is trying to move is not a valid place
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    ElseIf HoundMove.ForwardLeft.Value = True Then 'if the forward left option is selected
        If hp(1) = bluearray Or hp(1) = yellowarray Or hp(1) = topcorner Or hp(1) = redarray Then 'checking the value of hs(i) against the values of the green and purple arrays for a match
            hmfl = hp(1) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(1)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(1)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(1) = hmfl 'storing the new hound position
        ElseIf hp(1) = purplearray Then 'checking the value of hs(i) against the values of the red and blue arrays for a match
            hmfl = hp(1) + 3 'equation for the place of the new move
                FoxHound.Controls("B" & hp(1)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(1)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(1) = hmfl 'storing the new hound position
        Else 'the value of fs does not allow for the move
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    Else 'if no option is selected
        MsgBox "You need to select a move and a Hound!", vbOKOnly, "Error" 'error message
    End If 'end if statement
ElseIf HoundMove.H2.Value = True Then 'if hound 2 is selected
    'finding direction selection
    If HoundMove.ForwardRight.Value = True Then 'if the forward right option is selected
        If hp(2) = bluearray Or hp(2) = yellowarray Then 'checking the value of fs against the values of the bluearray for a match
            hmfr = hp(2) + 5 'equation for the place of the new move
                FoxHound.Controls("B" & hp(2)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(2)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(2) = hmfr 'storing the new hound position
        ElseIf hp(2) = purplearray Or hp(2) = orangearray Then 'checking the value of fs against the values of the purplearray for a match
            hmfr = hp(2) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(2)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(2)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(2) = hmfr 'storing the new hound position
        Else 'if the place that the hound is trying to move is not a valid place
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    ElseIf HoundMove.ForwardLeft.Value = True Then 'if the forward left option is selected
        If hp(2) = bluearray Or hp(2) = yellowarray Or hp(2) = topcorner Or hp(2) = redarray Then 'checking the value of hs(i) against the values of the green and purple arrays for a match
            hmfl = hp(2) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(2)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(2)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(2) = hmfl 'storing the new hound position
        ElseIf hp(2) = purplearray Then 'checking the value of hs(i) against the values of the red and blue arrays for a match
            hmfl = hp(2) + 3 'equation for the place of the new move
                FoxHound.Controls("B" & hp(2)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(2)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(2) = hmfl 'storing the new hound position
        Else 'the value of fs does not allow for the move
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    Else 'if no option is selected
        MsgBox "You need to select a move and a Hound!", vbOKOnly, "Error" 'error message
    End If 'end if statement
ElseIf HoundMove.H3.Value = True Then 'if hound 3 is selected
    'finding direction selection
    If HoundMove.ForwardRight.Value = True Then 'if the forward right option is selected
        If hp(3) = bluearray Or hp(3) = yellowarray Then 'checking the value of fs against the values of the bluearray for a match
            hmfr = hp(3) + 5 'equation for the place of the new move
                FoxHound.Controls("B" & hp(3)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(3)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(3) = hmfr 'storing the new hound position
        ElseIf hp(3) = purplearray Or hp(3) = orangearray Then 'checking the value of fs against the values of the purplearray for a match
            hmfr = hp(3) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(3)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(3)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(3) = hmfr 'storing the new hound position
        Else 'if the place that the hound is trying to move is not a valid place
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    ElseIf HoundMove.ForwardLeft.Value = True Then 'if the forward left option is selected
        If hp(3) = bluearray Or hp(3) = yellowarray Or hp(3) = topcorner Or hp(3) = redarray Then 'checking the value of hs(i) against the values of the green and purple arrays for a match
            hmfl = hp(3) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(3)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(3)).Caption = " " 'erasing the old fox position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(3) = hmfl 'storing the new hound position
        ElseIf hp(3) = purplearray Then 'checking the value of hs(i) against the values of the red and blue arrays for a match
            hmfl = hp(3) + 3 'equation for the place of the new move
                FoxHound.Controls("B" & hp(3)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(3)).Caption = " " 'erasing the old fox position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(3) = hmfl 'storing the new hound position
        Else 'the value of fs does not allow for the move
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    Else 'if no option is selected
        MsgBox "You need to select a move and a Hound!", vbOKOnly, "Error" 'error message
    End If 'end if statement
ElseIf HoundMove.H4.Value = True Then 'if hound 4 is selected
'finding direction selection
    If HoundMove.ForwardRight.Value = True Then 'if the forward right option is selected
        If hp(4) = bluearray Or hp(4) = yellowarray Then 'checking the value of fs against the values of the bluearray for a match
            hmfr = hp(4) + 5 'equation for the place of the new move
                FoxHound.Controls("B" & hp(4)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(4)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(4) = hmfr 'storing the new hound position
        ElseIf hp(4) = purplearray Or hp(4) = orangearray Then 'checking the value of fs against the values of the purplearray for a match
            hmfr = hp(4) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hp(4)).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hp(4)).Caption = " " 'erasing the old hound position
                FoxHound.Controls("B" & hmfr).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfr).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfr).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfr).ForeColor = vbWhite 'making text white in color
            hp(4) = hmfr 'storing the new hound position
        Else 'if the place that the hound is trying to move is not a valid place
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    ElseIf HoundMove.ForwardLeft.Value = True Then 'if the forward left option is selected
        If hp(4) = bluearray Or hp(4) = yellowarray Or hp(4) = topcorner Or hp(4) = redarray Then 'checking the value of hs(i) against the values of the green and purple arrays for a match
            hmfl = hp(4) + 4 'equation for the place of the new move
                FoxHound.Controls("B" & hs).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hs).Caption = " " 'erasing the old fox position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(4) = hmfl 'storing the new hound position
        ElseIf hp(4) = purplearray Then 'checking the value of hp against the values of the red and blue arrays for a match
            hmfl = hp(4) + 3 'equation for the place of the new move
                FoxHound.Controls("B" & hs).BackColor = vbButtonFace 'turning old button back white
                FoxHound.Controls("B" & hs).Caption = " " 'erasing the old fox position
                FoxHound.Controls("B" & hmfl).BackColor = RGB(160, 0, 0) 'turn the button dark red
                FoxHound.Controls("B" & hmfl).Caption = "H" 'write H for hound in the button
                FoxHound.Controls("B" & hmfl).Font.Size = 18 'font size for H
                FoxHound.Controls("B" & hmfl).ForeColor = vbWhite 'making text white in color
            hp(4) = hmfl 'storing the new hound position
        Else 'the value of fs does not allow for the move
            MsgBox "The move you are attempting is not possible." & Chr(13) & "Please choose another option.", vbOKOnly, "Error" 'error message
        End If
    Else 'if no option is selected
        MsgBox "You need to select a move and a Hound!", vbOKOnly, "Error" 'error message
    End If 'end if statement
End If
HoundMove.Hide
End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Any line with an array in it. For example, just because it's the first line the program reads, this line

Code:
If hp(1) = bluearray Or hp(1) = yellowarray Then 'checking the value of fs against the values of the bluearray for a match</pre>
 
Upvote 0
It is the positions of the hounds on the board. There are four of them. hp is a public array from (1 to 4). hp(1) for now = 1, hp(2) = 2, hp(3) = 3, and hp(4) = 4. It needs to update after every turn.
 
Upvote 0
You can't compare an element of an array to an entire array like that. Does this work for you?

Code:
If Not IsError(Application.Match(hp(1), bluearray, False)) Then
 
Upvote 0
That would work, except I am comparing the hp(1) to several different arrays to see which value should subtract/add to get the the location of the new position.

Instead, if I just declared the variables "hp1", "hp2", "hp3", and "hp4", do you think I could compare those values to the arrays I have already?
 
Upvote 0
Darn, not what I was hoping to hear. Thank you for your help. I'm going to think on this some more and change my approach.
 
Upvote 0

Forum statistics

Threads
1,215,019
Messages
6,122,707
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top