Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click 'label for GoTo statements is Tryline: '3 ships 4 length Dim a(10, 10) As Boolean, b(10, 10) As Boolean, c As Integer, x As Integer, y As Integer, ox As Integer, oy As Integer, picG(10, 10) As PictureBox, picR(10, 10) As PictureBox For c = 1 To 3 Try Tryline: For x = 0 To 9 For y = 0 To 9 a(x, y) = False 'clears array after each Try/Catch cycle Next y Next x ox = Int(Rnd() * 10) 'coordinates saved in origional x/y oy = Int(Rnd() * 10) c = Int(Rnd() * 4 + 1) 'direction If a(ox, oy) = True Then GoTo Tryline End If a(ox, oy) = True 'marked Select Case c Case 1 'up For y = 1 To 4 If a(ox, oy + y) = True Then GoTo Tryline Else a(ox, oy + y) = True End If Next y Case 2 'Down For y = 1 To 4 If a(ox, oy - y) = True Then GoTo Tryline Else a(ox, oy - y) = True End If Next y Case 3 'Left For x = 1 To 4 If a(ox - x, oy) = True Then GoTo Tryline Else a(ox - x, oy) = True End If Next x Case 4 'right For x = 1 To 4 If a(ox + x, oy) = True Then GoTo Tryline Else a(ox + x, oy) = True End If Next x End Select Catch q As IndexOutOfRangeException GoTo Tryline Catch q As Exception Dim result As Integer result = MsgBox("A fatal error has occurred in the code, please contact the programmer that wrote this program so he can fix it." + Str(q), 48, "Error!") If result = vbOK Then Beep() End End If Finally For x = 0 To 9 For y = 0 To 9 If a(x, y) = False Then For ox = 0 To 9 For oy = 0 To 9 If x = ox And y = oy Then picR(ox, oy).Visible = True Else picG(ox, oy).Visible = True End If Next oy Next ox End If Next y Next x End Try Next c End Sub
I've also attatched the picture of my form design so you can get an idea of what it looks like.
What I'm trying to do, is like for example, when you have a 2D boolean array, you use nested for loops to mark stuff off, and then use those positions for something later like:
For x = 0 to 9 For y = 0 to 9 If a(0,0)= True Then 'select case statements... blablabla... (0,) is ace, and (,0) is spades picAceofSpades.Visible=True End If
But as you can see in my project code, i have a wierd special case, and I haven't yet found a way to link the array and the pictures because you can't exactly say
if a(x,y)=True then picR(x,y).visible=True End If
If all of my picboxes are named by coordinates and color. ex: picR00 is the red picture box that represents (0,0).
THANK YOU IN ADVANCE SOOO MUCH TO WHOEVER ANSWERS MY LONG WINDED POST!!!!!