jennico Posted September 7, 2008 Posted September 7, 2008 (edited) hi there, is it possible to prevent a variable that is globally declared in an include file from being valid globally in the parent script ? thx j. Edited September 7, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96
martin Posted September 7, 2008 Posted September 7, 2008 hi there, is it possible to prevent a variable that is globally declared in an include file from being valid globally in the parent script ? thx j.Various ways but it might depend on how the variable is originally declared. If you make your parent script a function then you can declare the same variable name locally in the function. Eg global const $f=5;could have been declared in an include file hh() ConsoleWrite($f & @CRLF) func hh() local $f=4 ConsoleWrite($f & @CRLF) EndFunc You might also be abl eto use IsDeclared and Assign. Best way is to have a different variable name though. Why do you need to use the same name? Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Valuater Posted September 7, 2008 Posted September 7, 2008 (edited) Straight from help... If Not IsDeclared ("a") then MsgBox(0,"", "$a is NOT declared") ; $a has never been assigned EndIf $a=1 If IsDeclared ("a") then MsgBox(0,"", "$a IS declared" ) ; due to previous $a=1 assignment EndIf if using a function use local $a=1 inside the function 8) Edited September 7, 2008 by Valuater
jennico Posted September 7, 2008 Author Posted September 7, 2008 (edited) Best way is to have a different variable name though. Why do you need to use the same name?well, i don't know what name the user chooses in his script. i just write the include file and i want to ensure my global variables not to be assigned in the user's script so they do not mix something up. in an include file there can be two types of globals: - the ones needed in parent scripts to work like SW_POPUP a.s.o - and others that are not declared with the intention to be used in the parent script but still they have to be global in the include script. as valuater and martin (thank you !) state, you can prevent interference by assigning all parent function variables consequently locally and always in the parent script. i think, that's the deep sense of the Local scope that i did not understand before. but can't there be an "easier" way to de-assign the variable on returning from the include inside the include file ? j. could it be made possible to de_assign a variable, e.g by the "Assign()" command with flag -1 ? Assign($a,"",-1) => $a not declared anymore or e.g. a further scope declaration keyword besides global, local and dim, that ensures assignment within the script, but not in the other ? it could be called "limited" (because the assignment is limited to the script) or whatever. Global $WS_POPUP Limited $sArray[5] or is this a stupid idea or not possible in a I/0 context ? Edited September 7, 2008 by jennico Spoiler I actively support Wikileaks | Freedom for Julian Assange ! | Defend freedom of speech ! | Fight censorship ! | I will not silence.Don't forget this IP: 213.251.145.96
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now