Kenneth Ismert
kismert at gmail.com
Thu Sep 22 17:33:47 CDT 2011
> Stuart McLachlan: > You and I obviously have a different definition of > "Global". :-) Changing Private to Public changes > everything ... > ... Why not just create a Globals object instead > and get full class functionality? 'Global Variables' includes globally scoped classes or static functions that allow changeable values. This is my critical point: a writable property of a global class can be changed by anyone anywhere at any time -- just like a global variable, which is supposedly 'bad' for the same reason. So, just using global classes or functions doesn't fix the root problem of global variables. > Read once, write many variable: > Static Function mySafeGlobal(Optional invalue as Variant) as Variant > Dim store as Variant > If not isempty(store) then > mySafeGlobal = store > Exit Function > End if > If not ismissing(invalue) then > store = invalue > mySafeGlobal = store > End if > End Function Looking at the code, I assume you mean 'write once, read many'. And a typo: store should be Static, nod Dim'ed, otherwise you can change the value every time it is called. I use functions similar to this all the time. Contributing code is the most valuable way to work through the real issues of this discussion. -Ken