Jump to content

Passing raw array values onto a function?


ChiGGz
 Share

Recommended Posts

Lets say I have this

;how would i accomplish something like this without assigning the three numbers a variable. 
add3Num([1,2,10])  


Func add3Num(3nums)
     3num[0] + 3num[1]+3num[2]
EndFunc

Also, how do I get the size of an array?

TIA! :D

This is just a sample so you get an idea, i know theres other ways of accomplishing this without arrays....

Edited by ChiGGz
Link to comment
Share on other sites

Not sure I understand your first question. To pass the data into a function you would need to use some sort of variable. What are you trying to get out of it?

That's just it, I want to pass it with no variable.

I've come up with this method right now.

add3Num(StringSplit("2,5,29", ","))

Stringsplit is ugly though :D

Link to comment
Share on other sites

why are you trying to avoid a variable? The variable in the function will still be needed.

It's for regression testing. Each function will be reused many times for different cases. I'm trying to have some sort of standard where a tester would only be required to input values straight into the function call.

Link to comment
Share on other sites

That's just it, I want to pass it with no variable.

I've come up with this method right now.

add3Num(StringSplit("2,5,29", ","))

Stringsplit is ugly though :D

Hi,

Hard to know what you mean..

MsgBox(0,"","add3Num(1,2,10)="&add3Num(1,2,10) ) 
Func add3Num($n1nums,$n2nums,$n3nums)
    return $n1nums+$n2nums+$n3nums
EndFunc

Best, Randall

Link to comment
Share on other sites

It's for regression testing. Each function will be reused many times for different cases. I'm trying to have some sort of standard where a tester would only be required to input values straight into the function call.

You're not making any sense at all. Please post an example of one of these functions. The code you have posted so far is invalid and does nothing. That makes it hard to use as an example for understanding what you are saying.

For example: "add3Num([1,2,10])" will only cause the script to crash because of egregious syntax errors.

Then this:

"Func add3Num(3nums)

3num[0] + 3num[1]+3num[2]

EndFunc"

Attempts to make array references where no array is declared. AutoIt variables start with a dollar sign (i.e. $3nums), so that's wrong. You add three numbers together but don't save the sum anywhere or return it from the function.

How are you going to do "regression testing" with AutoIt if you can't code a valid one-line function in AutoIt...???

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

You're not making any sense at all. Please post an example of one of these functions. The code you have posted so far is invalid and does nothing. That makes it hard to use as an example for understanding what you are saying.

For example: "add3Num([1,2,10])" will only cause the script to crash because of egregious syntax errors.

Then this:

"Func add3Num(3nums)

3num[0] + 3num[1]+3num[2]

EndFunc"

Attempts to make array references where no array is declared. AutoIt variables start with a dollar sign (i.e. $3nums), so that's wrong. You add three numbers together but don't save the sum anywhere or return it from the function.

How are you going to do "regression testing" with AutoIt if you can't code a valid one-line function in AutoIt...???

:D

"add3Num([1,2,10])" was only an example of what I was trying to illustrate as per the comment";how would i accomplish something like this without assigning the three numbers a variable. ". It was not meant to have proper syntax, as well as the exclusion of $ for array 3num. I just wanted to know if there is a way to pass an array of numbers without storing it into a variable first. I've accomplished this via " add3Num( StringSplit ("1,9,44", ",") ) "

Thanks

Link to comment
Share on other sites

"add3Num([1,2,10])" was only an example of what I was trying to illustrate as per the comment";how would i accomplish something like this without assigning the three numbers a variable. ". It was not meant to have proper syntax, as well as the exclusion of $ for array 3num. I just wanted to know if there is a way to pass an array of numbers without storing it into a variable first. I've accomplished this via " add3Num( StringSplit ("1,9,44", ",") ) "

Thanks

Hmm... that's still an array input to the function. So the function usage would be like this:

add3Num(StringSplit ("1,9,44", ","))

Func add3Num($avInput)
    Local $RET = 0
    For $n = 0 to UBound($avInput) - 1
        $RET += $avInput[$n]
    Next
    MsgBox(64, "Result", "$RET = " & $RET)
EndFunc

Anyway, glad you figured it out.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Are you saying you don't want a variable outside of the function? If that is so then using an array or other variable inside the function would still work. As in the array that PsaltyDS shows or just variables.

add3Num(1,9,44)

Func add3Num($x,$y,$z)

return $x+$y+$z

EndFunc

Link to comment
Share on other sites

Hmm... that's still an array input to the function. So the function usage would be like this:

add3Num(StringSplit ("1,9,44", ","))

Func add3Num($avInput)
    Local $RET = 0
    For $n = 0 to UBound($avInput) - 1
        $RET += $avInput[$n]
    Next
    MsgBox(64, "Result", "$RET = " & $RET)
EndFunc

Anyway, glad you figured it out.

:D

Oh, forgot about moving stringsplit into the func. I'm glad you mentioned it :P Yes that will be much easier on the eyes.
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...