Change in Function operation? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Change in Function operation? (/showthread.php?tid=898) |
Change in Function operation? - dano - 09-17-2022 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 RE: Change in Function operation? - bplus - 09-17-2022 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. RE: Change in Function operation? - RhoSigma - 09-17-2022 Full story about that change is here: https://qb64forum.alephc.xyz/index.php?topic=4209 RE: Change in Function operation? - mnrvovrfc - 09-17-2022 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. RE: Change in Function operation? - dano - 09-18-2022 That works for me. Thank you all for the quick replies! |