I have created a recursive function that is called within a For loop, but I'm having a problem with one chunk of the code. From the code below it hopefully is clear that there should be a scenario in which the recursive function goes "backwards" (going back to the For loop from where it was called). What I would like to have happen is to have the probInt variable not go backwards (if that makes any sense).
For example, assuming the first IF statement is FALSE when the function is first called, probInt will be set to 0 and then SOLVE will be called again. If the IF statement is TRUE the second time the function is called, then probInt will be set to 1 and then the function will be exited - returning us to the initial FOR loop. I'm finding that when I return to that initial FOR loop, probInt is set to 0 again and not 1. How can I set this up so that probInt stays at 1 even when the recursive function goes backwards?
Public probInt As Integer
Function Solve()
If (some value in the spreadsheet) = 0 Then
probInt = probInt + 1
Exit Function
End If
For i = 0 To (some other value in the spreadsheet)
probInt = 0
Call Solve()
Next i
Exit Function
probInt = 0out of the loop?