BatMan22 Posted March 27, 2019 Share Posted March 27, 2019 Hey guys, I'm kinda stuck on how to get a program to hide/show a GUI only when certain criteria are true and to how to loop it. I tried it below which kinda works, but I'm hoping to find a solution that checks for the existence of the files continuously (every few seconds) then shows/hides GUI based off of the results. expandcollapse popup;checker for IC2/3/4 Loading! #include <File.au3> #include <Array.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Global $IC2, $IC3, $IC4, $IC5 Global $Gui Global $verbose = 0 TrayTip("Info!", "Hit ESCAPE to quit!", 10) HotKeySet("{Esc}", "_quit") ; Quit HotKeySet("^{Esc}", "_quit") ; Quit Func _quit() Send("{CTRLUP}") Exit EndFunc ;==>_quit #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("IC#", -1, -1, 206, 130) $Label1 = GUICtrlCreateLabel("IC2", 0, 0, 20, 17) $Label2 = GUICtrlCreateLabel("IC3", 0, 16, 20, 17) $Label3 = GUICtrlCreateLabel("IC4", 0, 32, 20, 17) $Label4 = GUICtrlCreateLabel("IC5", 0, 48, 20, 17) $Label5 = GUICtrlCreateLabel("Future", 0, 64, 34, 17) $Button1 = GUICtrlCreateButton("Button1", 40, 0, 25, 17) $Button2 = GUICtrlCreateButton("Button2", 40, 16, 25, 17) $Button3 = GUICtrlCreateButton("Button3", 40, 32, 25, 17) $Button4 = GUICtrlCreateButton("Button4", 40, 48, 25, 17) $Button5 = GUICtrlCreateButton("Button5", 40, 64, 25, 17) While $Gui = 0 GUISetState(@SW_HIDE) Sleep(5000) GuiChecker() WEnd If $Gui = 1 Then GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func GuiChecker() ;~ Sleep(5000) $IC2 = CheckIC2() $IC3 = CheckIC3() $IC4 = CheckIC4() $IC5 = CheckIC5() ConsoleWrite("IC2 Return is: " & $IC2 & @CRLF) ConsoleWrite("IC3 Return is: " & $IC3 & @CRLF) ConsoleWrite("IC4 Return is: " & $IC4 & @CRLF) ConsoleWrite("IC5 Return is: " & $IC5 & @CRLF) If $IC2 = 0 And $IC3 = 0 And $IC4 = 0 And $IC5 = 0 Then ConsoleWrite("Gui should NOT show") $Gui = 0 Else ConsoleWrite("Gui should show") $Gui = 1 EndIf EndFunc ;==>GuiChecker Func CheckIC2() Local $loaded _FileReadToArray("loadedfiles.txt", $loaded, 0) If $verbose = 1 Then _ArrayDisplay($loaded, "Everything from file") $loaded = _ArrayUnique($loaded, 0, 0, 0, 0) If $verbose = 1 Then _ArrayDisplay($loaded, "Everything from file that is unique") ;~ If @error Then MsgBox(0, 0, @error) If IsArray($loaded) Then Return (UBound($loaded)) If Not IsArray($loaded) Then Return (0) EndFunc ;==>CheckIC2 Func CheckIC3() If FileExists("IC3MCTemplate.csv") Then Return (1) Else Return (0) EndIf EndFunc ;==>CheckIC3 Func CheckIC4() If FileExists("IC4MCTemplate.csv") Then Return (1) Else Return (0) EndIf EndFunc ;==>CheckIC4 Func CheckIC5() If FileExists("IC5MCTemplate.csv") Then Return (1) Else Return (0) EndIf EndFunc ;==>CheckIC5 Link to comment Share on other sites More sharing options...
Nine Posted March 28, 2019 Share Posted March 28, 2019 Instead of having 2 competing While loops, put all the logic into a single one. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BatMan22 Posted April 3, 2019 Author Share Posted April 3, 2019 (edited) @Nine, I tried that and it doesn't work the way I want it to work. I figured that if I used the While loop for the GUI, that if I put a 3 second sleep at the front.. then it would still catch my gui clicks during those three seconds but it seems to miss the gui click no matter where I put the sleep.. Sooo I'm kinda confused on where to place the sleep. While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button2 Go(2) Case $Button3 Go(3) Case $Button4 Go(4) Case $Button5 Go(5) Case Else Sleep(3000) Local $c2 = $IC2 Local $c3 = $IC3 Local $c4 = $IC4 Local $c5 = $IC5 GuiChecker() If $c2 <> $IC2 then _Restart() ConsoleWrite($c2 & " is c2 " & $IC2 & " is the new value for IC2" & @CRLF) If $c3 <> $IC3 then _Restart() ConsoleWrite($c3 & " is c3 " & $IC3 & " is the new value for IC3" & @CRLF) If $c4 <> $IC4 then _Restart() ConsoleWrite($c4 & " is c4 " & $IC4 & " is the new value for IC4" & @CRLF) If $c5 <> $IC5 then _Restart() ConsoleWrite($c5 & " is c5 " & $IC5 & " is the new value for IC5" & @CRLF) EndSwitch WEnd Edited April 3, 2019 by BatMan22 Link to comment Share on other sites More sharing options...
Nine Posted April 5, 2019 Share Posted April 5, 2019 Do not use a large Sleep. Instead use TimerInit and TimerDiff to check for the delay, something like : Local $t = TimerInit () While True if TimerDiff ($t) > 3000 then ; Do you stuff here $t = TimerInit () endif Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Wend Also don't declare your variables inside the while loop. Declare them at the beginning of your script. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BatMan22 Posted April 7, 2019 Author Share Posted April 7, 2019 On 4/5/2019 at 8:54 AM, Nine said: Do not use a large Sleep. Instead use TimerInit and TimerDiff to check for the delay, something like : Local $t = TimerInit () While True if TimerDiff ($t) > 3000 then ; Do you stuff here $t = TimerInit () endif Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Wend Also don't declare your variables inside the while loop. Declare them at the beginning of your script. Oops.. That works. I wish I had seen that earlier.. I broke up the program into 2 parts.. one that checks if the GUI needs to be running at all and opens and kills the gui program, and a separate GUI with all the functions. 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