View Full Version : Solved: Execute a sub only one time?
I've forgotten how! (Old age?): I want to run a sub that defines several values, but only want to run it one time. I need a signal in the sub (or in "common!...Old FORTRAN USER") that will tell the program the sub has been run. Is it "permanent", 'Constant"...or what?
Oorang
04-12-2009, 11:33 AM
Here is one quick and dirty way:
Public Sub Example()
Static blnRunOnce As Boolean
If blnRunOnce Then Exit Sub
blnRunOnce = True
'Do stuff here.
End Sub
By making the variable static, it's value will be preserved between calls. It will be false by default causing it to get flagged as true and the code to execute. In all future calls the value will be True, and it will exit before any code executes.
"Static"! It came to me just now while showering.
Oorang
04-12-2009, 02:13 PM
You read this thread while showering!?
eek
:jester:
Sure, I take my work with me!
No, just the memory of "Static" came to me! But your example aso helped!
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.