[RESOLVED] Variable not retaining value when exiting sub.
Hi,
Can someone explain why a public variable is not retaining it's value when exiting a subroutine.
I want to search through an array and if a condition is hit then the subroutine exited (thereby holding the index value of a variable named MarkerNo)
The variable is dimmed in a separate module as public.
Code:
Public Sub FindMarker()
For MarkerNo As Integer = 0 To UBound(Markers)
If A(MarkerNo) = B Then Exit Sub
Next
MarkerNo = -1 'Return -1 if not found
End Sub
Re: Variable not retaining value when exiting sub.
if you have it declared public in a module:
vb Code:
Public Sub FindMarker()
For MarkerNo = 0 To UBound(Markers)
If A(MarkerNo) = B Then Exit Sub
Next
MarkerNo = -1 'Return -1 if not found
End Sub
Re: Variable not retaining value when exiting sub.
Putting "As Integer" in your for loop declares it again for use within the loop ONLY
Kris
Re: Variable not retaining value when exiting sub.
ohh of course..
Thankyou.