Nova Posted November 20, 2004 Share Posted November 20, 2004 Ok I have a bit of a problem here ! In the below code assume the function Input has been called by earlier code (Im not going to post it allunless its totally nessary because its huge) Ok the password entered by the user is stored into the varible $password like so $password=GUIRead($Input) Then a hotkey is set to enter which when pressed checks if the password is correct. Heres where the problem arises becasue $password=GUIRead($Input) is inside 1 function its value gets deleted when that function ends and it ends in order for the nxt function the password check to take place. It appears that I need a Dim Global $password=GUIRead($Input) but this dosent seem possible to the best of my knowledge ! Func Input() GUICtrlSetState ( $Logon, $GUI_SHOW ) $Input = GUICtrlCreateInput ( "", @DesktopWidth/2-25, @DesktopHeight/2 + 10, 300, 25,$ES_PASSWORD) GUICtrlSetState ( $Input, $GUI_FOCUS ) HotKeySet("{ENTER}", "Enter2") $password=GUIRead($Input) EndFunc Func Enter2() if $password = ("correct") then SoundPlay("C:\Nova-Menu\Sounds\Start.wav") ToolTip ( "Password correct, Welcome friend !" , 550, 450) sleep (2000) ToolTip ( "" , 550, 450) else SoundPlay("C:\Nova-Menu\Sounds\End.wav") ToolTip ( "Password incorrect, plz try again !" , 550, 450) sleep (2000) ToolTip ( "" , 550, 450) endif EndFunc Can anyone advise ??? If my probelm isnt apparent from this section of code plz say so and ill post the full script ! Link to comment Share on other sites More sharing options...
Nova Posted November 20, 2004 Author Share Posted November 20, 2004 I understand the problem I just cant figure out a solution ! Link to comment Share on other sites More sharing options...
Developers Jos Posted November 20, 2004 Developers Share Posted November 20, 2004 I understand the problem I just cant figure out a solution !<{POST_SNAPBACK}>This is a "contradiction in termino" ... Just do a Global $password at the top of your program to make the variable available in the whole program without doing a Dim/Local?Global statement for it in the Func. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Developers Jos Posted November 20, 2004 Developers Share Posted November 20, 2004 SCOPE... Global and Local@DEVS: Is this true for loops too?<{POST_SNAPBACK}>The scope for a Local is the Func .. not loops...heres the definitions from the helpfile:Dim = Local scope if the variable name doesn't already exist globally (in which case it reuses the global variable!)Global = Forces creation of the variable in the Global scopeLocal = Forces creation of the variable in the Local/Function scope SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nova Posted November 20, 2004 Author Share Posted November 20, 2004 Just do a Global $password=GUIRead($Input)at the top of your programI cant because $Input isnt defined untill the function input is called ! Link to comment Share on other sites More sharing options...
db26 Posted November 20, 2004 Share Posted November 20, 2004 Also, you can have the Input() function return $password, and the Enter2() function take $password as a parameter. However, this may not work in the context of your program. I can't really tell from what you've posted. I think it should though... Link to comment Share on other sites More sharing options...
Developers Jos Posted November 20, 2004 Developers Share Posted November 20, 2004 (edited) I cant because $Input isnt defined untill the function input is called !<{POST_SNAPBACK}>lost me here, don't see any reason not being able to do:Global $password at the beginning of your script and in a func do :$password=GUIRead($Input)EDIT: By the way ... its better to quote what is really there, not what you read into it.... Edited November 20, 2004 by JdeB SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Nova Posted November 20, 2004 Author Share Posted November 20, 2004 lost me here, don't see any reason not being able to do:Global $password at the beginning of your script and in a func do :$password=GUIRead($Input)A thousand appologies JdeB,I tought that in order to make a varible Global you had to set a value to it !like so Global $password = 'whatever'Ive got my script working now !Tnx everyone for the help ! Link to comment Share on other sites More sharing options...
Developers Jos Posted November 20, 2004 Developers Share Posted November 20, 2004 A thousand appologies JdeB,I tought that in order to make a varible Global you had to set a value to it !like so Global $password = 'whatever'Ive got my script working now !Tnx everyone for the help !<{POST_SNAPBACK}>no problem... It is a good practice the have a section at the top of your program which defines all variables with a global scope and also set the initial value just in case.So you could do that for your $password variable like:Global $password = '' SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
ezzetabi Posted November 21, 2004 Share Posted November 21, 2004 and it is a good habit also using for 'more than 4 lines scripts' Opt('MustDeclareVars',1) It avoids silly but difficult to find mispelling errors and force you give a scope for every variant. Link to comment Share on other sites More sharing options...
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