typhoon Posted November 25, 2006 Share Posted November 25, 2006 (edited) In testing, it seems that arrays are 0-based, but the examples in the docs seem to imply that they are 1-based. Can someone clarify? Here's an example dim $LABEL_TEXT[4] = ["left", "right", "top", "bottom"] for $i = 1 to 4 MsgBox(0, "note", $LABEL_TEXT[$i]) GUICtrlCreateLabel($LABEL_TEXT[$i], 2 * ($i - 1) * $CELL_WIDTH, 0) next I am expecting it to iterate from [1] to [4] but it starts with the second value and ends with an out-of-bounds error. So I assume the arrays are actually 0-based despite the examples using [1] as the starting point? Edited November 25, 2006 by typhoon Link to comment Share on other sites More sharing options...
Developers Jos Posted November 25, 2006 Developers Share Posted November 25, 2006 In testing, it seems that arrays are 0-based, but the examples in the docs seem to imply that they are 1-based. Can someone clarify? Here's an example dim $LABEL_TEXT[4] = ["left", "right", "top", "bottom"] for $i = 1 to 4 MsgBox(0, "note", $LABEL_TEXT[$i]) GUICtrlCreateLabel($LABEL_TEXT[$i], 2 * ($i - 1) * $CELL_WIDTH, 0) next I am expecting it to iterate from [1] to [4] but it starts with the second value and ends with an out-of-bounds error. So I assume the arrays are actually 0-based despite the examples using [1] as the starting point? Arrays are always zero-based... so your example goes from 0 to 3 ... Some examples are based on StringSplit() which createss a zero based array. position 0 hold the number of items found and the first Item is put in position 1 . 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...
jpm Posted November 25, 2006 Share Posted November 25, 2006 Where did you found the info of 1-based? Link to comment Share on other sites More sharing options...
typhoon Posted November 25, 2006 Author Share Posted November 25, 2006 In the Help file, under Variables, all of the Array examples begin iteration at [1]. Link to comment Share on other sites More sharing options...
jpm Posted November 25, 2006 Share Posted November 25, 2006 In the Help file, under Variables, all of the Array examples begin iteration at [1].Thanks, But the declaration of the $array is not mention so you cannot conclude the 1-based assertion. You have to look in the DIM/Local/Local definition. AnyWay I will update the Variable page to avoid such "deduction" Link to comment Share on other sites More sharing options...
Uten Posted November 25, 2006 Share Posted November 25, 2006 Good catch @Typhoon,At last someone really reading the help file I have noticed before that arrays can be a problem area for a new scripter so I have created a wiki page called Arrays. I will try to fill in some content during the day. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling 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