Delta01 Posted April 10, 2008 Share Posted April 10, 2008 Hey, I'm kind of new to arrays and I'm trying to declare it at the start of my script so that my Case statement wont error out. I get errors like telling me it's exceeded the variables subscript. How do I declare arrays like $Hello[1] so that if I have a case statement like Case $Hello[1] = "Yes" I won't get an error if $Hello[1] wasn't been set. I've checked the helpfile... Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 10, 2008 Moderators Share Posted April 10, 2008 (edited) Hey, I'm kind of new to arrays and I'm trying to declare it at the start of my script so that my Case statement wont error out. I get errors like telling me it's exceeded the variables subscript. How do I declare arrays like $Hello[1] so that if I have a case statement like Case $Hello[1] = "Yes" I won't get an error if $Hello[1] wasn't been set. I've checked the helpfile...Learn the functionality of ReDim/UBound or cheat and use _ArrayAdd Edited April 10, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Delta01 Posted April 10, 2008 Author Share Posted April 10, 2008 No. That's not what I need. My code is similar to... Dim $Command[2] ;Create GUI While 1 ;Declare a few variables For $i = 1 To $Command[2] Next sleep(100) WEnd Try running that, that's the error I get and that's what I'm trying to fix. Sorry, I wasn't very clear. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 10, 2008 Moderators Share Posted April 10, 2008 (edited) No. That's not what I need. My code is similar to... Dim $Command[2] ;Create GUI While 1 ;Declare a few variables For $i = 1 To $Command[2] Next sleep(100) WEnd Try running that, that's the error I get and that's what I'm trying to fix. Sorry, I wasn't very clear.You're wrong. That Is what you needed. For $i = 1 To Ubound($Command) - 1 Unless $Command[2] = an integer. Also keep in mind, you cannot exceed the limit you propose. [2] < is the max, Arrays start at 0 (zero), so 0 and 1 are the only two elements you can use without exceeding the array elements. Edit: Example: Dim $Command[2] 2 is the Max elements I can use. [0] = 1st Element [1] = 2nd Element [2] = 3rd Element = Exceeding element size Edited April 10, 2008 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Delta01 Posted April 10, 2008 Author Share Posted April 10, 2008 You're wrong. That Is what you needed. For $i = 1 To Ubound($Command) - 1 Unless $Command[2] = an integer. Also keep in mind, you cannot exceed the limit you propose. [2] < is the max, Arrays start at 0 (zero), so 0 and 1 are the only two elements you can use without exceeding the array elements. Edit: Example: Dim $Command[2] 2 is the Max elements I can use. [0] = 1st Element [1] = 2nd Element [2] = 3rd Element = Exceeding element size Sorry and thank you. Link to comment Share on other sites More sharing options...
Delta01 Posted April 10, 2008 Author Share Posted April 10, 2008 (edited) Sorry for the double post... Thanks for fixing the array error, but now it won't read what I want it to. Below is an example in notepad (type some text into notepad, ie Hello*Test and it should read the Test.) Dim $ReadCommand[5] Dim $Command[5] $Title = "Untitled - Notepad" $Text = ControlGetText($Title, "", "Edit1") $Command = StringSplit($Text, "*") For $i = 1 To Ubound($Command, 2) - 1 $ReadCommand = StringSplit($Command[2], @CR) Next MsgBox(64, "Text read after the *", $ReadCommand[1]) Edited April 10, 2008 by Delta01 Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted April 10, 2008 Moderators Share Posted April 10, 2008 Sorry for the double post... Thanks for fixing the array error, but now it won't read what I want it to. Below is an example in notepad (type some text into notepad, ie Hello*Test and it should read the Test.) Dim $ReadCommand[5] Dim $Command[5] $Title = "Untitled - Notepad" $Text = ControlGetText($Title, "", "Edit1") $Command = StringSplit($Text, "*") For $i = 1 To Ubound($Command, 2) - 1 $ReadCommand = StringSplit($Command[2], @CR) Next MsgBox(64, "Text read after the *", $ReadCommand[1])1. Ubound($Command, 2) << You are referencing a 2 dimensional array but you only have a 1 dimensional array. 2. Why are you going to use a "loop" (For/Next) if you are hard coding the split with [2]? 3. http://www.autoitscript.com/forum/index.ph...st&p=295888 is the best I think I can help you now without referring (confusing you) with http://en.wikipedia.org/wiki/Array Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Bert Posted April 10, 2008 Share Posted April 10, 2008 Take a look at this - http://www.autoitscript.com/wiki/index.php?title=Arrays The Vollatran project My blog: http://www.vollysinterestingshit.com/ Link to comment Share on other sites More sharing options...
Richard Robertson Posted April 10, 2008 Share Posted April 10, 2008 No. No. You are trying to read an array index that does not exist because AutoIt arrays are zero index. If you declare Dim $var[2] you are creating a two index array. This means you have indexes 0, 1. If you try to go out of this, you get a subscript error. 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