Jump to content

Declaring Functions...


Recommended Posts

Guest BlackDiablo110
Posted

I noticed that in AutoIt, all the examples look something like this

NewFunc()

Func NewFunc()

MsgBox(0, "I am new func().", "Hear me roar.")

EndFunc

And usually when you run this script file it will print out the message box.

BUT: What I want to know is, can you declare a function, like the above, but then not use it until later or whatever? Maybe not even at all. Like in java you can make a function, but when you execute the script it won't technically use it unless you have something like:

NewFunc()

After it has been declared. I was just curious, because then you could run a function more than once or in combination with other functions without copy + pasting the entire thing.

Posted

That's the whole point of functions...

Declare as many functions as you want, then call them as you need them, so for you example:

$result = MsgBox(1, "Testing", "Press OK to run NewFunc, Cancel to exit")
if $result = 1 then
   NewFunc()
else
Exit
endif

Func NewFunc()

MsgBox(0, "I am new func().", "Hear me roar.")

EndFunc

Hope this is what you are looking for

CheersNobby

Guest BlackDiablo110
Posted

Ahh, ok thanks. For some reason, I already knew that, I guess it just didn't come to my mind. I don't know lol. But thanks anyways!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...