Alterego Posted February 27, 2005 Share Posted February 27, 2005 (edited) I've always avoided directly declaring arrays by instead using StringSplit because I could never get them to work properly; they always cause an error. The help file says I can declare an array in the following ways:; Example 2 - Declaring arrays Dim $weeklyWorkSchedule[$daysWorking] Global $chessBoard[8][8] Local $mouseCoordinates[2], $windowStats[4] Here is an example segment of code, where count turns out to be 9 in this case.For $process = 1 to $count $hyperlink[$process] = StringInStr($pageText,$pattern1) MsgBox(1,"",$hyperlink[$process]) NextIf I don't declare $hyperlink at all it gives "You must DIM an array before you can assign to it." So, I decide to DIM it in one of two methods at the beginning of my program:Global $hyperlink Global $process Global $hyperlink[$process] or Global $hyperlink[0][0][0][0][0][0][0][0][0][0][0]The former returns==> Array variable subscript badly formatted.: Global $hyperlink[$process] Global $hyperlink[^ ERROR and the latter returnsArray variable subscript badly formatted.: Global $hyperlink[0][0][0][0][0][0][0][0][0][0][0] Global $hyperlink[^ ERROR Can anyone help me out? Edited February 27, 2005 by Alterego This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
Developers Jos Posted February 27, 2005 Developers Share Posted February 27, 2005 (edited) With DIM you basically define the array dimension...Global $hyperlink[9] would mean you can use $hyperlink[0] till $hyperlink[8].this gives an error since $process = 0 when the array is created..Global $hyperlink Global $process Global $hyperlink[$process] Edited February 27, 2005 by JdeB 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...
therks Posted February 27, 2005 Share Posted February 27, 2005 (edited) Well what's the point of declaring an array with 0 indexes?Dim $arrayName[0] = "Hey I'm gonna make an array, but I can't put anything in it"See what I mean?What you're probably experiencing problems is that the arrays start at 0 when you predeclare them.So if you go like this:Dim $array[3]Then the valid variables there are $array[0], $array[1], and $array[2]. See, there are 3 items, but $array[3] is never actually reached.So what you need is something like this:Dim $hyperlink[$count] For $process = 0 to $count - 1 $hyperlink[$process] = StringInStr($pageText,$pattern1) MsgBox(1,"",$hyperlink[$process]) NextOR this:Dim $hyperlink[$count + 1] For $process = 1 to $count $hyperlink[$process] = StringInStr($pageText,$pattern1) MsgBox(1,"",$hyperlink[$process]) NextTry those out.*Edit: Damn you JdeB, type slower. Now I just look like a rambling fool. Edited February 27, 2005 by Saunders My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Alterego Posted February 27, 2005 Author Share Posted February 27, 2005 (edited) Thanks guys. One point i'm still confused on (and cant test because im on a mac atm), what is the effect of declaring: Global $chessBoard[8][8] Seeing this example is what led me to [0][0][0][0][0][0] etc... Edited February 27, 2005 by Alterego This dynamic web page is powered by AutoIt 3. Link to comment Share on other sites More sharing options...
therks Posted February 27, 2005 Share Posted February 27, 2005 That's for two dimensional arrays (personally I'm not a fan of how they work, but that's another story). I guess it's like a way of more easily organizing information in array without having to use two seperate arrays. You'd do something like this Dim $myArray[3][5] Then you'd have all these items in the array: $myArray[0][0] $myArray[0][1] $myArray[0][2] $myArray[0][3] $myArray[0][4] $myArray[1][0] $myArray[1][1] $myArray[1][2] $myArray[1][3] $myArray[1][4] $myArray[2][0] $myArray[2][1] $myArray[2][2] $myArray[2][3] $myArray[2][4] My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Blue_Drache Posted February 27, 2005 Share Posted February 27, 2005 That's for two dimensional arrays (personally I'm not a fan of how they work, but that's another story). I guess it's like a way of more easily organizing information in array without having to use two seperate arrays.I use them to organize data in a two dimensional table with an X and Y component.$array[3][3]could be used as a base for a simple "naughts and crosses" game. Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache Link to comment Share on other sites More sharing options...
therks Posted February 27, 2005 Share Posted February 27, 2005 Naughts and crosses? That's an interesting name. I assume that's the same as what we'd call Tic-Tac-Toe? (Get three X's or three O's in a row in a 3x3 grid to win) My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
SlimShady Posted February 27, 2005 Share Posted February 27, 2005 (edited) It's called "Butter, Cheese and Eggs" here in Holland I'm serious Edited February 27, 2005 by SlimShady Link to comment Share on other sites More sharing options...
Alterego Posted February 27, 2005 Author Share Posted February 27, 2005 OK great. This new understanding is going to greatly increase my effectiveness This dynamic web page is powered by AutoIt 3. 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