MasonMill Posted August 8, 2010 Share Posted August 8, 2010 Hi guys, What is the quickest way to find the last element of an array? _arraymax() finds the highest value but id like the last element in the array regardless of its value. I couldn't find a function that would find the size of an array. The arrays would be different sizes. Thanks! -Mason Link to comment Share on other sites More sharing options...
Tvern Posted August 8, 2010 Share Posted August 8, 2010 Ubound() Link to comment Share on other sites More sharing options...
jaberwacky Posted August 8, 2010 Share Posted August 8, 2010 (edited) Quick 'n' dirty... (that's what they call me) Global Const $array[3] = [1, 2, 3] Global Const $element = LastElement($array) ConsoleWrite($element & @LF) Func LastElement(ByRef Const $array) Return UBound($array) EndFunc ;==>$lastElement Edited August 8, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
MasonMill Posted August 8, 2010 Author Share Posted August 8, 2010 Cool! Ill look into Ubound thanks guys! Link to comment Share on other sites More sharing options...
Developers Jos Posted August 8, 2010 Developers Share Posted August 8, 2010 (edited) Quick 'n' dirty... (that's what they call me) Global Const $array[3] = [1, 2, 3] Global Const $element = LastElement($array) ConsoleWrite($element & @LF) Func LastElement(ByRef Const $array) Return UBound($array) EndFunc ;==>$lastElement mmm... Not sure what func LastElement is supposed to do more than UBound() here? or did you mean?: Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Edited August 8, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 8, 2010 Share Posted August 8, 2010 or did you mean?: Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Criminy! Wow, I totally overlooked the obvious bug in my code. Thanks Jos. I saw the '3' and assumed it was the value of the element! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
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