telmob Posted January 8, 2013 Share Posted January 8, 2013 (edited) How do i return a value to a running function? The following example (not a real code) shows a function that checks for a need for password input. If needed, it will open a gui password input. If the password is correctly inserted then it should return the 'uneeded password input' value and continue the previous function. Did i complicate to much!? Its because i'm sleepy. How can i solve this? CheckForPassword() RunFunc() Func CheckForPassword() If $password=1 Then $Locked=1 ElseIf $password=0 Then $Locked=0 EndIf EndFunc Func RunFunc() CheckForPassword() If $Locked=1 Then GUISetState(@SW_SHOW,$FormPass) ElseIf $Locked=0 Then DoSomething() EndIf EndFunc Func SubmitPassButton() If Guictrlread($PassInput)="Password" Then Return $Locked=0 ; ??? NO? :) EndFunc My main problem is that i have tens of functions or else i would just call back the function RunFunc() after correct pass input... Edited January 10, 2013 by telmob Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2013 Share Posted January 8, 2013 (edited) telmob, Not sure what you are doing, but, assumming that $locked is "global" in scope this might work. ; ; RunFunc() Func RunFunc() If $Locked = 1 Then GUISetState(@SW_SHOW, $FormPass) ElseIf $Locked = 0 Then DoSomething() EndIf EndFunc ;==>RunFunc Func SubmitPassButton() If GUICtrlRead($PassInput) = "Password" Then $Locked = 0 Else $Locked = 1 endif EndFunc ;==>SubmitPassButton Not tested, of course. kylomas edit: even simpler example eliminating variables RunFunc() Func RunFunc() If SubmitPassButton() Then GUISetState(@SW_SHOW, $FormPass) Else DoSomething() EndIf EndFunc ;==>RunFunc Func SubmitPassButton() If GUICtrlRead($PassInput) = "Password" Then return true Else return false endif EndFunc ;==>SubmitPassButton Edited January 8, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
michaelslamet Posted January 8, 2013 Share Posted January 8, 2013 use a global variable or use a Return keyword: Func blblablbla . . . return $result EndFunc Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 telmob, Not sure what you are doing, but, assumming that $locked is "global" in scope this might work. RunFunc() Func RunFunc() If $Locked = 1 Then GUISetState(@SW_SHOW, $FormPass) ElseIf $Locked = 0 Then DoSomething() EndIf EndFunc ;==>RunFunc Func SubmitPassButton() If GUICtrlRead($PassInput) = "Password" Then $Locked = 0 EndFunc ;==>SubmitPassButton Not tested, of course. kylomas Thanks kylomas, that is basically what i'm doing, but i need to continue the previous function. use a global variable or use a Return keyword: Func blblablbla . . . return $result EndFunc That is exactly what i'm trying to achieve, but.....: Func RunFunc() CheckForPassword() If $Locked=1 Then GUISetState(@SW_SHOW,$FormPass) ElseIf $Locked=0 Then DoSomething() EndIf EndFunc ...... after i return the result, the function doesn't continue, and i need it to continue. Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2013 Share Posted January 8, 2013 telmob, Does this not do what you want? (lsightly modified from above) RunFunc() Func RunFunc() If SubmitPassButton() Then GUISetState(@SW_SHOW, $FormPass) DoSomething() Else DoSomething() EndIf EndFunc ;==>RunFunc Func SubmitPassButton() If GUICtrlRead($PassInput) = "Password" Then return true Else return false endif EndFunc ;==>SubmitPassButton kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 (edited) Almost, i guess. That assumes that i've already inserted the password in the $formpass input field. I need it to show the $formpass first, insert the pass and only then return the result to the previous function and continue it. Interesting aproach btw. Edited January 8, 2013 by telmob Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2013 Share Posted January 8, 2013 telmob,That assumes that i've already inserted the password in the $formpass input field.No, it will return false if the psw does not match, including if it is blank. If you are saying that it does not fit within the flow of your script then you need to post more of the script as you are alluding to parts of the script that we cannot see...kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 Sorry i took so long to reply. I went to sleep. It doesn't show $FormPass. I immediately get the 'Wrong Password' message. And even after that, the GUI opens and it shouldn't. TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "On_DblClick") Func On_DblClick() If SubmitPass() Then GUISetState(@SW_SHOW,$FormPass) Else Local $state = WinGetState("App", "System") If WinExists("App", "System") Then GUISetState(@SW_HIDE, $MAINGUI) ElseIf Not WinExists("App", "System") Then GUISetState(@SW_SHOW, $MAINGUI) UpdateGUI() EndIf EndFunc Func SubmitPass(); This function is the submit button in my input password gui. Local $CheckPassExist=RegRead(*******************************) Local $PassInputRead=Guictrlread($PassInput) Local $FFF=_Crypt_HashData($PassInputRead,$CALG_MD5) If _Crypt_HashData($PassInputRead,$CALG_MD5)=$CheckPassExist Then GUISetState(@SW_HIDE,$FormPass) GUICtrlSetData($PassInput, "") Return True ElseIf _Crypt_HashData($PassInputRead,$CALG_MD5)<>$CheckPassExist Then MsgBox(16, "Error", "Wrong password!") GUISetState(@SW_HIDE,$FormPass) Return False EndIf EndFunc Link to comment Share on other sites More sharing options...
kylomas Posted January 8, 2013 Share Posted January 8, 2013 telmob,Again If you are saying that it does not fit within the flow of your script then you need to post more of the script as you are alluding to parts of the script that we cannot see...kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 I think that the problem is that SubmitPass() is a button and not the gui itself. What do you think? Link to comment Share on other sites More sharing options...
BrewManNH Posted January 8, 2013 Share Posted January 8, 2013 I think you should do as he stated several times, show the code you're using in your script, right now we have tiny pieces that aren't connected to anything else and it's extremely hard to figure out what it is you're doing. 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 GudeHow 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 Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 I'll try to setup a code to show you. Sorry i haven't done before, but the password code is a little big, i'll try to shrink it and i'll post it here. Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 (edited) Here it is, finally. Notice how it assumes i've already clicked the submit button when double-clicking the tray to open the gui. expandcollapse popup#include <ButtonConstants.au3> #include <ComboConstants.au3> #include <GUIConstantsEx.au3> #include <GUIListBox.au3> #include <StaticConstants.au3> #include <TabConstants.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> #include <GUIComboBox.au3> #include <Constants.au3> #include <GUIListview.au3> #include <Array.au3> #include <File.au3> #include <Crypt.au3> Opt("WinTitleMatchMode",2) opt("TrayAutoPause",0) TrayMenu("create") $FormPasswidth = 280 $FormPassheight = 121 $FormPass = GUICreate("fghjfghjfgj", 280, 121, @DesktopWidth/2 - $FormPasswidth/2, @DesktopHeight/2 - $FormPassheight/2, BitOR($WS_SYSMENU, $GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) $PassInput = GUICtrlCreateInput("", 8, 29, 257, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD)) $ButtonsubmitPass = GUICtrlCreateButton("&OK", 110, 58, 75, 28, $BS_NOTIFY) $ButtonCancelPass = GUICtrlCreateButton("&Cancel", 191, 58, 75, 28, $BS_NOTIFY) $EnterPassLabel = GUICtrlCreateLabel("Enter password:", 8, 12, 130, 17, 0) #EndRegion ### END Koda GUI section ### ;~ GUISetState(@SW_HIDE) $SRPEGUI = GUICreate("App", 200, 200, 500, 500, BitOR($WS_EX_ACCEPTFILES, $WS_EX_WINDOWEDGE, $GUI_SS_DEFAULT_GUI)) $ButtonLockSystem = GUICtrlCreateButton("Lock System", 54, 80, 91, 28) GUISetState(@SW_HIDE) ;~ GUISetState() TraySetClick(8) TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "On_DblClick"); ----<-----<-----<-----<-----<-----<-----<-----<---- Func On_DblClick() If SubmitPass() Then GUISetState(@SW_SHOW,$FormPass) Else GUISetState(@SW_SHOW, $SRPEGUI) EndIf EndFunc While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $ButtonsubmitPass SubmitPass() EndSwitch WEnd Func SubmitPass(); ----<-----<-----<-----<-----<-----<-----<-----<---- Local $Pass=1 Local $PassInputRead=Guictrlread($PassInput) If $PassInputRead=$Pass Then GUISetState(@SW_HIDE,$FormPass) GUICtrlSetData($PassInput, "") Return True ElseIf $PassInputRead<>$Pass Then MsgBox(16, "Error", "Wrong password!") GUISetState(@SW_HIDE,$FormPass) Return False EndIf EndFunc func TrayMenu($tAction="create") Opt("TrayMenuMode",11) TrayItemSetOnEvent(-1,"TrayClick") $t_settings=TrayCreateItem("Configure") TrayItemSetOnEvent(-1,"TrayClick") TrayCreateItem("") $t_exit=TrayCreateItem("Exit") TrayItemSetOnEvent(-1,"TrayClick") Opt("TrayIconHide",0) opt("TrayOnEventMode",1) TraySetState() endfunc func TrayClick() $t_msg=TrayItemGetText(@tray_id) Select Case $t_msg = "Configure" Local $state = WinGetState("App", "") If WinExists("App", "") Then GUISetState(@SW_HIDE, $SRPEGUI) ElseIf Not WinExists("App", "") Then GUISetState(@SW_SHOW, $SRPEGUI) EndIf Case $t_msg = "Exit" Exit EndSelect EndFunc Edited January 8, 2013 by telmob Link to comment Share on other sites More sharing options...
spudw2k Posted January 8, 2013 Share Posted January 8, 2013 (edited) Just a quick comment. I would change the elseif statements into simple else statements. I don't see any value in testing for more than the "true' condition and re-evaluating might cause undesired performance issues. i.e. ElseIf $PassInputRead<>$Pass Then Else ElseIf Not WinExists("App", "") Then Else Edited January 8, 2013 by spudw2k Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 I didn't know that. I use elseif plenty, and performance is a major concern. Time to change things a bit Link to comment Share on other sites More sharing options...
spudw2k Posted January 8, 2013 Share Posted January 8, 2013 In some cases you'd prob want to evaluate multiple conditions, but in others (like checking for a correct password) it's only important to eval if it's true because any other condition would be false. I wanted to throw out my comment when I saw in your earlier posting where you used if _Crypt... elseif _Crypt... Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX BuilderMisc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retreive SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose ArrayProjects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalcCool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
telmob Posted January 8, 2013 Author Share Posted January 8, 2013 LOL. Come to think of it. In the real script, i do evaluate seceral situations, just noticed that all my else and elseifs are correctly placed Link to comment Share on other sites More sharing options...
telmob Posted January 10, 2013 Author Share Posted January 10, 2013 Any help on this? Link to comment Share on other sites More sharing options...
kylomas Posted January 10, 2013 Share Posted January 10, 2013 telmob, Ran your reproducer. Clicking on the "configure" option does'nt do anything. Looked at your code and am not sure what you are trying to do. My impression is that you want a tray menu to do various things after pasword validation. Is this correct? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
telmob Posted January 10, 2013 Author Share Posted January 10, 2013 (edited) No, the 'configure' option is just to open the gui, but i've included it in the reproducer above just for completeness sake.The only important example in the code above is in the double click tray action which also just opens/closes the gui but it has the code you've introduced.I've put some '<-----<-----<' in the code for you to find it easily. If the code works for that function, i will implement it in the other important functions that require a password to get accessed. Edited January 10, 2013 by telmob 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