sumone4life Posted August 1, 2007 Posted August 1, 2007 This is going to sound like a rediculous newbie question but i really cant find it anywhere. How do i get the index of the last term in an array?
xcal Posted August 1, 2007 Posted August 1, 2007 Ubound($array) - 1 How To Ask Questions The Smart Way
sumone4life Posted August 1, 2007 Author Posted August 1, 2007 what is the -1 for? ive seen that a couple times and i dont understand what it is for.
qazwsx Posted August 1, 2007 Posted August 1, 2007 because an array starts at $array[0] not $array[1]
mikehunt114 Posted August 1, 2007 Posted August 1, 2007 (edited) Arrays in AutoIt use a 0-based index. That means the first element is #0. This then means that the index of the last element would be one less than the actual number of elements. Like so:$array[0] = "first element"$array[1] = "second element"$array[2] = "third and last element"Ubound($array) would return 3, the total number of elements. To access the 3rd element ($array[2]), you would use an index of 2, hence the -1.Edit: typos Edited August 1, 2007 by mikehunt114 IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
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