11-12-2022, 04:56 AM
(11-12-2022, 04:38 AM)james2464 Wrote: 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.
STATIC is a bit like a local CONSTANT. That means it remains in the SUB. Let's say you are counting something with the variable cnt, but it isn't shared or passed. by declaring it as a STATIC variable, you can come back to the counting SUB and pick right up where you left off. If you didn't either pass the cnt variable, or declare it as SHARED or STATIC, cnt would be zeroed the next time the counting SUB call was made.
Code: (Select All)
SUB mySUB
STATIC cnt
Pete