rotac Posted March 10, 2021 Posted March 10, 2021 hello maybe you can help me I would like to read a time xx:xx via an input field. but if no time xx:xx should be entered there, an error should appear. While 1 $nMsg = GUIGetMsg($Zeit) Switch $nMsg Case $GUI_EVENT_CLOSE $Button6 = GUICtrlRead($Zeit) Exit Case $Button6 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ")$readinput = GUICtrlRead($Zeit) If $readInput <> '' Then Else MsgBox(262192,"ERROR","ERROR keine Zeit gefunden")
FrancescoDiMuro Posted March 10, 2021 Posted March 10, 2021 Hi @rotac, and to the AutoIt forum! Could you please post the entire script? rotac 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
rotac Posted March 10, 2021 Author Posted March 10, 2021 here the whole script. it's about the part that is written in bold. it works if I don't enter anything the error comes. but when I enter a name or a letter there is no error and he writes it in the exl file. The goal is to enter a time in order to continue without errors #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=D:\autoit\Liste test\marc.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=D:\autoit\Liste test\test2\Form2.kxf $Form1 = GUICreate("GehtMeldung", 280, 287, 555, 138) $Button1 = GUICtrlCreateButton("12:00Uhr", 30, 40, 75, 25) $Button2 = GUICtrlCreateButton("14:00Uhr", 30, 80, 75, 25) $Button3 = GUICtrlCreateButton("15:00Uhr", 30, 120, 75, 25) $Button4 = GUICtrlCreateButton("15:30Uhr", 30, 160, 75, 25) $Button5 = GUICtrlCreateButton("16:00Uhr", 30, 200, 75, 25) $Zeit = GUICtrlCreateInput("Zeit", 160, 120, 81, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) GUICtrlSetLimit(-1, 5) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetTip(-1, "0") $Button6 = GUICtrlCreateButton("OK", 163, 160, 75, 25) $Label1 = GUICtrlCreateLabel("GehtMeldung", 11, 8, 112, 23) GUICtrlSetFont(-1, 12, 400, 0, "Cooper Black") $Label2 = GUICtrlCreateLabel("Zeit selbst eintragen", 136, 88, 129, 20) GUICtrlSetFont(-1, 10, 400, 0, "CorpoSExtBol") $Label3 = GUICtrlCreateLabel("V2.1 Marc", 224, 264, 53, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc While 1 $nMsg = GUIGetMsg($Zeit) Switch $nMsg Case $GUI_EVENT_CLOSE $Button6 = GUICtrlRead($Zeit) Exit Case $Button6 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ")$readinput = GUICtrlRead($Zeit) If $readInput <> '' Then Else MsgBox(262192,"ERROR","ERROR keine Zeit gefunden") EndIf Send($readinput) Send("{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit Case $Button1 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("12{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit Case $Button2 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("14{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button3 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("15{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button4 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxxxxxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("15{SHIFTDOWN}:{SHIFTUP}30{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button5 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxxxxxxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("16{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- EndSwitch WEnd
Somerset Posted March 10, 2021 Posted March 10, 2021 Click the code button to insert code to paste for an easier format to read. FrancescoDiMuro 1
rotac Posted March 10, 2021 Author Posted March 10, 2021 oh sorry dont know how to edit my post so here with the code buttton expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=D:\autoit\Liste test\marc.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form=D:\autoit\Liste test\test2\Form2.kxf $Form1 = GUICreate("GehtMeldung", 280, 287, 555, 138) $Button1 = GUICtrlCreateButton("12:00Uhr", 30, 40, 75, 25) $Button2 = GUICtrlCreateButton("14:00Uhr", 30, 80, 75, 25) $Button3 = GUICtrlCreateButton("15:00Uhr", 30, 120, 75, 25) $Button4 = GUICtrlCreateButton("15:30Uhr", 30, 160, 75, 25) $Button5 = GUICtrlCreateButton("16:00Uhr", 30, 200, 75, 25) $Zeit = GUICtrlCreateInput("Zeit", 160, 120, 81, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_CENTER)) GUICtrlSetLimit(-1, 5) GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif") GUICtrlSetTip(-1, "0") $Button6 = GUICtrlCreateButton("OK", 163, 160, 75, 25) $Label1 = GUICtrlCreateLabel("GehtMeldung", 11, 8, 112, 23) GUICtrlSetFont(-1, 12, 400, 0, "Cooper Black") $Label2 = GUICtrlCreateLabel("Zeit selbst eintragen", 136, 88, 129, 20) GUICtrlSetFont(-1, 10, 400, 0, "CorpoSExtBol") $Label3 = GUICtrlCreateLabel("V2.1 Marc", 224, 264, 53, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### Func _Au3RecordSetup() Opt('WinWaitDelay',100) Opt('WinDetectHiddenText',1) Opt('MouseCoordMode',0) EndFunc Func _WinWaitActivate($title,$text,$timeout=0) WinWait($title,$text,$timeout) If Not WinActive($title,$text) Then WinActivate($title,$text) WinWaitActive($title,$text,$timeout) EndFunc While 1 $nMsg = GUIGetMsg($Zeit) Switch $nMsg Case $GUI_EVENT_CLOSE $Button6 = GUICtrlRead($Zeit) Exit Case $Button6 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") $readinput = GUICtrlRead($Zeit) If $readInput <> '' Then Else MsgBox(262192,"ERROR","ERROR keine Zeit gefunden") EndIf Send($readinput) Send("{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit Case $Button1 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("12{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit Case $Button2 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("14{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button3 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("15{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button4 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxxxxxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("15{SHIFTDOWN}:{SHIFTUP}30{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- Case $Button5 send ("#r") ;WinActivate("Ausf") Sleep(2000) Send("excel file:///I:/xxxxxxxxxxxxxx.xls") Send("{ENTER}") _WinWaitActivate("Geht-Zeit angeben","Herzlich willkommen ") Send("16{SHIFTDOWN}:{SHIFTUP}00{ENTER}") Sleep(2000) Send("{ALTDOWN}{F4}{ALTUP}") _WinWaitActivate("Microsoft Excel","") Send("{ENTER}") Sleep(1000) GUIDelete() Exit #endregion --- Au3Recorder generated code End --- EndSwitch WEnd
FrancescoDiMuro Posted March 10, 2021 Posted March 10, 2021 @rotac There are a couple ways to make this work: Use a Date Time Picker control instead of a Text Input control with the Control Style $DTS_TIMEFORMAT; Use StringRegExp() to ensure that the user is inserting exactly a time format string, and nothing else. Which one do you like the most? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
rotac Posted March 10, 2021 Author Posted March 10, 2021 i am really a beginner in autoit. StringRegExp () sounds good to me, but I can't find anything online that explains how I can integrate it into my script
FrancescoDiMuro Posted March 10, 2021 Posted March 10, 2021 @rotac Don't worry. That function is so powerful, but needs a bit of knowledge before digging into it. Here's something that might help you: #include <StringConstants.au3> Test() Func Test() Local $arrTimes[6] = ['23:59', '15:20', '01:72', '14:32', '00:00', '41:59'] For $i = 0 To UBound($arrTimes) - 1 Step 1 ConsoleWrite("Is a correct time " & $arrTimes[$i] & "? " & (_IsTime($arrTimes[$i]) ? "Yes" : "No") & @CRLF) Next EndFunc Func _IsTime($strUserInput) Return StringRegExp($strUserInput, '^[0-2][0-9]:[0-5][0-9]$', $STR_REGEXPMATCH) EndFunc Just use the function _IsTime() when you read the content of the input control, passing what you've read from that control, and checking that the return value is 1 rotac 1 Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
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