× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Kurt Anderson wrote:
Every so often I come across a situation where I'd like to use a static variable in a subprocedure because I want to keep that variable's value between subP calls - and if I can keep it encapsulated and not have to make it a global variable, all the better. But the one thing I can never really get a grip on is how to control when I should be resetting that value. A typical use for this may be a subprocedure that toggles a value on the screen. So if I could call toggleValue() the subP would already know the current toggle state.
Should I add a *nopass parm that is used to tell the subP that I want the toggle value reset? I'm just curious how the general community is doing this. I'm currently using a global variable to control this (or if not global a higher level local variable).

You've hit on the right answer, I think, Kurt. You've got one of two choices, basically. If you're already passing an opcode parameter (something to tell the subprocedure what to do) then adding an "INIT" opcode is the best way. But if you're not, then changing the number of parms is as good a way to communicate as any. If you normally DO pass parameters, then DON'T pass any to signal a initialization. If you normally DON'T pass any parameters, then DO pass one to signal initialization.

Joe



As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.