I understand that code execution in a sub ends at the return statement. In a class module (b4a 8.80), I was creating a trivial public sub that returns the value of the private variable sErrorMessage, but I also wanted to clear the sErrorMessage value, so that if LastError is called twice in a row, it will only return a value one time. Ok that's easy. Except of course I cannot set sErrorMessage="" after the Return statement, because it will never execute. So I did this:
However the above, in all cases, returns empty string, even if sErrorMessage had a value. I'm guessing the value is getting assigned to sTemp, how could it not, but then the Return of sTemp doesn't work as expected -- maybe because the variable is local and getting deallocated when the sub folds up? Still the very simple example above makes me think something odd is going on with Return. How should I have done this? One workaround I've found that works is removing the Dim statement and declaring sTemp in Class_Globals. I've stared at this for about 20 minutes wondering if I'm losing my mind. Is there some other obvious reason I can't return the value as shown above? Just curious at this point. Thanks!
Public Sub LastError As String Dim sTemp As String sTemp=sErrorMessage sErrorMessage="" Return sTemp End Sub