Jump to content

Function return a value and terminate


Recommended Posts

I've spent some time browsing through what search for "return" brought. Unfortunately I couldn't find an answer ... so ... here I am.

How can a function return a value and terminate earlier than its natural end?

like this:

Func test1()
  ;some stuff here
    If $testvalue = 0 Then
       Return "bad"          ; after this Return I would like to quit this function and go back to function another()
    EndIf 
 ....
   :function continues here
EndFunc

Func another()
  ;something long here  ... so I can't call this function again without messing the program
   If test1() = "bad" Then
      ;do stuff
   EndIf 
     .....
   EndFunc

Sorry for this so generic example but the code I'm working now is darn big and complicated and any try to post it will only bring confusion.

The way I've used until now to quit a function was to use a Return without anything ... heh ... once I needed a true return I can't use this anymore.

Thanks for help.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

I guess you did not try your own sample, right? Return does exactly that.

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

My functions have a similar structure ... the problem is - after returning "bad" the function continued its execution ...

I have a "workaround" for this and it needs a global error flag set and it works but unfortunately I have many functions and already many flags (I know the code could be "cleaned" and put into a more compact/organized way ... )

anyway - thanks for advice - I will try again.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • Moderators

So add a parameter to the function:

another()
Func test1($testvalue)
    If $testvalue = 123456 Then
       Return "bad"             ; after this Return I would like to quit this function and go back to function another()
    EndIf
EndFunc

Func another()
   If test1(123456) = "bad" Then
      MsgBox(64, 'Info', 'test1() = bad')
   EndIf
EndFunc

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I am ASHAMED.

My appologies for wasting the time to all people who read my message and replied.

My bad - The Return statement do exactly what /dev/null said.

The return code was in another branch of my script.

Thanks and appologies.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

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