11-12-2022, 04:38 AM
(11-12-2022, 04:24 AM)mnrvovrfc Wrote: If you're more comfortable writing subprograms then don't change that. Using "GOSUB" and "RETURN" isn't a great advantage by this time especially if you expect your BASIC code compatible with Freebasic or Purebasic. For example, for Freebasic you only need to change function name on LHS and equals to "RETURN", that's why "GOSUB" was eventually dumped by them to follow along with Visual Basic.
Coding while relying on "GOSUB" sections of code must have global variables always. If you're not used to it, it's going to be a mess trying to force that issue with "SUB... END SUB" and "FUNCTION... END FUNCTION" while they weren't designed for that purpose. If you need a local variable that has to keep its value after the subprogram is in must leave, and then come back, use "STATIC" to declare it instead of "DIM". In fact the whole subprogram could be declared "STATIC" (use keyword at the end after parameter list). But probably you knew this already.
I haven't used STATIC yet. I don't think my programming is very sophisticated, so I usually just DIM SHARED most of the time. I found that to be much easier than passing variables to sub programs and keeping track of that. I assume that STATIC would be similar to CONST? I checked the wiki and it says it's for retaining values, but I don't know what the difference would be (STATIC vs CONST)
I'm comfortable using SUB / END SUB for sure, just wondered if GOSUB might be an advantage sometimes, as it seems that was the case in this example.