Jump to content

Recommended Posts

Posted

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.

Posted

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

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

 

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

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

 

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
×
×
  • Create New...