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
 

kayleeh

New Member
Joined
Dec 3, 2014
Messages
5
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>
 

kayleeh

New Member
Joined
Dec 3, 2014
Messages
5
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.
 

Andrew Poulsom

MrExcel MVP
Joined
Jul 21, 2002
Messages
73,092
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
 

kayleeh

New Member
Joined
Dec 3, 2014
Messages
5
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?
 

kayleeh

New Member
Joined
Dec 3, 2014
Messages
5
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.
 

Forum statistics

Threads
1,081,418
Messages
5,358,559
Members
400,504
Latest member
RedSquirrel

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top