TheDcoder

Setting the @error returned by a UDF in advance

15 posts in this topic

Hello, I recently opened a bug report without reading the Helpfile... My bad :sweating:. After @Melba23's gentle reminder, I was curious about why it was like that.

It is about SetError's behaviour. This is the example from the bug report:

Example()

If @error Then
    ConsoleWrite("Error" & @CRLF)
Else
    ConsoleWrite("No Error" & @CRLF)
EndIf

Func Example()
    SetError(1)
    Sleep(1000)
EndFunc

What I tried to do is set Example's (my user defined function's) @error value to 1... but the value set by SetError is cleared after calling a function, I wonder why? Why should calling to an external function effect my function's @error which is set when my function returns.

Setting the error of a UDF in advance by using SetError makes sense... but I cannot find a reason why calling a function should clear it? Please note that I am not talking about @error, I am talking about the @error set by my function when it ends/returns!

I hope someone can enlighten me, thanks for the answers in advance! :D

P.S I tried to explain my best but my English is not very good and I didn't feel like I did a good job explaining today, so please pardon any mistakes that I have made :)

1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

13 minutes ago, TheDcoder said:

Please note that I am not talking about @error, I am talking about the @error set by my function when it ends/returns!

One and the same thing. The way I understand it, @error is a macro, and any error return is stored in that (one) macro. That's why any following function clears it or stores its own result in it, replacing any previous value.

P.S. And if you look at the first Help file example for SetError, you will see that the error is stored in the Return. Your code doesn't do that.

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@TheSaint Yes, I agree that @error is a macro and it is used by every function so it is replaced after every function call.

But what I am talking about is:

13 minutes ago, TheDcoder said:

the @error set by my function when it ends/returns!

The @error macro should be set to 1 after my function Example() ends. Think of it as me setting my function's @error macro in advance... It is totally not related to the @error macro which is reset after every call


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi. 

Because Sleep() returns with no error your func returns with no error. Therefor @error is set to 0.

Conrad

Edited by Simpel
2 people like this

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Exactly. the error returned to your function is from that last command in your function ... which is Sleep.

When you are setting the error, you are not setting it for the function or a command, but rather to the @error macro ... which Sleep clears.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Hello @Simpel, looks like you have fallen into the same trap.

1 minute ago, TheSaint said:

the error returned to your function is from that last command in your function ... which is Sleep.

This looks like a key point, you said "the error returned to your function". That error returned to my function is totally unrelated/irrelavent. I was talking about the error returned by my function, not to my function! The @error can be set to 1 when my function ends, no need to it be 0 just because I called a function before returning. The error specified in SetError should be set as the @error macro after my function ends.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

To keep your error I use something like this:

example()

Func example()
   Local $iError = 0
   ; doing a lot of stuff and now
   $iError = 1
   Sleep(1000)
   Return SetError($iError)
EndFunc

Sometimes I do this with $iExtended too. 

Conrad

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Gawd.

Look at it this way.

You have a bucket called @error and there is only one.

You fill that bucket with water, that we will call 1.

You put that bucket on you scooter and drive around to the Function at my place.

On the way there, a person named Sleep empties your bucket.

When you get to the Function at my place 1 has disappeared ... the @error bucket is empty.

P.S. I forgot to say, that you were originally at the Function at my place, but left with your bucket, to collect some @error. You shouldn't have let Sleep tag along for the ride. :muttley:

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@Simpel I am doing it too, but that is just a work around :).


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

No, not a work around. 

There is only one macro @error and that should always work. Sleep() is a function too. A function you call inside your function. Why shouldn't sleep() return nothing and not setting @error?

Conrad

Share this post


Link to post
Share on other sites

SetError will set @error only as long with your expected error as it is the "last" line before return. 

Share this post


Link to post
Share on other sites
3 minutes ago, TheSaint said:

You have a bucket called @error and there is only one.
You fill that bucket with water, that we will call 1.
You put that bucket on you scooter and drive around to the Function at my place.
On the way there, a person named Sleep empties your bucket.
When you get to the Function at my place 1 has disappeared ... the @error bucket is empty.

Wow, that makes perfect sense :blink:. My line of thought was not the same... let me explain what I was thinking:

Quote

There is a person called AutoIt and his duty is to go to every home in a street. Every person in the home assigns him a tasks and he does them. When a person commands "SetError to 1", he remembers that number and when he visits the next house, he shouts that number to the first person in that house.

Home = line of code which calls a function
Person = lines of code within that function (Home)

When a line is SetError(x), AutoIt should remember it and shout it (pass it) to the first person in the next home (another line of code outside the function).

Sorry for being not so creative...


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

13 minutes ago, Simpel said:

SetError will set @error only as long with your expected error as it is the "last" line before return. 

Unless of course all the others are  functions that don't call seterror.

If there is any gap in the helpfile I would say its in leaving off the error description from Sleep().  It should read

"Always sets error to 0 since there is literally no way to mess up the sleep command and still run the script"

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

10 minutes ago, TheDcoder said:

When a line is SetError(x), AutoIt should remember it and shout it (pass it) to the first person in the next home (another line of code outside the function).

But what happens if another error happens meanwhile, before you pass it? It is all done on a command by command basis.

It would start to get awfully complex real soon if AutoIt were to try doing otherwise.

What error would you want returned by your function? First or Last?
What if First was nothing much, but Last was script or usage breaking?

Without having deep AI understanding of the code, how would AutoIt prioritize?

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

way to go Dcoder you broke TheSaint

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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

    • pboom
      By pboom
      I am looking for a way to retrieve filtered messages from the ‘system debug channel.' also known as  ‘kernel-mode debug output.'

      AutoIt must do the capture in real time. The following AutoIt UDF almost does what is required but it only captures application level, or Win32 debug output.

      https://www.autoitscript.com/forum/topic/82889-capture-debug-information-udf/#comment-593268

      The utility DebugView by Sysinternals captures the information as required by turning on Capture Kernal and in my case using the Filter include:

      *Incoming connection*

      The use of DebugView to do this is covered in the following tech note;

      https://www.tacticalsoftware.com/support/tech-notes/logging-com-port-activity.htm

      https://technet.microsoft.com/en-us/sysinternals/debugview.aspx

      However to make to make the information from DebugView available to my AutoIt script required DebugView capture to a text file and then my AutoIt script monitor that file for changes. The use of DebugView to capture the system debug channel could be made to work, but it was less than reliable and difficult to get started. The startup wasn’t something that could be easily automated not even with AutoIt.

      If you understood what I am talking about and made it this far, I think an explanation of the application is in order. Lots of details here sorry trying to answer questions in advance.

      I support a large installation of General Electric MUSE application. MUSE is a Windows-based medical application that processes and archives ECGs (electrocardiograms) taken on dedicated hardware (ECG Carts). Several methods exist on the cart to get the ECG from the Carts to the MUSE system; they range from floppies (on old obsolete hardware), memory cards, RS232 serial ports, and hardwired network connections.

      In our installation, we choose not to use the vendor-supplied network solution due to a variety of reasons I won’t get into here.  Instead, we have designed our own connection solution.

      We use a wireless serial server mounted on the ECG carts connecting to a server running a Serial/IP COM Port Redirector. The ECG cart and MUSE application think they are talking to each other via an RS232 port and as far as they are concerned, they are. However, this RS232 cable happens to run through our province (think State) wide Health Care WAN.  The hardware and software used can be seen on these two sites;

      http://www.bb-elec.com/Products/Wireless-Cellular/AirborneM2M-802-11-a-b-g-n-Dual-Band-Wireless/AirborneM2M-Industrial-Dual-Band-Wi-Fi-Router-Brid.aspx

      https://www.tacticalsoftware.com/virtual-serial-port-redirector/serial-ip.htm

      This setup works well we have over 130 ECG carts connecting using this setup. However, the end users are not technical, and there is a lot that can go wrong with wireless connections. So we do get complaints, often after the fact, that the ECG cart would not connect. A log of what ECG carts connected and when would be very helpful.

      The Serial redirector software can be configured to log all activity to the Kernal-mode Debug output. The serial redirector software itself being kernel level software. For configuration of the Wireless modules, we have custom written software (written in AutoIt) that amongst other things can display relevant configuration information for a Wireless module given it’s IP address.

      By extracting messages like the ones below from the Kernal-Mode Debug channel;

      COM56 : ½ Incoming connection from 10.158.188.172:51562

      COM18 : ½ Incoming connection from 10.158.188.200:50896

      COM19 : ½ Incoming connection from 10.158.188.180:59074

      COM68 : ½ Incoming connection from 142.239.15.82:34322

      We can have the module configuration program retrieve the configuration. The retrieved configuration contains more information such as the module ID number and wireless signal strength. This information is then logged to a file which is later loaded into a database. We can then query the database for connections made by a particular module within a specified time frame. The results of these Queries help us determine if the module was connected or is having problems connecting. Problems are usually indicated by poor signal strength and frequent re-connecting.

      So what I am looking for is a way for our module configuration program (written in AutoIt) to retrieve filtered Kernal-Level debug messages directly without using the DebugView application.

      The Forum post listed at the first of this message includes the source code for the DLL. So if you are versed in these matters and Visual Studio this may be an easy task. I looked at what needed to be done but, I was way over my head. If you look up the price of the serial IP redirector software, you can see that there is some money in our project for such things however, I do have a spending limit for purchases such as this.

       
    • jollypk
      By jollypk
      hI,
      Is there any UDF for Zeromq ?
      I need to communicate with a remote and local socket. Any suggestion or guidance will be very appreciated.
       
      Thanks
    • FrancescoDiMuro
      By FrancescoDiMuro
      Good morning everyone
      I am working on a little script, which takes some data from a SQLite DB and should create a sort of report, inserting rows in a Word Document... I arrived at the point of:
      _Word_DocTableWrite() and, I don't know how to set the range parameter? What does that specify? 
      Thanks a lot for the help
      EDIT:
      Managed to write a table in the Word document, but now I get an error when I save the document with _Word_DocSaveAs(), with error 2.
      Which are possible causes? Thanks a lot, again
      EDIT 2:
      ... And, how can I set a border to the table? Maybe, with a sort of auto-formatting for text ( larger is the text, larger is the height/width of the table's cell ).
      Thanks  
      EDIT 3 ( bug ):
      Including the parameter $WdSaveChanges in the function _Word_DocSaveAs(), a save dialog box appears, and it should not do it, as it's written in the MSDN documentation:
      wdSaveChanges -1 Save pending changes automatically without prompting the user. Thanks again for everyone will answer to me  
    • SorryButImaNewbie
      By SorryButImaNewbie
      Hello,
      I try to add a new UDF to my AutoIT library, and it seems I fail. I started to work following the insturctions found on the wiki . 
      I made an extra folder just next to my AutoIT folder, called ExtraUDF, and copied the file CUIAutomation2.au3 in it (I try to use this UDF for automating a program) then I run sciteconfig, set this folder up as User Include Folder, applied the changes, then run the calltip manager and got a msg when I tried to parse it. I attach a few pictures for better present the problem.
      I think I miss something here, should i put anything else on the ExtraUDF folder? I dont think that the CallTip manager added the udf to scite, If I try to run it i get a msg saying that I Scite cant open the include file and naturally after that, It can't use the functions called from it.
      Thank you for your help and insight as always! Please ask, if anything is fuzzy about the problem
       





    • Gowrisankar
      By Gowrisankar
      Good day to the members of the forum.. 
      Is there any UDF that is available to automate Attachmate Extra Mainframe sessions?
      I am trying to automate mainframe processes. I couldn't get values from particular co-ordinates in mainframe or pass values to particular co-ordinates in mainframe.
      Please let me know if there is any UDF or any other kind of solution is available. 
      Thanks and regards,
      Gowrisankar R.