Jump to content
Sign in to follow this  
olo

Check if something executes correctly?

Recommended Posts

olo

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

Share this post


Link to post
Share on other sites
water

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.

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

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

Share this post


Link to post
Share on other sites
water

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 (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

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

Share this post


Link to post
Share on other sites
water

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
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

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

Share this post


Link to post
Share on other sites
water

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
  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

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

Was just about to thank you. Managed to get that one.

Share this post


Link to post
Share on other sites
water

Glad you got it working :)

  • Like 1

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2018-09-01 - Version 1.3.4.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
olo

Glad you got it working :)

Much Appreciated :thumbsup:

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
Sign in to follow this  

×