WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: mueer01 on January 17, 2022, 07:42:39 AM

Title: Global Variables
Post by: mueer01 on January 17, 2022, 07:42:39 AM
Hello,

is it possible to define GLOBAL variables?

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

GlobalVariable = "Hello"
TestFunction( )

---
Title: Re: Global Variables
Post by: td on January 17, 2022, 08:01:56 AM
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
Title: Re: Global Variables
Post by: mueer01 on January 18, 2022, 01:24:40 AM
Many Thanks
Title: Re: Global Variables
Post by: kdmoyers on January 18, 2022, 07:49:50 AM
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
Title: Re: Global Variables
Post by: td on January 18, 2022, 01:49:56 PM
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


Title: Re: Global Variables
Post by: kdmoyers on January 18, 2022, 03:24:50 PM
whoa, that's good! I'm going to have to stare at that a bit...