CaptainBeardsEyesBeard Posted August 9, 2018 Share Posted August 9, 2018 Hi Guys/gals, I'm using this function and trying to utilise the error function in a try/catch situation Func InputMatterNumber($MatterNumber) Local $hWnd1 = WinWait("[CLASS:ThunderRT6FormDC]", "", 10) ControlSend($hWnd1, "", "ThunderRT6TextBox22", $MatterNumber) FileWrite($hFilehandle, @CRLF & $MatterNumber) If @error = 1 Then MsgBox(($MB_ICONINFORMATION, "", "Cannot enter Matter number") EndIf Sleep(4000) EndFunc However I just ran it and it didn't send the matter number to the box but I didn't get the MsgBox which should've been triggered by the error function? Cheers Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 According to the help file: FileWrite does not set @error but the return value tells you if the command was successful or not My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 If you want to check if ControlSend did work or not then the check needs to be done immediately after ControlSend. Because each AutoIt function call resets @error. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
AutoBert Posted August 9, 2018 Share Posted August 9, 2018 (edited) 16 minutes ago, CaptainBeardsEyesBeard said: FileWrite($hFilehandle, @CRLF & $MatterNumber) The handle is realy existing! No error occurs. Edited August 9, 2018 by AutoBert Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 Sure you get an error! Global $handle $iReturnvalue = FileWrite($handle, "Text") If $iReturnvalue = 1 Then MsgBox(0, "Success!", "Data written to file!") Else MsgBox(0, "Error!", "Data NOT written to file!") EndIf My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
ternal Posted August 9, 2018 Share Posted August 9, 2018 @water is there a reason why you need to assign a variable? can't you just use: Global $handle If FileWrite($handle, "Text") = 1 Then MsgBox(0, "Success!", "Data written to file!") Else MsgBox(0, "Error!", "Data NOT written to file!") EndIf Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 No, there's no reason except readability Your code can even be shortened to: Quote Global $handle If FileWrite($handle, "Text") Then MsgBox(0, "Success!", "Data written to file!") Else MsgBox(0, "Error!", "Data NOT written to file!") EndIf ternal 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 Or even shorter Global $handle MsgBox(0, "Result", (FileWrite($handle, "Text") = 1) ? "Success!" : "Error!") ternal 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
pixelsearch Posted August 9, 2018 Share Posted August 9, 2018 (edited) On 09/08/2018 at 10:19 AM, water said: Because each AutoIt function call resets @error. @water : Hello. May I use this thread for a specific question related to this "@error reset when entering any Autoit function". Please have a look at the two following scripts : #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox(BitOR($MB_ICONERROR, $MB_TOPMOST), "1st script", "@error = " & @error) Endif #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) Endif The 2nd script is correct (@error = 1) because the file to be read doesn't exist. So could we say that the MsgBox function in the 2nd script didn't reset @error to 0, but the BitOr() function in the 1st script did ? I noticed Melba23 using a few times the + sign instead of BitOr(), so I tried his way and it works. My question : can we do this kind of thing with BitAnd() too ? I mean replacing BitAnd() by a mathematical operator that wont interfere with @error, as shown in the precedent scripts ? Edited August 11, 2018 by pixelsearch Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 (edited) In your case BitOr resets @error to 0 because statements are evaluated from left to right (this is true for BitAnd as well). BitAnd won't work because: BitOr($MB_ICONERROR, $MB_TOPMOST) returns 262160 BitAnd($MB_ICONERROR, $MB_TOPMOST) returns 262144 You could solve this problem with the approach you use in your 2nd script or by: #include <MsgBoxConstants.au3> Local $bFlag = BitOR($MB_ICONERROR, $MB_TOPMOST) Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox($bFlag, "1st script", "@error = " & @error) or by #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") Local $iError = @error If $iError Then MsgBox(BitOR($MB_ICONERROR, $MB_TOPMOST), "1st script", "@error = " & $iError) Edited August 9, 2018 by water pixelsearch 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
pixelsearch Posted August 9, 2018 Share Posted August 9, 2018 Thanks for your quick reply ! I started using your 2nd suggestion a few weeks ago, always keeping @error in a variable asap, like this (non runnable script) : $iKeyIndex = _ArrayBinarySearch($aArray, $CheckSum, 0 ,0 ,1) $iKeep_error = @error ; important (+++) because any function (BitOr() in the following code) would reset @error to 0 when executed +++ If $iKeep_error = 0 Then MsgBox($MB_SYSTEMMODAL, 'Entry found', ' Index: ' & $iKeyIndex & " @error = " & $iKeep_error) Else ; $iKeep_error <> 0 MsgBox(BitOR($MB_ICONERROR, $MB_TOPMOST), 'Entry NOT found', ' Index: ' & $iKeyIndex & " @error = " & $iKeep_error) EndIf And to make sure MsgBox resets @error to 0 even without BitOr() in it, here we go : #include <MsgBoxConstants.au3> Local $sFileRead = FileRead("C:\temp\this file name doesn't exist.txt") If @error Then MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) MsgBox($MB_ICONERROR + $MB_TOPMOST, "2nd script", "@error = " & @error) Endif It will show @error = 1 in 1st MsgBox.... immediately followed by @error = 0 in 2nd MsgBox Thanks water ! Link to comment Share on other sites More sharing options...
water Posted August 9, 2018 Share Posted August 9, 2018 Glad I could shed some light onto the subject My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki 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