somdcomputerguy Posted February 11, 2010 Share Posted February 11, 2010 Ok, here is what I am attempting to do, create an array from text (format -> xxx.xxx.xxx.xxx) read from a file, which is first split into an array. Local $IPArr[1][1] Local $fname = "C:\xampp\htdocs\somdcomputerguy\banned\oldIP.txt" Local $flines = _FileCountLines($fname) Local $file = FileOpen($fname, 0) For $x = 1 To $flines $line = FileReadLine($file) If @error = -1 Then ExitLoop ;EOF $IPline = StringSplit($line, ".") For $n = 1 To UBound($IPline) - 1 ;ConsoleWrite("[" & $x & "][" & $n & "] " & $IPline[$n] & " ") $IPArr[$x][$n] = $IPline[$n] ;; Error Here Next ;ConsoleWrite(@LF) Next FileClose($file) This is the error. Array variable has incorrect number of subscripts or subscript dimension range exceeded.: $IPArr[$x][$n] = $IPline[$n] ^ ERROR It has taken me years and years to come up with just this simple bit of code. I usually avoid asking for help in a situation like this, and just go back to reading and reading until I've figured out my mistake, but now I sway.. So, what am I doing wrong here? Thanks, -bruce - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
jchd Posted February 11, 2010 Share Posted February 11, 2010 Local $fname = "C:\xampp\htdocs\somdcomputerguy\banned\oldIP.txt" Local $flines = _FileCountLines($fname) Local $file = FileOpen($fname, 0) Local $IPArr[$flines][4] For $x = 0 To $flines - 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ;EOF $IPline = StringSplit($line, ".", 2) For $n = 0 To UBound($IPline) - 1 ;ConsoleWrite("[" & $x & "][" & $n & "] " & $IPline[$n] & " ") $IPArr[$x][$n] = $IPline[$n] ;; Error Here Next ;ConsoleWrite(@LF) Next FileClose($file) ReDim $IPArr[$x][4] Does this work (untested)? This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
whim Posted February 11, 2010 Share Posted February 11, 2010 Maybe move Local IPArr[1][1] down and declare instead as Local $IPArr[$flines+1][5] ? ( assuming that $IPline has 4 elements ) HTH, whim Link to comment Share on other sites More sharing options...
Yoriz Posted February 11, 2010 Share Posted February 11, 2010 The place your going wrong is that when you set up the array you have made it only able to contain one value in both the indexes of the array. ie You have Local $IPArr[1][1] this needs to be more like Local $IPArr['this should be a value enough to contain the number of lines']['this should be a value enough to contain the number of splits in each line'] GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF. Link to comment Share on other sites More sharing options...
enaiman Posted February 11, 2010 Share Posted February 11, 2010 (edited) Definitely the error stays in declaring $IPArr[1][1] That means that your array members will be $IPArr[0][0] and $IPArr[0][1] so whenever you try to access anything but these you'll get that error (your script will work for 1 line but it will fail for the second. Here are a couple suggestions: - when dealing with this type of error and can't figure where it goes wrong, put a ConsoleWrite inside your loop to show the index values (ConsoleWrite("x= "&$x&", n= "&$n&@CRLF)); this way you can see what was the last index number - when your script relies on StringSplit every line, always add a condition to go to next line if the current one is empty (does not contain any separators) - when you are interrested in processing "lines" from a file, it is better (and easier and faster) to use _FileReadToArray instead of FileReadLine. The reasons behind this? 1) Array returned (everything already there) 2) Number of lines in element[0] 3) Only 1 file operation (faster) 4) No need to open/read line/close the file, count lines, look for EOF ... Edited February 11, 2010 by enaiman SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 12, 2010 Author Share Posted February 12, 2010 @jchd, Thanks, but no, it doesn't. Generates the same error also. @whim, I even declared IPArr[10][4] as that is the 'size' of the text file in an array (after the StringSplit (10 lines of IP addresses)) @Yoriz, At one point I had IPArr[0][0], then defined as [100][100], no go with either. @enaiman, Actually the error points to the second IPArr line, where I'm trying to populate the array. Real confusing to me is that the commented ConsoleWrites there already work just as I intend, so for now I have only a way to text view an array, instead of creating one.. I believe I will go back to using _FileReadToArray, which I was using earlier, till I remember why I stopped using it that way, or find another way to use it.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
enaiman Posted February 12, 2010 Share Posted February 12, 2010 Why don't you use _ArrayDisplay too? (forgot to mention that one in my previous post) SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script wannabe "Unbeatable" Tic-Tac-Toe Paper-Scissor-Rock ... try to beat it anyway :) Link to comment Share on other sites More sharing options...
somdcomputerguy Posted February 13, 2010 Author Share Posted February 13, 2010 (edited) Well I got this to work, enough to go to the next step anyway. Eventually, I aim to make a program that will do the same as this.sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 IPcopy.txt (GnuWin32)#include <array.au3> Local $IPArr[1][1], $x, $lines, $n, $IPline _FileReadToArray("C:\xampp\htdocs\somdcomputerguy\banned\oldIP.txt", $lines) ;_ArrayDisplay($lines, "$lines") ReDim $IPArr[UBound($lines)][5] For $x = 1 To $lines[0] $IPline = StringSplit($lines[$x], ".") For $n = 1 To UBound($IPline) - 1 $IPArr[$x][$n] = Int($IPline[$n]) Next Next ;_ArrayDisplay($IPArr, "$IPArr") _ArraySort($IPArr, 0, 0, 0, 1) _ArrayDisplay($IPArr, "$IPArr - sorted") EndFuncoldIP.txt76.20.142.194 76.20.140.180 92.48.106 194.8.75.214 84.19.188.30 84.19.190.30 91.117.133.10 91.118.132.100 221.120.250.37 221.120.238.57 221.125.222.17 92.241.169.166 131.107.65.41 64.27.10.35 89.149.241.229 Edited February 13, 2010 by snowmaker - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. 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