Android Question Wordsearch Puzzle

brianwiz12

Active Member
Licensed User
Longtime User
Im getting a syntax error and invalid number of indices.2 expected in the following code

indices.2 expected. Invalid Number:
Sub CheckHorizontal(row As Int, col As Int, checkLength As Int, word As String) As Boolean
    If col + checkLength > wordSearchGrid(row).Length Then
        Return False ' Word goes out of bounds horizontally
    End If

    For i = 0 To checkLength - 1
        If wordSearchGrid(row, col + i) <> word.CharAt(i) Then
            Return False ' Mismatch found, word not present horizontally
        End If
    Next
    Return True ' Word found horizontally
End Sub
 

emexes

Expert
Licensed User
Is wordSearchGrid() a 1-dimensional array, or 2-dimensional?

If it is an array of arrays, then it is new to me that you could access it using two indices inside one set of brackets.
 
Upvote 0

emexes

Expert
Licensed User
Lol you could put the letter check inside a Try so that if you access wordSearchGrid() past its edges then it does a Catch Return False.

Should work, but feels dangerous.
 
Upvote 0

emexes

Expert
Licensed User
The Year of Programming Dangerously:
Sub CheckHorizontal(row As Int, col As Int, checkLength As Int, word As String) As Boolean
    For i = 0 To checkLength - 1
        Try
            If wordSearchGrid(row, col + i) <> word.CharAt(i) Then
                Return False ' Mismatch found, word not present horizontally
            End If
        Catch
            Return False ' Word goes out of bounds
        End Try
    Next
    Return True ' Word found horizontally
End Sub
 
Upvote 0
Top