IAMK Posted December 3, 2018 Share Posted December 3, 2018 (edited) I had a script which stored GUIText in variables, but maintaining the code when it had to be changes was difficult and messy. I'm now trying to change the code to the following, so that all I need to do is call writeStep() x amount of times with the messages I want, and then the script does all the dirty work. However, the GUI has no text (Below code can be copy/pasted and run): expandcollapse popup#include <Date.au3> #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> HotKeySet("!{DEL}", "endScript") HotKeySet("^{p}", "pressPass") HotKeySet("^{f}", "pressFail") $K_GUI = GUICreate("AutoIT_K_StepsCheck.exe", 400, 300) WinSetOnTop($K_GUI, "", 1) ;Keeps the window on the top. $Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230) GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif") ;DO NOT TOUCH THESE VARIABLES------------------------------------------------- Local $stepMessage[1] = "NULL" ;This will become a dynamically filled array. Local $maxSteps = 1 ;Make this 2 if "Next Step" is required. Local $step = 1 ;This will be incremented when a step is passed or failed. ;----------------------------------------------------------------------------- ;MODIFIABLE VARIABLES========================================================= writeStep("a", "Hello" & @CRLF & "There!") writeStep("m", "Hello I AM BOB") writeStep("ma", "Hello" & @CRLF & @CRLF & """K""") writeStep("x", "This is unspecified...") ;============================================================================= _ArrayDisplay($stepMessage) ;This array is empty? Func writeStep($executionType, $message) _ArrayAdd($stepMessage, getExecutionType($executionType) & """Step: "" & $step & ""/"" & ($maxSteps - 2) & @CRLF & @CRLF & "" & $message""") $maxSteps = $maxSteps + 1 EndFunc Func getExecutionType($executionType) If($executionType = "m") Then Return """<Manual>"" & @TAB & @TAB""" ElseIf($executionType = "a") Then Return """<Auto>"" & @TAB & @TAB & @TAB""" ElseIf($executionType = "ma") Then Return """<Manual/Auto>"" & @TAB""" Else Return """<Unspecified>"" & @TAB""" EndIf EndFunc Local $showGUI = "False" Local $buttonPressed = 0 Local $file Local $filename = "SC_" & @YEAR & "-" & @MON & "-" & @MDAY & "_" & @HOUR & "-" & @MIN & "-" & @SEC & ".txt" Local $file = FileOpen($filename, 1) Func SanityCheckGUI(ByRef $pass) Local $message = "" GUICtrlSetData($GUIText, Execute($stepMessage[$step])) $showGUI = "True" GUISetState(@SW_SHOW) If($step < ($maxSteps - 1)) Then MouseClick("Primary", 10, 10, 1, 0) ;Give control back to System. EndIf While($showGUI = "True") $buttonPressed = GUIGetMsg() Switch $buttonPressed Case $Button1 ;Pass $pass = "True" $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) Case $Button2 ;Fail $buttonPressed = 0 $showGUI = "False" GUISetState(@SW_HIDE) While($message = "") $message = InputBox("StepCheck.exe", "Please enter the reason the step failed." & @CRLF & "E.g. The Documents folder is missing.", "", "", 300, 200) WEnd Return $message EndSwitch WEnd EndFunc Func getStatus($pass) If($pass = "True") Then Return " passed " Else Return " failed " EndIf EndFunc Func logGUI($timer) ;Called every Step() to bring up call the GUI and log the results. Local $pass = "False" ;Whether "Pass" or "Fail" was pressed. Local $failLog = SanityCheckGUI($pass) ;Returns a message to log if the step failed. FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF) If($failLog <> "") Then FileWrite($file, "Logged comment: " & $failLog & @CRLF) EndIf EndFunc Func convertTime() $tempTime = Ceiling(TimerDiff($totalTime) / 1000) $hours = 0 $mins = 0 While($tempTime > 3600) $hours = $hours + 1 $tempTime = $tempTime - 3600 WEnd While($tempTime > 60) $mins = $mins + 1 $tempTime = $tempTime - 60 WEnd $secs = $tempTime If($hours > 0) Then Return $hours & " hours, " & $mins & " minutes and " & $secs & " seconds" ElseIf($mins > 0) Then Return $mins & " minutes and " & $secs & " seconds" Else Return $secs & " seconds" EndIf EndFunc ;SCRIPT======================================================================= FileWrite($file, _Now() & ": AUTOIT - Steps Check started." & @CRLF & "-----------------------------" & @CRLF & "IP: " & @IPADDRESS1 & @CRLF) $totalTime = TimerInit() ;Used to time the duration of the entire script. While($step < $maxSteps) Local $timer = TimerInit() logGUI($timer) $step = $step + 1 WEnd FileWrite($file, _Now() & ": AUTOIT - Steps Check completed." & @CRLF & "Total duration: " & convertTime() & ".") FileClose($file) ;============================================================================= Func pressPass() $buttonPressed = $Button1 If($step < ($maxSteps - 1)) Then MouseClick("Primary", 10, 10, 1, 0) ;Give control back to System. EndIf EndFunc Func pressFail() $buttonPressed = $Button2 EndFunc Func endScript() FileWrite($file, _Now() & ": AUTOIT - Terminated using the Alt+DEL key." & @CRLF & "Total duration: " & convertTime() & ".") FileClose($file) Exit 0 EndFunc Please help me with this, as I believe the issue is the amounts of " needed, which is like a puzzle to me. Edited December 3, 2018 by IAMK Removed: MsgBox at end of script. Link to comment Share on other sites More sharing options...
pixelsearch Posted December 3, 2018 Share Posted December 3, 2018 (edited) Local $stepMessage[1] = ["NULL"] You keep editing your post lol, 1st one was : Local $stepMessage ;This will become a dynamically filled array. May I suggest you test variables to be consistant arrays, like this : #include <Array.au3> Local $aArray ; will produce errors as no dimension is given _ArrayAdd($aArray, "hello") If @error = 1 Then MsgBox(0, "_ArrayAdd", "$aArray" & " is not an array") EndIf _ArrayDisplay($aArray) If @error = 1 Then MsgBox(0, "_ArrayDisplay", "$aArray" & " is not an array") EndIf Last error in script comes from : MsgBox(0, "AutoIT_K_StepsCheck.exe", $stepMessage[42], 5) It works for me with [4], not [5] not [42], with nice displays like this one, where 1st row was declared empty : Local $stepMessage[1] Edited December 3, 2018 by pixelsearch Link to comment Share on other sites More sharing options...
IAMK Posted December 3, 2018 Author Share Posted December 3, 2018 (edited) @pixelsearch Yes, sorry. I figured out the error was with that declaration after some more testing. I have therefore changed the question to just be about the messages in the GUI (After the ArrayDisplay, the GUI is empty, instead of showing the messages seen in ArrayDisplay). I will also update the point you mentioned. Edited December 3, 2018 by IAMK Link to comment Share on other sites More sharing options...
IAMK Posted December 3, 2018 Author Share Posted December 3, 2018 In case I wasn't clear enough in the OP: I want the first step to look like this: Same behaviour for other steps as well. The above was done by using: GUICtrlSetData($GUIText, Execute("""Step: "" & $step & ""/"" & ($maxSteps - 2) & @CRLF & @CRLF & $message & ""Hello"" & @CRLF & ""There!""")) I just can't get the correct syntax(?) when I try to do it in separate parts. Link to comment Share on other sites More sharing options...
pixelsearch Posted December 3, 2018 Share Posted December 3, 2018 (edited) Well... with the reworked $sString below, MsgBox shows something correct, but definitely not with the original commented $sString (surrounded by single quotes below, commented) $step = 1 $maxSteps = 1 $message = "hello" ; $sString = '"<Auto>" & @TAB & @TAB & @TAB""Step: " & $step & "/" & ($maxSteps - 2) & @CRLF & @CRLF & " & $message"' $sString = '"<Auto>" & @TAB & @TAB & @TAB & "Step: " & $step & "/" & ($maxSteps - 2) & @CRLF & @CRLF & $message' $vExec = Execute($sString) If $vExec <> "" Then MsgBox(0, "Execute", $vExec) Else MsgBox(0, "Execute", "failed") EndIf This will also show "failed" if, for instance, one of the 3 variables lines was commented. Edited December 3, 2018 by pixelsearch Link to comment Share on other sites More sharing options...
IAMK Posted December 3, 2018 Author Share Posted December 3, 2018 @pixelsearch Thanks, I got it working now. ;MODIFIABLE VARIABLES========================================================= writeStep("a", '"Hello" & @CRLF & "There!"') writeStep("m", '"Hello I AM BOB"') writeStep("ma", '"Hello" & @CRLF & @CRLF & "K"') writeStep("x", '"This is unspecified..."') ;============================================================================= _ArrayAdd($stepMessage, "End of Sanity Check! :)") _ArrayDisplay($stepMessage) Func writeStep($executionType, $message) _ArrayAdd($stepMessage, getExecutionType($executionType) & '& "Step: " & $step & "/" & ($maxSteps - 1) & @CRLF & @CRLF & ' & $message) $maxSteps = $maxSteps + 1 EndFunc Func getExecutionType($executionType) If($executionType = "m") Then Return '"<Manual>" & @TAB & @TAB ' ElseIf($executionType = "a") Then Return '"<Auto>" & @TAB & @TAB & @TAB ' ElseIf($executionType = "ma") Then Return '"<Manual/Auto>" & @TAB ' Else Return '"<Unspecified>" & @TAB ' EndIf EndFunc The use of ' versus " makes it much simpler. Link to comment Share on other sites More sharing options...
pixelsearch Posted December 3, 2018 Share Posted December 3, 2018 (edited) Great news, bravo Chr(34) can be a big help too in these cases, it's the double quote character, solving a lot of syntax issues. Edited December 3, 2018 by pixelsearch 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