DigDeep Posted April 13, 2015 Share Posted April 13, 2015 (edited) Hi AutoIT team, Could you please help me out to correct thebelow code? This code is working correctly except with few issues. 1. When I run this code, it displays 2 buttons. If I would press the Button 1 or 2 it would run the codes written inside it and then will call the Function at the end and display a message box with final results as which tests passed and which part got failed. 2. The "Passed" message Text should come Green in color and "Failed" Text as Red. I am able to run script correctly and it does run the button command. The problem is that: 1. I get error Variable not declared, only If I press the Button 1 first. But If I presss the Button 2 first and then button 1 it works with no errors. 2. I am not able to figure how to display the passed and failed text as Green or Red color. - $Dcheck = "Dcheck : Failed" $Dcheck = "Dcheck : Passed" Only the Failed and Passed text should be colored. I tried doing by creating different vairables as $Failed and $Passed and call them whereever needed but that did not work. and 3. As you can see both the buttons are calling same func. But both buttons have different mesage box items to show. I am able to do this if creating 2 different functions for both buttons but that's making my code too lengthier. Is there any ways I can make only 1 Func but can call the Same Func and msg box with different messages? Any help with these would be appriciate. expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include<process.au3> #include <Date.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate(" Example", 352, 117, 753, 472, $GUI_SS_DEFAULT_GUI) $Button1 = GUICtrlCreateButton("Button1", 32, 48, 131, 25) Button2 = GUICtrlCreateButton("Button2", 192, 48, 131, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### ;==>> "Commands written here to call" ;========>> Func Calling_Function() Select Case Not ProcessExists(something) Or Not FileExists(something) Global $Vcheck = "Vcheck: Failed" Case Else $Vcheck = "Vcheck: Passed" EndSelect Select Case "something_new" Global $Pcheck = "Pcheck : Failed" Case Else $Pcheck = "Pcheck: Passed" EndSelect Select Case "something_new2" Global $Dcheck = "Dcheck : Failed" Case Else $Dcheck = "Dcheck: Passed" EndSelect EndFunc While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = Button1 Select Case Not FileExists($VC1) "Run commands" EndSelect Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $PCheck) Case $nMsg = Button2 Select Case Not FileExists($VC2) "Run Commands" EndSelect Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $PCheck & @LF & @LF & $DCheck) EndSelect WEnd Edited April 13, 2015 by sunshinesmile84 Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 13, 2015 Share Posted April 13, 2015 (edited) Hello, haven't read the entire code but button2 seems to miss its $ not making it a variable, so that could cause a few problems that you experiencing Edit: where is $VC1-2 is decleared? (can be somewhere else), you generally should deacler global variables outside the function (beginning of the code somewhere I would suiggest), they can cause a few problems, chiefs amongst them is that if you dont run the function beforehand you dont have that variable. Dont know if case "something_new" is valid or not, but thats just because this is a "ghost code". M'I using that expression right? Anyway hope this helped, good luck! Edited April 13, 2015 by SorryButImaNewbie Link to comment Share on other sites More sharing options...
JohnOne Posted April 13, 2015 Share Posted April 13, 2015 (edited) Clearly you are writing a bunch of pseudo code and it is nothing like your real code. here's what invariably happens when people do that. They get people to waste their time looking for solutions via a guessing game and then a big Q & A session ensues to try and drag information out of the OP while they are kicking and screaming trying to hold onto to their very important and ever so secret real code. Not this person though, I'm out. Best of luck. Edited April 13, 2015 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
mikell Posted April 13, 2015 Share Posted April 13, 2015 More gently said : please post a runnable code SorryButImaNewbie 1 Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 13, 2015 Share Posted April 13, 2015 ghost code = psuedo code was the word I was looking for, @JohnOne taught me something while he was "tutoring" OP Link to comment Share on other sites More sharing options...
DigDeep Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) Hello, haven't read the entire code but button2 seems to miss its $ not making it a variable, so that could cause a few problems that you experiencing Edit: where is $VC1-2 is decleared? (can be somewhere else), you generally should deacler global variables outside the function (beginning of the code somewhere I would suiggest), they can cause a few problems, chiefs amongst them is that if you dont run the function beforehand you dont have that variable. Dont know if case "something_new" is valid or not, but thats just because this is a "ghost code". M'I using that expression right? Anyway hope this helped, good luck! Hi SorryButlmaNewbie, Thank you for pointing out to that error, but I missed to give the $ sign in this forum itself. It is correctly placed in my actual code. As I have mentioned in my email earlier, when I run the code, selecting Button 2 first and then Button 1 comes out with no error. The problem is when I select Button 1 first. Also, $VC1 and $VC2 are declared under the section I have marked here as: ;==>> "Commands written here to call" ;========>> Edited April 13, 2015 by sunshinesmile84 Link to comment Share on other sites More sharing options...
DigDeep Posted April 13, 2015 Author Share Posted April 13, 2015 More gently said : please post a runnable code Hi mikell, The codes written are not for public use but I will get the same code with runable items added and posted very soon. Thanks. Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 13, 2015 Share Posted April 13, 2015 You should also try to add #include<debug.au3> and use : #AutoIt3Wrapper_Run_Debug_Mode = Y #AutoIt3Wrapper_Run_Debug = On These 2 could give you a lot of information about what is exactly happening when you run your script! Also, I don't know what exactly is that you want to do, but do you really need 2 buttons? Can't it just do both? At the While 1 loop I see 2 WEnd, but this can be just an error in the posted code. I understand all too well that you can't post actual code here (have the same problem many times ) because the firm you are working for doesn't want any of its code on te net, understandable. I would suggest to post the code and change everything that could be problematic (paths, directories, account names/passes maybe even variabels what ever else you deamed risky, I had something else to this list but forgot...) and post a runable code. That's usually helps a lot to those who try to help (just a suggestion ) Good luck and welcome again! Link to comment Share on other sites More sharing options...
DigDeep Posted April 13, 2015 Author Share Posted April 13, 2015 You should also try to add #include<debug.au3> and use : #AutoIt3Wrapper_Run_Debug_Mode = Y #AutoIt3Wrapper_Run_Debug = On These 2 could give you a lot of information about what is exactly happening when you run your script! Also, I don't know what exactly is that you want to do, but do you really need 2 buttons? Can't it just do both? At the While 1 loop I see 2 WEnd, but this can be just an error in the posted code. I understand all too well that you can't post actual code here (have the same problem many times ) because the firm you are working for doesn't want any of its code on te net, understandable. I would suggest to post the code and change everything that could be problematic (paths, directories, account names/passes maybe even variabels what ever else you deamed risky, I had something else to this list but forgot...) and post a runable code. That's usually helps a lot to those who try to help (just a suggestion ) Good luck and welcome again! Thank you for your help here. I have corrected the WEND error here. But I will be getting another runable code posted soon for getting better help. Thanks again. Link to comment Share on other sites More sharing options...
mikell Posted April 13, 2015 Share Posted April 13, 2015 I will be getting another runable code posted soon for getting better help. Wise decision Link to comment Share on other sites More sharing options...
Trong Posted April 13, 2015 Share Posted April 13, 2015 Something like:expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include<process.au3> #include <Date.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Opt("TrayAutoPause", 0) #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate(" -Example- ", 352, 117, 753, 472, $GUI_SS_DEFAULT_GUI) Global $Button1 = GUICtrlCreateButton("Button1", 32, 48, 131, 25) Global $Button2 = GUICtrlCreateButton("Button2", 192, 48, 131, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $VC1 = "something.exe" Global $VC2 = "thingsome.exe" Global $Vcheck, $Pcheck, $Dcheck While 1 Local $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $Button1 If Not FileExists($VC1) Then ;~ "Run commands" EndIf Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $Pcheck) Case $nMsg = $Button2 If Not FileExists($VC2) Then ;~ "Run Commands" EndIf Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $Pcheck & @LF & @LF & $Dcheck) EndSelect WEnd ;==>> ;~ "Commands written here to call" ;========>> Func Calling_Function() If Not ProcessExists("something.exe") Or Not FileExists("thingsome.exe") Then $Vcheck = "Vcheck: Failed" Else $Vcheck = "Vcheck: Passed" EndIf If ProcessExists("something.exe") Then $Pcheck = "Pcheck : Failed" Else $Pcheck = "Pcheck: Passed" EndIf If ProcessExists("thingsome.exe") Then $Dcheck = "Dcheck : Failed" Else $Dcheck = "Dcheck: Passed" EndIf EndFunc ;==>Calling_Function Regards, Link to comment Share on other sites More sharing options...
DigDeep Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) Well, here is the runable code. The application mentioned is just for testing here as IDM and I am not using that as for actual code. Any help would be greatly appriciated. 1. Button 2 gives "Variable not declared " error. 2. If it is possible to correct the code to get the "Passed" message with GREEN and "Failed" with RED color. 3. I have given only 1 Func with all the variables inside it and both buttons msgbox at the end have different calls. So any ways I can keep only 1 Func for both the buttons? expandcollapse popup#NoTrayIcon #RequireAdmin #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #AutoIt3Wrapper_Run_Debug_Mode=Y #AutoIt3Wrapper_Run_Debug=On #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include<process.au3> #include <Date.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Dim $OS1, $OS2, $OS3, $ProgramFilesDir, $nMsg, $Vcheck, $PCheck, $Update, $iDate $OS1 = @OSVersion = 'WIN_7' $OS2 = @OSVersion = 'Win_8' $OS3 = @OSVersion = 'Win_81' $Uninstall = 0 $P = 0 Select Case @OSArch = 'x86' $ProgramFilesDir = @ProgramFilesDir Case @OSArch = 'x64' $ProgramFilesDir = 'c:\Program Files (x86)' EndSelect Global $VC1 = $ProgramFilesDir & "\Internet Download Manager\IDMan.exe" Global $P_ver = FileGetVersion($ProgramFilesDir & "\Internet Download Manager\IDMan.exe", "Productversion") #Region ### $Form1 = GUICreate(" Example", 352, 117, 753, 472, $GUI_SS_DEFAULT_GUI) $Button1 = GUICtrlCreateButton("Button 1", 32, 48, 131, 25) $Button2 = GUICtrlCreateButton("Button 2", 192, 48, 131, 25) GUISetState(@SW_SHOW) #EndRegion ### Func Uninstall() If $Uninstall = 0 Then MsgBox(0, "", "Uninstalling IDM") $Uninstall = 1 EndIf EndFunc ;==>Uninstall Func VC() If $VC1 = 0 Then MsgBox(0, "", "Installing IDM") $VC1 = 1 EndIf EndFunc ;==>VC ;Install Patches Func P() If $P = 0 Then SplashTextOn("Pathes", "Installing Patches", 303, 100, 35, 49, "") Sleep(10000) SplashOff() $P = 1 EndIf EndFunc ;==>P Func UpdateIDM() If $Update = 0 Then MsgBox(0, "", "Running Update") $Update = 1 EndIf EndFunc ;==>UpdateIDM Func Update() SplashTextOn("IDM", "Updating Application...", 275, 100, 575, 366, "Verdana") Sleep(3000) SplashOff() EndFunc ;==>Update Func Final_Check() Select Case Not FileExists($VC1) Global $Vcheck = "VC check: Failed" Case Else $Vcheck = "VC check: Passed" EndSelect Select Case $P_ver <> "V1" Global $PCheck = "Patching: Failed" Case Else $PCheck = "Patching: Passed" EndSelect Select Case $iDate >= '2' Global $DCheck = "Update check: Failed" Case Else $DCheck = "Update check: Passed" EndSelect EndFunc ;==>Final_Check While 1 $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $Button1 ; Button2 SplashTextOn("IDM", "Installing Application...", 275, 100, 575, 366, "Verdana") Sleep(3000) SplashOff() Select Case Not FileExists($VC1) MsgBox(0, "", "File currupted." & @LF & "Please select 'Button1'.") Exit EndSelect ; Check if file is up-to-date Select Case FileExists($ProgramFilesDir & "\Internet Download Manager\IDMan.exe") $DBdate1 = FileGetTime($ProgramFilesDir & "\Internet Download Manager\IDMan.exe", 0) $mdate1 = $DBdate1[1] & "/" & $DBdate1[2] & "/" & $DBdate1[0] Local $sdate = _NowDate() Local $iDateDif = _DateDiff('d', $mdate1, $sdate) Global $iDate = _DateDiff('d', $mdate1, _NowCalc()) EndSelect Select Case $iDate >= '2' UpdateIDM(); This wil install the application completly by uninstalling and re-installing then EndSelect Sleep(2000) Final_Check() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $PCheck) Case $nMsg = $Button2 ; Button2 SplashTextOn("IDM", "Checking Application for errors...", 275, 100, 575, 366, "Verdana") Sleep(3000) SplashOff() Select Case Not FileExists($VC1) MsgBox(0, "", "File currupted." & @LF & "Please select 'Button1'.") Exit EndSelect ; Check if file is up-to-date Select Case FileExists($ProgramFilesDir & "\Internet Download Manager\IDMan.exe") $DBdate1 = FileGetTime($ProgramFilesDir & "\Internet Download Manager\IDMan.exe", 0) $mdate1 = $DBdate1[1] & "/" & $DBdate1[2] & "/" & $DBdate1[0] Local $sdate = _NowDate() Local $iDateDif = _DateDiff('d', $mdate1, $sdate) Global $iDate = _DateDiff('d', $mdate1, _NowCalc()) EndSelect Select Case $iDate >= '2' UpdateIDM() ; This will repair the application if not running or found errors EndSelect Sleep(2000) Final_Check() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $PCheck & @LF & @LF & $DCheck) EndSelect WEnd Edited April 13, 2015 by sunshinesmile84 Link to comment Share on other sites More sharing options...
DigDeep Posted April 13, 2015 Author Share Posted April 13, 2015 (edited) Something like: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_AU3Check_Stop_OnWarning=y #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include<process.au3> #include <Date.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <Constants.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Opt("MustDeclareVars", 1) Opt("TrayAutoPause", 0) #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate(" -Example- ", 352, 117, 753, 472, $GUI_SS_DEFAULT_GUI) Global $Button1 = GUICtrlCreateButton("Button1", 32, 48, 131, 25) Global $Button2 = GUICtrlCreateButton("Button2", 192, 48, 131, 25) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Global $VC1 = "something.exe" Global $VC2 = "thingsome.exe" Global $Vcheck, $Pcheck, $Dcheck While 1 Local $nMsg = GUIGetMsg() Select Case $nMsg = $GUI_EVENT_CLOSE Exit Case $nMsg = $Button1 If Not FileExists($VC1) Then ;~ "Run commands" EndIf Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $Pcheck) Case $nMsg = $Button2 If Not FileExists($VC2) Then ;~ "Run Commands" EndIf Calling_Function() MsgBox(0, "Final Check", $Vcheck & @LF & @LF & $Pcheck & @LF & @LF & $Dcheck) EndSelect WEnd ;==>> ;~ "Commands written here to call" ;========>> Func Calling_Function() If Not ProcessExists("something.exe") Or Not FileExists("thingsome.exe") Then $Vcheck = "Vcheck: Failed" Else $Vcheck = "Vcheck: Passed" EndIf If ProcessExists("something.exe") Then $Pcheck = "Pcheck : Failed" Else $Pcheck = "Pcheck: Passed" EndIf If ProcessExists("thingsome.exe") Then $Dcheck = "Dcheck : Failed" Else $Dcheck = "Dcheck: Passed" EndIf EndFunc ;==>Calling_Function This one is lookin good. So, I believe keeping the While/Wend in the begning and the Commands and Functions to call at the bottom. Is there a way I can get the Passed and Failed words as RED and Green color? So that it reads as below when the msgbox popps up: Dcheck : Failed Or Dcheck: Passed Thank you lots for your help here. Edited April 13, 2015 by sunshinesmile84 Link to comment Share on other sites More sharing options...
SorryButImaNewbie Posted April 13, 2015 Share Posted April 13, 2015 I'm 100% sure it can be done, dont know hwo Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 13, 2015 Moderators Share Posted April 13, 2015 sunshinesmile84, Is there a way I can get the Passed and Failed words as RED and Green color?Not quite what you want, but check out my ExtMsgBox UDF - the link is in my sig. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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