sumone4life Posted August 1, 2007 Share 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? Link to comment Share on other sites More sharing options...
xcal Posted August 1, 2007 Share Posted August 1, 2007 Ubound($array) - 1 How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
sumone4life Posted August 1, 2007 Author Share Posted August 1, 2007 what is the -1 for? ive seen that a couple times and i dont understand what it is for. Link to comment Share on other sites More sharing options...
qazwsx Posted August 1, 2007 Share Posted August 1, 2007 because an array starts at $array[0] not $array[1] Link to comment Share on other sites More sharing options...
mikehunt114 Posted August 1, 2007 Share 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] 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