Jump to content

Check if something executes correctly?


Recommended Posts

I am trying to return a value of 1 = pass, 0 = fail.

But I dont know if my winexists is the correct function to use?

Is there a function that after I run my command and it was successful that I can return 1 or 0.

As I think my If statement is wrong :(

#include-once

Func RemovePath($RmPath)

    DirRemove($RmPath, 1)

EndFunc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

#include <..\Library\RemovePath.au3>

Func Test_RemovePath()

    Local $var = EnvGet("HOMEDRIVE")

    Local $var1 = EnvGet("HOMEPATH")

    Local $RmPath = $var & "\" & $var1 & "\Desktop\EEX\DDX\"

    RemovePath($RmPath)

    If FileExists($RmPath) Then
        Return 1
    Else
        Return 0
    EndIf


EndFunc
Link to comment
Share on other sites

Most of the AutoIt functions return a value and set the macros @error and @extended to 0 if the function ran succesfully.

If an error occurred then either thze return value or @error that and which error happened.

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

Most of the AutoIt functions return a value and set the macros @error and @extended to 0 if the function ran succesfully.

If an error occurred then either thze return value or @error that and which error happened.

Ok thanks man. I shall research into this @error. :)

Link to comment
Share on other sites

Make sure to test the return value OR @error. Not all functions set the return value, not all functions set @error to denote an error - it depends on the function.

The help file is your friend!

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

Make sure to test the return value OR @error. Not all functions set the return value, not all functions set @error to denote an error - it depends on the function.

The help file is your friend!

I have msgboxes in place. But does SetError(1) set the @error = 1? As there is a SetError(2)? I thought it would be SetError(0) to have @error = 0

Link to comment
Share on other sites

Accordibng to the help file:

The first parameter sets the value of @error, the second of @extended and the third the return value.

Example

Func Test()
    Return SetError(7, 12345, "Wrong Result")
EndFunc

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

Accordibng to the help file:

The first parameter sets the value of @error, the second of @extended and the third the return value.

Example

Func Test()
Return SetError(7, 12345, "Wrong Result")
EndFunc

Yea the help file is a bit confusing for this one.

So can I say

If @error = 0 Then
MsgBox(4096, "Success", "Yes")
SetError(1)
Return 1
Else
MsgBox(4096, "Error", "No")
Return 0
EndIf
Edited by olo
Link to comment
Share on other sites

I wouldn't set @error on success. Use something like this:

If @error = 0 Then
    MsgBox(4096, "Success", "Yes")
    Return 1
Else
    MsgBox(4096, "Error", "No")
    Return 0
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

Glad you got it working :)

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

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...