232showtime

Error Checking

3 posts in this topic

Hello World!!!

this is the first time I use Error checking and Im really confused with this, am I doing it correctly?.

I check the help file and came up with this

#include <MsgBoxConstants.au3>
;1st example
Local $hWndR = wtf(WinExists("[CLASS:CalcFrame]"))

If @error Then
    MsgBox($MB_SYSTEMMODAL, "Error", "calculator does not Exist!!!")
Else
    MsgBox($MB_SYSTEMMODAL, "Result", "calculator Exist!!!")
EndIf
Exit

Func wtf($hWndR)
    If $hWndR < 1 Then
        SetError(2);where did you get this "2"
    ElseIf $hWndR > 1 Then
        SetError(1); and this "1"
    EndIf
    Return $hWndR
EndFunc   ;==>wtf

;~ 2nd Example
Local $hWndR = wtf(WinExists("[CLASS:CalcFrame]"))

If Not @error Then
    MsgBox($MB_SYSTEMMODAL, "Error", "calculator does not Exist!!!")
ElseIf @error Then
    MsgBox($MB_SYSTEMMODAL, "Result", "calculator Exist!!!")
EndIf
Exit

Func wtf($hWndR)
    If $hWndR = 1 Then
        SetError(2)
    ElseIf $hWndR = -1 Then
        SetError(1)
    EndIf
    Return $hWndR
EndFunc   ;==>wtf

Please can someone enlighten me...


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

You have two functions with the same name ("wtf") in your scipt ;)


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You need to check the function you call in the help file.
Some denote an error in the return value (like WinExists), some other functions set macros @error / @extended.
I would simplify your script to:
 

#include <MsgBoxConstants.au3>
Local $hWndR = WinExists("[CLASS:CalcFrame]")
If $hWndR <> 1 Then
    MsgBox($MB_SYSTEMMODAL, "Error", "Calculator does not exist!")
Else
    MsgBox($MB_SYSTEMMODAL, "Result", "Calculator does exist!")
EndIf
Exit

 

Edited by water
1 person likes this

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
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

  • Similar Content

    • 232showtime
      By 232showtime
      Hi, Im kind of confused with seterror, If I put Sleep SetError is working fine, but without sleep set error doesn't work. please can someone give me a good and easy example. TIA
      Parameters:
      code = I don't really understand this, is it ok to put any numbers??? or some numbers represent something?
      extended = same situation, is it ok to put any integer???
      #include <Array.au3> #include <File.au3> $sFilePath = "C:\New Folder" $FLTAR = _FileListToArrayRec($sFilePath = "", "*.pdf", $FLTAR_FILES, $FLTAR_NORECUR, $FLTAR_SORT, $FLTAR_FULLPATH) If @error Then $FLTAR = SetError(1, 0, "0 files for transfer") Sleep(100) If $FLTAR = @error Then MsgBox(0, "$FLTARIf", $FLTAR) Else MsgBox(0, "$FLTARElse", "SUCCESS") EndIf I used 1 and 0 for testing only.