Global Variables

Started by mueer01, January 17, 2022, 07:42:39 AM

Previous topic - Next topic

mueer01

Hello,

is it possible to define GLOBAL variables?

Example:
---
#DefineFunction TestFunction()
   Message( "Global", GlobalVariable )
#EndFunction

GlobalVariable = "Hello"
TestFunction( )

---

td

Please see the PtrGLobalDefine function in the Consolidated WIL Help file or online here:

https://docs.winbatch.com/mergedProjects/WindowsInterfaceLanguage/html/WILLZ_P__015.htm
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mueer01


kdmoyers

Here's another example
Code (winbatch) Select
    fred = 6
    ptrglobaldefine(fred)       ; make that variable "global"

    #definefunction abc(x)
        fred = ptrglobal(fred)  ; grab the pointer
        *fred += 1              ; add one to the value
        return x + *fred        ; use the value to compute something
    #endfunction

    message('', abc(100) )      ; shows 107
    message('', abc(100) )      ; shows 108

    exit
The mind is everything; What you think, you become.

td

How about declaring today obfuscation Tuesday?

Code (winbatch) Select
x = 42
PtrGlobalDefine(x)
PtrGlobalDefine(pX)
ppX  = PtrGlobal(px)
*ppX = PtrGlobal(x)

#DefineFunction Useless()
   g_ppX = PtrGlobal(pX)
   g_px = *g_ppX
   return *g_px
#EndFunction

z = Useless()

Message('True?', z:' == ':x)

exit


"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

kdmoyers

whoa, that's good! I'm going to have to stare at that a bit...
The mind is everything; What you think, you become.