Sign in to follow this  
Followers 0
Bluesmaster

Static & ByRef

53 posts in this topic

#1 ·  Posted (edited)

Is it possible to store a reference given to a function by "ByRef" for later use of the function. The reason I need it is a bit complicated but

any suggestions would be helpfull.

Local $a = 3, $b = 0

test( $a )
test( $b )
test( $b )

ConsoleWrite( $a & @LF )


Func test( ByRef $a )

    static $staticA  = $a

    $staticA += 1

EndFunc

$a should be 6 at the end of the scrip but it is not. What can I do avoiding global variables and ugly string execution?

kind regards

Bluesmaster

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites



Bluesmaster,

For a start the variables you have declared as Local in the first line are actually Global - that is the forced state for all variables declared outside of a function. So your wish to avoid Global variables is doomed from the start! ;)

How about explaining what you want to do rather then just posting a few lines of code? Then we might be able to offer some sensible advice. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi Melba,

The "local" mistake is true. Normally this line is called from within another function, a small weakness of my example. But I want to understand it in deep.

Why cant one store the reference within a static variable? Or better question: How can one achieve this?

ok ok the background: I need a modular fcn ( not just one script, so the variable to store the results has to be flexible) and the fcn is double used as a receiver

of a wm_timer-message. When receives the timer message it has to "remember" the ByRef-variable from the first call. Ah well I told you its s bit complicated but all reasonable.

Oh it seems even my first workaround with global variable fails. But thats a second question then.

global $TestCounter = 1
test()
ConsoleWrite( $TestCounter & @LF )


Func test()
    Execute( "global $TestCounter = 3"  )
EndFunc
Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Why would you be assuming that $a is going to be 6 at the end of that script? You're passing the value ByRef, but copying it to the variable $staticA, and then increasing that value by 1. You never do anything to the incoming value other than copying it to $staticA.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Global $a = 3, $b = 0

test( $a )
test( $b )
test( $b )

ConsoleWrite( $a & @LF )


Func test( ByRef $a )

    static $staticA  = $a
    ConsoleWrite("The Static Variable $staticA is: " & $staticA & @LF)
    ConsoleWrite("The Passed Variable $a is: " & $a & @LF)

    $a += 1

EndFunc


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

(The example with the global variable missed the "global" sorry, my mistake but it does not work even with )

@BrewManNH & JohnOne

Sorry for beeing a bit fuzzy: I do know it cannot work this way cause $a gets only copied but the real question is:

Is it possible in autoIt to store the lets say "pointer" for later use? Or can you as experts tell me that its definitly not possible to archive what I intended?

Thank you very much

Blues


My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Bluesmaster,

I see you have now received other very pertinent advice - I was going to suggest something like this:

Main()

Func Main()

    Local $a = 3, $b = 0, $c = 7

    test($a, True)
    test($b)
    test($b)
    test($c, True)

    ConsoleWrite("At the end, $a = " & $a & @LF)

EndFunc

Func test(ByRef $z, $fFlag = False)

    ; This variable will be retained between calls
    Static $Initial

    ; If the flag is set then reset the variable
    If $fFlag Then
        $Initial = $z
    EndIf
    ConsoleWrite("This pass $Initial = " & $Initial & @CRLF)

    $a += 1
    ConsoleWrite("This pass $a = " & $a & @CRLF)

EndFunc   ;==>test
Any use? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Is it possible in autoIt to store the lets say "pointer" for later use? Or can you as experts tell me that its definitly not possible to archive what I intended?

The code I posted shows that $StaticA is set to the first value the function is passed, and remains that way.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

@JohnOne

 

The code I posted shows that $StaticA is set to the first value the function is passed, and remains that way.

 

Thats true, but it remains a copy inside the function. I need a connection to the "outside world". In the most clearest words I have to provide:

One Function calls the other saying: "Here take this pointer from me and write your results there when you are called later, even if the call comes from another fcn, I will check the results at any later moment wich is  not of your interesst"

But at the moment I got ( even with your and melbas code ): "Here you got an pointer which you can use initial value  and wich you can increment or whatever, but when I read this variable again in my private workspace, it remains the same or misses changes from later calls, because you just copied the value it contained at the first call"

Again: excuse me for making so much trouble about that small question :sweating:

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Bluesmaster,

 

I need a connection to the "outside world"

So get the function to return a value which you can access outside - nothing internal to the function is visible elsewhere. :)

I am still very unclear exactly what you are trying to do here - and why you feel that you cannot use a Global variable. If you need to store a value that is non-volatile and accessible throughout the script then I cannot see any alternative to a Global variable - after all, that is a pretty good description of exactly what makes a variable Global. :D

Rather than these small snippets of code with repeated variable names and all the other problems pointed out above, why not post a logic flow which explains exactly what it is you want to happen with the code. Use plain English and be reasonably verbose so that the underlying requirements are clear - then we might be able to offer you a solution. Perhaps not the one you envisage at present, but one that will actually work. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Hello Melba, thanks for not giving me up, and sorry for my poor english.

So point by point:

1. I can not use global variables, because my function needs to be modular. It would be extremly bad practice to write into the function help: "whenever you use this function, the results will be stored in the global variable <foo>"

2. The soft way of 2 functions ( and only those 2! )  sharing a variable ( lets call it X ) is "ByRef" wich gives Fcn2 access to X in workspace of Fcn1?

3. My goal is to maintain this access to X ( like in c++ a pointer can do ) even when Fcn2 is called from another source wich does NOT have access to X ( in my case an external event namely a  WM_TIMER event, Fcn2 is kind of polymorph )

4. The main problem is that Fcn1 cannot wait for Fcn2 as usual but should instead check X at certain intervalls.

5. If you tell me, that one simply cannot maintain this "ByRef"-access for multiple fcn calls I will develop another workaround wich make some effort, but I want to be sure it is impossible first :)

6. Even if I try to use a global variable wich the "user" can choose a name ( realised by an execute()-statement ) for this seems not to work as I showed in this example: where $TestCounter stays 1

global $TestCounter = 1
test()
ConsoleWrite( $TestCounter & @LF )


Func test()
    Execute( "global $TestCounter = 3"  )
EndFunc

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

For a  better understanding here is an example of such a multipurpose-fcn I wrote some time ago:

; Test
HotKeySet("{ESC}", "_Exit")
Func _Exit()
    Exit
EndFunc
processHook( "testProcessHookCallback" , "notepad.exe"  , 1 , 2000 )
Sleep(2^22)

Func testProcessHookCallback( $processName , $eventType )
    ConsoleWrite( "event: "  & $processName &  "  "  & $eventType & @LF )
EndFunc


Func processHook( $callback  , $processToWatch = "notepad.exe" , $eventType = 1 , $pollingRateMilliSec = 3000   )
; Note: do not add aditional parameters to the function or delete one, as it needs exactly an interface of 4 parameters to catch timer callbacks

    ; $callback = fcn to call wenn event detected  >> fcn signature: callback( $processName )
    ;
    ; $processWatch = call fcn 2x with the same processname.exe will unhook
    ;
    ; eventType = 0  >> Process ended
    ;           = 1  >> Process created
    ;           = 2  >> both


    ; 1 - INIT
    static $aProcessesToBlock[ 100 ][ 2 ] ; fixe definition, weil redim mit statischen variablen erst ab ai 3.3.9.x funktioniert
    static $hmessageReceiverGUI = GUICreate( "" )
    static $r1 = GUIRegisterMsg( 0x0113 , "processHook" ) ;     $WM_TIMER = 0x0113
    static $r2 = DllCall( "user32.dll" , "uint_ptr" , "SetTimer" , "hwnd" , $hmessageReceiverGUI , "uint_ptr" , 12345 , "uint" , $pollingRateMilliSec , "ptr", 0 )   ;  12345 = timerID
    static $staticCallback  = $callback
    static $staticEventType = $eventType

    if IsString( $callback ) Then

        for $i = 1 to UBound( $aProcessesToBlock )-1

            if  $aProcessesToBlock[ $i ][ 0 ] = $processToWatch Then
                $aProcessesToBlock[ $i ][ 0 ] = ""
                ExitLoop
            EndIf

            if  $aProcessesToBlock[ $i ][ 0 ] = "" Then
                $aProcessesToBlock[ $i ][ 0 ] = $processToWatch
                $aProcessesToBlock[ $i ][ 1 ] = ProcessExists( $processToWatch ) ; erstmaliger Check des prozesses

                ; merken bis wohin iteriert werden muss ( falls später Lücken ins array kommen wegen unhook )
                if $aProcessesToBlock[ 0 ][ 0 ] < $i Then $aProcessesToBlock[ 0 ][ 0 ]  = $i
                ExitLoop
            EndIf

        Next


    ; 2 - SURVEILLE
    Else

        for $i = 1 to $aProcessesToBlock[ 0 ][ 0 ]

            $curProcess = $aProcessesToBlock[ $i ][ 0 ]
            $processExistedOnLastIteration = $aProcessesToBlock[ $i ][ 1 ]  <>  0
            $processExistsThisIteration    =  ProcessExists($curProcess )   <>  0

            if      NOT ( $processExistsThisIteration )   _  ; Prozess beendet?
                AND $processExistedOnLastIteration        _
                AND    (  $staticEventType = 1  OR   $staticEventType = 2 )       Then Execute( "testProcessHookCallback" & "("  & '"' & $curProcess  & '" ,' &   "0 )"   )

            if           $processExistsThisIteration      _  ; Prozess gestartet?
                AND NOT( $processExistedOnLastIteration ) _
                AND    (  $staticEventType = 1  OR   $staticEventType = 2 )       Then Execute( "testProcessHookCallback" & "("  & '"' & $curProcess  & '" ,' &   "1 )"   )

            ; Prozessexistenz speichern
            $aProcessesToBlock[ $i ][ 1 ]   =   $processExistsThisIteration

        Next

    EndIf

EndFunc

It monitores processes to appear and disappear. The clue is:  Its just one Fcn without external depencies that does the following 2 tasks:

- get the users parameters

- receive and resolve later events

so its:

- non-blocking

- totaly modular usable ( just copy n paste without external depencies )

but:

it does not have to write results back to the call (what the new fcn I am planning should do)


My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Bluesmaster,

Clever little function that one. :thumbsup:

Let me see if I have it clear - you want this modular function to continually update the original calling function when it is subsequently called by third function such as a timer? :huh:

Func Func_1()
    
    Local $vVar ; This is the variable to keep updated
    Func_2("various parameters")
    
EndFunc


Func Func_2("various parameters")
    
    If "Called from Func_1" Then
        ; Do things including setting a timer to recall this function
    ElseIf "Called from Timer" Then
        ; Do other things which might change $vVar
        ; Somehow update $vVar if changed
    EndIf
    
EndFunc
Does that sum up the problem or am I completely off track? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Yes exactly

And you will now tell me, that it is impossible right? ;)

 

I had the idea of implementing a kind of ID-system. So when Fcn1 calls Fcn2 then Fcn2 returns some kind of GUID. Fcn1 can later use this GUID to call Fcn2 again to receive the results matching with the initial config.

But as you can imagine this is an ugly, costly solution. So I tried the "execute"-"global uservarname" combination. But it also fails :(

regards

 

edit: Do you think some kind of DLL-structure /  pointer combination could help?

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Bluesmaster,

 

Yes exactly

Hurrah! :party:

 

Do you think some kind of DLL-structure / pointer combination could help?

Way ahead of you - but so far without success: :(

#include <WinAPI.au3>

HotKeySet("{ESC}", "On_Exit")

While 1
    Func_1()
    Sleep(5000)
WEnd


Func Func_1()

    Static $fFirstPass = True
    Local $vB, $vD

    $tStruct_1 = DllStructCreate("int")
    DllStructSetData($tStruct_1, 1, "9999")
    $pPointer = DllStructGetPtr($tStruct_1)

    If $fFirstPass Then
        ; Initiate the whole thing
        ConsoleWrite("Initiating" & @CRLF)
        Func_2("String", $vB, $pPointer, $vD)
        $fFirstPass = False
    EndIf

    ; What do we have in the struct?
    ConsoleWrite("Reading from struct: " & DllStructGetData($tStruct_1, 1) & @CRLF)

EndFunc


Func Func_2($vW, $vX, $pPointer, $vZ)

    Static $hmessageReceiverGUI = GUICreate("")
    Static $r1 = GUIRegisterMsg(0x0113, "Func_2") ;     $WM_TIMER = 0x0113
    Static $r2 = DllCall("user32.dll", "uint_ptr", "SetTimer", "hwnd", $hmessageReceiverGUI, "uint_ptr", 12345, "uint", 2000, "ptr", 0)
    Static $staticPointer = $pPointer
    Static $staticProcesshandle = _WinAPI_OpenProcess(0x00000020, False, @AutoItPID, False) ; $PROCESS_VM_WRITE
    Local $iError = @error

    Local $tStruct_2 = DllStructCreate("int")
    Local $iSec, $iWritten, $iRead

    If IsString($vW) Then
        If $iError Then
            ConsoleWrite("OpenProcess failed" & @CRLF)
            Exit
        Else
            ConsoleWrite("Process handle = " & $staticProcesshandle & @CRLF)
        EndIf
    Else
        $iSec = @SEC
        ConsoleWrite("Timer fired at " & $iSec & @CRLF)
        DllStructSetData($tStruct_2, 1, $iSec)
        $fRet = _WinAPI_WriteProcessMemory($staticProcesshandle, $staticPointer, DllStructGetPtr($tStruct_2), 4, $iWritten)
        ConsoleWrite("Write result = " & $fRet & " - " & $iWritten & @CRLF)
    EndIf

EndFunc

Func On_Exit()
    Exit
EndFunc
The script returns a process handle but the write operation fails for some reason. I am afraid I am now well out of my depth - I will ask some others to look in and see if they can help. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Thanks for making so much effort trying to help me.

The solution you posted is way to powerfull, as it allows even interprocess communication. I just need "inter-fcn" communication.

I worked out an example:

Main()

Func Main()

   Local $initialA = 3, $b = 0

   $a = DllStructCreate( "int var1" )
   DllStructSetData( $a , "var1", $initialA )

   test( DllStructGetPtr($a) , True )
   test( $b )


   ConsoleWrite("At the end, $a = " &  DllStructGetData( $a , "var1" ) & @LF )


EndFunc



Func test( $pointerToResultVar , $fFlag = False )

    Static $staticPointerToResultVar

    If $fFlag Then
        $staticPointerToResultVar = $pointerToResultVar
    EndIf


    Local $a
    $a = DllStructCreate( "int var1" , $staticPointerToResultVar )
    $oldA = DllStructGetData( $a , "var1" )

    ConsoleWrite( $oldA & @LF )

    DllStructSetData( $a , "var1" , $oldA  + 1 )

EndFunc   ;==>test

This is working now. But you know what: its ugly again ^^

Telling the user to create a dll-struct and so on is even more complicated than telling him to use a certain global variable. Well I keep thinking. I will post any solutions.

Other suggestions are welcome of course :)

Edited by Bluesmaster

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

Bluesmaster,

I did say I was out of my depth! :D

Sorry I could not be of more help. Please do let us know if you come across a solution. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Oha, seems as my "execute"-"global" attempt was a nooby mistake as "execute" performs a comparison instead of an assignment:

$TestCounter = 1
test( "TestCounter" )
ConsoleWrite( $TestCounter & @LF )

Func test( $nameOfGlobalResultVariable )
    Execute( "global " & $nameOfGlobalResultVariable  )
    Assign( $nameOfGlobalResultVariable , 3 )
EndFunc

My UDF: [topic='156155']_shellExecuteHidden[/topic]

Share this post


Link to post
Share on other sites

An answer to the question in the first post.

Can't you just do something like this:

main()


Func main()

  Local $a = 3, $b = 0

  test( $a, 1 )
  test( $b )
  test( $b )
  test( $a, 2 )

  ConsoleWrite( $a & @LF )

EndFunc


Func test( ByRef $a, $flag = 0 )

  Local Static $staticA

  Switch $flag
    Case 0 ; $b as parameter (or $c, $d ...)
      ; Code when $b is parameter (or $c, $d ...)
    Case 1 ; $a as parameter, init $staticA
      $staticA = $a
    Case 2 ; $a as parameter, get $staticA
      $a = $staticA
      Return
    Case Else
  EndSwitch

  $staticA += 1

EndFunc

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0