Change in Function operation?
#1
The following worked several versions back:

Function CountUnmarked% (KSorCC$)
    CountUnmarked% = 0
    If KSorCC$ = "KS" Then
        For x = 1 To TotKSrecs%
            If KSdata$(Assigned%, x) = "N" Then CountUnmarked% = CountUnmarked% + 1
        Next x
    Else
        For x = 1 To TotCCrecs%
            If CCdata$(Assigned%, x) = "N" Then CountUnmarked% = CountUnmarked% + 1
        Next x
    End If
End Function



With PE edition, you cannot use the variable CountUnmarked% the same as you would any other variable (within the function). It appears that QB64 thinks that you are calling the function again.  Instead you have to use a temp variable and then assign that value to CountUnmarked% before exiting the function:


Function CountUnmarked% (KSorCC$)
    tCountUnmarked% = 0
    If KSorCC$ = "KS" Then
        For x = 1 To TotKSrecs%
            If KSdata$(Assigned%, x) = "N" Then tCountUnmarked% = tCountUnmarked% + 1
        Next x
    Else
        For x = 1 To TotCCrecs%
            If CCdata$(Assigned%, x) = "N" Then tCountUnmarked% = tCountUnmarked% + 1
        Next x
    End If
    CountUnmarked% = tCountUnmarked%
End Function



Is this because recursion code changed ?  I can make adjustments if this is proper operation, no biggie.  I just wanted to mention this in case is this is a bug...<ahem>...errr...an 'undocumented feature'.

Thanks to all,
Dano
Reply
#2
It's not a bug, functions were changed starting with version QB64 2.0.

"(I think QB64 thinks that you are calling the function again). "

Good way to think about it.
b = b + ...
Reply
#3
Full story about that change is here: https://qb64forum.alephc.xyz/index.php?topic=4209
Reply
#4
https://qb64phoenix.com/qb64wiki/index.php/MEM

It has a relation to example #3 of the page indicated above. I offered at least one program on this forum which used "ConvertOffset()" but couldn't supply it the way it was shown on that page. I'm glad it was changed to how it is now. Using a "FUNCTION's" name like a variable is a source of confusion. That's why I liked Free Pascal (at least the 32-bit Windows version I had) allowing "Result" or "Function" on LHS of assignment inside a function to set the function's return value.
Reply
#5
That works for me. Thank you all for the quick replies!
Reply




Users browsing this thread: 1 Guest(s)