Author Topic: Global Variables  (Read 395 times)

mueer01

  • Newbie
  • *
  • Posts: 21
Global Variables
« 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( )

---

td

  • Tech Support
  • *****
  • Posts: 4044
    • WinBatch
Re: Global Variables
« Reply #1 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
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

mueer01

  • Newbie
  • *
  • Posts: 21
Re: Global Variables
« Reply #2 on: January 18, 2022, 01:24:40 am »
Many Thanks

kdmoyers

  • Sr. Member
  • ****
  • Posts: 452
Re: Global Variables
« Reply #3 on: January 18, 2022, 07:49:50 am »
Here's another example
Code: Winbatch
    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

  • Tech Support
  • *****
  • Posts: 4044
    • WinBatch
Re: Global Variables
« Reply #4 on: January 18, 2022, 01:49:56 pm »
How about declaring today obfuscation Tuesday?

Code: Winbatch
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

  • Sr. Member
  • ****
  • Posts: 452
Re: Global Variables
« Reply #5 on: January 18, 2022, 03:24:50 pm »
whoa, that's good! I'm going to have to stare at that a bit...
The mind is everything; What you think, you become.