Jump to content

SetError returned error


AutID
 Share

Recommended Posts

Hello,

I have an infinity while...wend loop. Within the while loop i have a for...next loop.

In the for/next loop i am calling a function and checking if it returns an error or a value, something like this:

Local $hState = 1
While (True)
If $hState Then
For $i = 0 To 10
$sFunc = _myFanc()
If @error Then
ConsoleWrite("Error: " & @error & @CRLF)
ExitLoop ;will exit for/next loop and restart the whole proccess
Else
ConsoleWrite($sFunc & @CRLF)
EndIf
Next
EndIf
Sleep(100)
WEnd
However if the $sFunc returns an error once, everytime the loop is restarted it will return the same error.

In _myFunc() i have 3 SetErrors

SetError(1)

SetError(2)

SetError(3).

Any ideas? I haven't quitly used SetError function so i am not sure if my bug is that function.

Cheers

Link to comment
Share on other sites

According to the help file for SetError: "When entering a function @error is set to 0"

If your function returns @error <> 0 then either an error occurred in your function or you have called SetError.

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

I have called seterror in my function. My func checks for a name in a ini file. If the name exists it returns the name, else it returns seterror depending of the names in the ini file. When i call _myFunc for the first time if the name doesnt exists it returns the @error set from seterror. When i call it a second time, since it is an infinity loop, i think the func doesnt run. It returns the same @error it returned the first time it was called even if the name exists...

Link to comment
Share on other sites

Sorry, but it is not possible to help you without seeing the full code.

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

Sorry, but it is not possible to help you without seeing the full code.

Ahh i played a little bit more with it and found my error.

_myFunc has a text in it stored and based on that text it returns the errors via SetError.

When i called the function it was checking the text and returning the error. Then i was using ExitLoop. However the $text var inside the _myFunc function was still the same since it is in Global scope and the function was returning the same error again and again each time it was called. So i just refreshed the $text before the exitloop and fix it.

Local $hState = 1
While (True)
If $hState Then
For $i = 0 To 10
$sFunc = _myFanc()
If @error Then
ConsoleWrite("Error: " & @error & @CRLF)
$text = ""
ExitLoop ;will exit for/next loop and restart the whole proccess
Else
ConsoleWrite($sFunc & @CRLF)
EndIf
Next
EndIf
Sleep(100)
WEnd
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...