Declare test_it(variable)
Global variable=#False
Debug "value of variable:"+Str(variable)
test_it(#False)
Debug "value of variable:"+Str(variable)
End
Procedure test_it(variable)
variable=#True
ProcedureReturn #False
EndProcedure
It returns #False although inside the procedure I change the variable to #True.
EDIT: changed the version on topic, I only tested with 5.70 not 5.71, sorry.
Do not post to Bugs if you are not sure.
Your code is wrong.
You pass in a Global variable which is copied inside the Procedure.
This is called ByVal.
What happens to the variable inside the Procedure is like Vegas. It stays there.
After the Procedure, the Global variable is unchanged.
EnableExplicit
Procedure test_ByVal(variable)
; variable is passed by value.
; Even though it matches name of a Global variable
; it does not change the Global value.
variable=1
ProcedureReturn 0
EndProcedure
Procedure test_ByRef(*variable.Integer)
; variable is passed by reference.
; This changes the Global value.
*variable\i=1
ProcedureReturn 0
EndProcedure
Global variable=0
Debug "BEFORE TEST variable = "+Str(variable)
test_ByVal(variable)
Debug "AFTER ByVal variable = "+Str(variable)
test_ByRef(@variable)
Debug "AFTER ByRef variable = "+Str(variable)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
;// Precedence for scope of variables (and not prototypes, structures, enumerations, procedures, etc.) //
;The first declared prohibits further declaration of all others having the same name that are active in the current scope.
;--- Outside procedure ---
Global (global scope)
Threaded (global scope)
Define (local scope to main code outside procedures)
;--- Inside procedure ---
parameter (local scope to procedure)
Global (global scope)
Threaded (global scope)
Protected (local scope, can be defined after a Global and will override Global's scope)
Static (local scope)
Define (local scope, can also repeat the declaration of a parameter, i.e. they are equivalent except Define can also assign an initial value)
Last edited by Demivec on Tue Jun 18, 2019 7:06 am, edited 1 time in total.
Global variables considered harmful. Avoid at any cost. When impossible give it a very weird name, as "___glb_my_inevitable_global_variable_". I have only one project in purebasil some 100k lines and less than 20 global variables, and counting down.