Zepx Posted December 6, 2007 Posted December 6, 2007 (edited) Hi, I would like to know the correct method to receive multiple parameters from a function.... If not mistaken, in C++, it should be Functionname(param1, param2) . . . . FunctionName(param1, param2) { ...everything here return value1, value2 } So how can I do it in autoit? Edited December 6, 2007 by Zepx
JustinReno Posted December 6, 2007 Posted December 6, 2007 (edited) Here is a simple one to start off of: _MessageBox("Stop", "Message Box", "Example!") Func _MessageBox($Icon, $Title, $Text) If $Icon = "Stop" Then MsgBox(16, $Title, $Text) EndFunc I planned on putting more, but I think you can figure it out. Edited December 6, 2007 by JustinReno
Zepx Posted December 6, 2007 Author Posted December 6, 2007 Thanks, Also, is it possible to return multiple value from the function?
rudi Posted December 6, 2007 Posted December 6, 2007 Hello,Also, is it possible to return multiple value from the function?You use autoit3 with SciTE from the Autoit download page, right? Pls edit your script (has to be saved with extension AU3), type Func, leave cursor just behind this word and press <F1> to directly jump to the help file. Regards, Rudi. Earth is flat, pigs can fly, and Nuclear Power is SAFE!
Zepx Posted December 6, 2007 Author Posted December 6, 2007 Hi Rudi, I do check the help file. But that doesn't help. I want to know if it is possible to return multiple parameters...
JerryD Posted December 6, 2007 Posted December 6, 2007 Hi Rudi, I do check the help file. But that doesn't help. I want to know if it is possible to return multiple parameters...Perhaps you should tell us what you're trying to do. By definition, a function can only return one "thing". Now that thing could be a multi dimensional array that has lots of info, or a number, or a string. You can also return error codes and extended error codes using SetError (see the help file). You can also have a function directly manipulate a variable using ByRef, and you can pass as many variables as parameters as you want and manipulate them directly. So you could have something like this: Local $Lvar1='', $Lvar2='', $Lvar3='' SomeFunction ( $Lvar1, $Lvar2, $Lvar3 ) MsgBox ( 0, "Vars are now", $Lvar1 & @crlf & $Lvar2 & @crlf & $Lvar3 ) Func SomeFunction ( ByRef $var1, ByRef $var2, ByRef $var3 ) $var1 = "One" $var2 = 2 $var3 = "Tre" EndFunc I know it's hard to find what you're looking for when you don't know what you're looking for, but using Scite and the Help File and the code samples in the help file and the AutoIT examples you can really learn a lot!
SadBunny Posted December 6, 2007 Posted December 6, 2007 Perhaps you should tell us what you're trying to do. By definition, a function can only return one "thing". Now that thing could be a multi dimensional array that has lots of info, or a number, or a string. You can also return error codes and extended error codes using SetError (see the help file). You can also have a function directly manipulate a variable using ByRef, and you can pass as many variables as parameters as you want and manipulate them directly. So you could have something like this: Local $Lvar1='', $Lvar2='', $Lvar3='' SomeFunction ( $Lvar1, $Lvar2, $Lvar3 ) MsgBox ( 0, "Vars are now", $Lvar1 & @crlf & $Lvar2 & @crlf & $Lvar3 ) Func SomeFunction ( ByRef $var1, ByRef $var2, ByRef $var3 ) $var1 = "One" $var2 = 2 $var3 = "Tre" EndFunc I know it's hard to find what you're looking for when you don't know what you're looking for, but using Scite and the Help File and the code samples in the help file and the AutoIT examples you can really learn a lot! Another quick example: #include <Array.au3> $a = test(30,5,15); Say I want this to return 30 random numbers between 5 and 15 _ArrayDisplay($a) Exit Func test($amount,$min,$max) Dim $resultArray[$amount] For $loop = 0 To $amount-1 $resultArray[$loop]=Random($min,$max) Next Return $resultArray EndFunc Roses are FF0000, violets are 0000FF... All my base are belong to you.
Zepx Posted December 6, 2007 Author Posted December 6, 2007 @JerryD, since this is autoit, I doubt it is possible... Thanks for the info. Actually my intention is to call a function without inputting any parameter. The function then runs and read from a file. It checks if the file exists, if the file contains sufficient details. It thens return the value to tell if everything is okay. If it is not, the Function should return the value False, and if it is okay, it should return the value True. That was what i'm thinking.
weaponx Posted December 7, 2007 Posted December 7, 2007 All of that stuff is possible. If you need to allow the user to input an endless amount of parameters into the function, accept an array as input. If you need to return an endless amount of paramaters, again use an array. If that isn't sufficient, use global variables outside the function. Autoit isn't picky about return types so a function can play multiple roles.
SadBunny Posted December 8, 2007 Posted December 8, 2007 @weaponx,Thanks for the info.Also be sure to check out SetError(). It will allow you to set the @error value your function returns. You could use this to distinghuish between the False or True result, and have your function return the result data you want it to return. Roses are FF0000, violets are 0000FF... All my base are belong to you.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now