Sub solve(sudoku1(,) As Int, cellX As Int, cellY As Int)
'If the y value is 9 then the sudoku has been solved. How do we exit from here as fast as possible?
If(cellY > 8) Then
endtm = DateTime.Now
Dim cnt As Int = 0
For i = 0 To 8
For j = 0 To 8
lab(cnt).text = sudoku(i,j)
cnt = cnt + 1
Next
Next
'I SOMEHOW NEED TO EXIT FROM HERE AS THE SOLUTION HAS BEEN FOUND
'USING Return DOES NOT SOLVE THE PROBLEM
'IS IT BUSY PROCESSING EVERYTHING THAT HAS BEEN PUSHED ONTO THE STACK BEFORE IT RETURNS CONTROL TO THE UI?
Log("Solved puzzle No " & randnum & " in " & (endtm - starttm) & "ms")
Label1.Text = "Solved puzzle No " & randnum & " in " & (endtm - starttm) & "ms"
Return
Else
Dim nextX As Int = cellX
Dim nextY As Int = cellY
If(cellX = 8) Then
nextX = 0
nextY = nextY + 1
Else
nextX = nextX + 1
End If
If(sudoku1(cellY,cellX) <> 0) Then
solve(sudoku1, nextX, nextY) 'SUB IS CALLING ITSELF - is it adding too much to the stack and then once a solution has been found the excessive
'delay to process the stack before returning control to the B4A UI?
Else
For checkNum = 1 To 9
If (checkSquare(sudoku1, cellX, cellY, checkNum) AND checkRow(sudoku1, cellY, checkNum) AND checkCol(sudoku1, cellX, checkNum)) Then
sudoku1(cellY,cellX) = checkNum
solve(sudoku1, nextX, nextY) 'SUB ALSO CALLING ITSELF
End If
Next
sudoku1(cellY,cellX) = 0
End If
End If
End Sub