Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

search array

Status
Not open for further replies.

andreas57

Technical User
Joined
Sep 29, 2000
Messages
110
Location
CH
hello i0've got a problem with a array search. where the arrows are it doesn't work and i tried an alternitiv algorithme which nether worked. i would be very thankful for help.

Dim b(7, 6)

Private Sub winn()
Dim i, c, j, d, e, k, m As Integer
'horizontal
For i = 1 To 6
For c = 1 To 4
If b(c, i) = p And b(c + 1, i) = p And b(c + 2, i) = p And b(c + 3, i) = p Then
win = 3
Exit For
Exit For
End If
Next c
Next i
'vertikal
For j = 1 To 7
For d = 1 To 3
If b(j, d) = p And b(j, d + 1) = p And b(j, d + 2) = p And b(j, d + 3) = p Then
win = 3
Exit For
Exit For
End If
Next d
Next j
'diagonal
For k = 1 To 7
For e = 1 To 3
If k < 4 Then
If b(k, e) = p And b(k + 1, e + 1) = p And b(k + 2, e + 2) = p And b(k + 3, e + 3) = p Then
win = 3
Exit For
Exit For
End If
-->> ElseIf b(4, e) = p And b(5, e + 1) = p And b(6, e + 2) = p And b(7, e + 3) = p Then
win = 3
Exit For
Exit For
-->> ElseIf b(4, e) = p And b(3, e + 1) = p And b(2, e + 2) = p And b(1, e + 3) = p Then
win = 3
Exit For
Exit For
ElseIf k > 4 Then
If b(k, e) = p And b(k - 1, e + 1) = p And b(k - 2, e + 2) = p And b(k - 3, e + 3) = p Then
win = 3
Exit For
Exit For
End If
End If
Next e
Next k
'additional diagonal
For m = 6 To 4
If b(1, e) = p And b(2, e - 1) = p And b(3, e - 2) = p And b(4, e - 3) = p Then
win = 3
Exit For
ElseIf b(7, e) = p And b(6, e - 1) = p And b(5, e - 2) = p And b(4, e - 3) = p Then
win = 3
Exit For
End If
Next m

andreas owen
aowen@swissonline.ch
 
this string is a fail transmission, sorry.

andreas owen
aowen@swissonline.ch
 
this isn't afterall a fail transmission. the program is a game board. i'm looking for diffrent combinations but those with the arrows dont work. i'd be thankful for help please.
andreas owen
aowen@bluewin.ch
 
Where is 'p' declared? Calculated? How is it available to this routine?

What is the intent of the double Exit For statements? (the second of each pair will NEVER be executed).

Why doesn't 'b' have a type? What 'type' of data is in it? Is 'p' of the same 'type'?

Code:
            'Try:
            ElseIf k = 4 Then
                If b(4, e) = p And b(5, e + 1) = p And b(6, e + 2) = p And b(7, e + 3) = p Then
                    win = 3
                    Exit For
                End If

                If b(4, e) = p And b(3, e + 1) = p And b(2, e + 2) = p And b(1, e + 3) = p Then
                    win = 3
                    Exit For
                End If


MichaelRed
mred@duvallgroup.com
There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top