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