Jump to content

I never get an error when this function fails (error handling)


Recommended Posts

So I'm trying to find out why it's not inputting into this rate box however I never get the error msg I've put in for error handling

Func InputRate($Rate)   
Local $hWnd1 = WinWait("[CLASS:ThunderRT6FormDC]", "", 10)ControlSend($hWnd1, "", "ThunderRT6TextBox13", $Rate)
If @error = 1 Then   MsgBox(($MB_ICONINFORMATION, "", "Cannot enter $Rate number")
EndIf  
FileWrite($hFilehandle, @CRLF & $Rate)
Sleep(4000)

EndFunc

How come I don't get the msgbox?
 

Link to comment
Share on other sites

  • Developers

Where does it state in the helpfile that the @eeror is set? 

Quote

Return Value

Success: a handle to the requested window.
Failure: 0 if timeout occurred.

Just test for the returned value in $hWnd1. ;)

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

OK, so to do that I would do the below? I tried it and it doesn't work either.

Func InputRate($Rate)  
Local $hWnd1 = WinWait("[CLASS:ThunderRT6FormDC]", "", 10)
ControlSend($hWnd1, "", "ThunderRT6TextBox13", $Rate)If $hWnd1 = 1 Then   
MsgBox(($MB_ICONINFORMATION, "", "Cannot enter $Rate number")
EndIf  

FileWrite($hFilehandle, @CRLF & $Rate)
Sleep(4000)
EndFunc

 

Link to comment
Share on other sites

18 minutes ago, CaptainBeardsEyesBeard said:

If $hWnd1 = 1 Then  

That's not the way you check if you have a valid handle.
Take a look at IsHWnd() function.
And, watch out of your indentation...

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

If you want to test for an error then test for the value that is returned in case of an error. This value is 0 (according to Jos' post.
So try:

Func InputRate($Rate)  
    Local $hWnd1 = WinWait("[CLASS:ThunderRT6FormDC]", "", 10)
    If $hWnd1 = 0 Then   
        MsgBox(($MB_ICONINFORMATION, "", "Cannot enter $Rate number")
    Else
        ControlSend($hWnd1, "", "ThunderRT6TextBox13", $Rate)
        FileWrite($hFilehandle, @CRLF & $Rate)
    EndIf  
EndFunc

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...