handro Posted October 18, 2007 Posted October 18, 2007 (edited) CODE$Line2=0 Do $Line2+=1 $LineRead2=FileReadLine("Database.txt",$Line2) $Split2=StringSplit($Lineread2,",") MsgBox(0,"Worked:",$Split2[2]) Until $Lineread2="" Error: C:\Documents and Settings\Nobody\Desktop\Program\Array.au3 (16) : ==> Array variable has incorrect number of subscripts or subscript dimension range exceeded.: Note: The program successfully opens a messagebox and shows Split[2] from all 4 lines, but If I have it read a string from a file and replace it with Split[2] it won't do it until this error is resolved. (my guess, since it didint work) Ignore the line number, I have more code above this that isn't associated with this particular loop. Edited October 18, 2007 by handro
-Ultima- Posted October 18, 2007 Posted October 18, 2007 Trace through and see what's happening. Every time you split the string, the number of elements becomes less and less. Eventually, you reach a point where you're trying to split an empty string with the comma character, which results in an array [1, ""] -- only 2 elements with the max index being 1. [ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]
Valuater Posted October 18, 2007 Posted October 18, 2007 (edited) Maybe.. $Line2 = 0 Do $Line2 += 1 $LineRead2 = FileReadLine("Database.txt", $Line2) If @error = -1 Then ExitLoop $Split2 = StringSplit($LineRead2, ",") If IsArray($Split2) And $Split2[0] >= 2 Then MsgBox(0, "Worked:", $Split2[2]) Until $LineRead2 = "" 8) Edited October 18, 2007 by Valuater
Valuater Posted October 18, 2007 Posted October 18, 2007 Trace through and see what's happening. Every time you split the string, the number of elements becomes less and less. Eventually, you reach a point where you're trying to split an empty string with the comma character, which results in an array [1, ""] -- only 2 elements with the max index being 1. ??? He is reading a file ??? 8)
handro Posted October 18, 2007 Author Posted October 18, 2007 Valuater , the script ran fine when I did that
handro Posted October 18, 2007 Author Posted October 18, 2007 (edited) CODE$Line2=0 Do $Line2+=1 $LineRead2=FileReadLine("Database.txt",$Line2) If @error = -1 Then ExitLoop $Split2=StringSplit($Lineread2,",") $Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48) $Worked=StringReplace($Replace,"John Williams",$Split[2],0,1) $File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1) If IsArray($Split2) And $Split2[0] >= 2 Then FileWriteLine($File,$Worked) Until $Lineread2="" When I would do this for example, it doesn't replace John Williams with what I have in my database.txt file I changed up to actually editing the files since there were no array errors this time Edited October 18, 2007 by handro
handro Posted October 18, 2007 Author Posted October 18, 2007 (edited) The only issue I could find is that when i do MsgBox(0,"Worked:",$File) it returns: 1(clicked ok) 2 ( ok) 3 (ok) 4 (ok) It should return the file names ( I created them using a do loop earlier in the program, the first part has no problems making them, just modifying them after theyre made) "image.1" "image.2" My database file contains 4 lines and looks like this: 1, Name, image.jpg 2, Name, image.jpg etc Heres the code again: CODE$Line2=0 Do $Line2+=1 $LineRead2=FileReadLine("Database.txt",$Line2) If @error = -1 Then ExitLoop $Split2=StringSplit($Lineread2,",") $Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48) $Worked=StringReplace($Replace,"John Williams",$Split[2],0,1) $File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1) If IsArray($Split2) And $Split2[0] >= 2 Then FileWriteLine($File,$Worked) Until $Lineread2="" Edited October 18, 2007 by handro
Valuater Posted October 18, 2007 Posted October 18, 2007 Dunno!!! ***** $DirN and $Split are unknown to me $Line2=0 Do $Line2+=1 $LineRead2=FileReadLine("Database.txt",$Line2) If @error = -1 Then ExitLoop $Split2=StringSplit($Lineread2,",") If IsArray($Split2) And $Split2[0] >= 2 Then $Replace=FileReadLine("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",48) ;***** $DirN and $Split are unknown to me $Worked=StringReplace($Replace,"John Williams",$Split[2],0,1) $File=FileOpen("C:\Test\"&$DirN[1]&"."&$Split[1]&"\cap2.htm",1) FileWriteLine($File,$Worked) FileClose($File) EndIf Until $Lineread2="" 8)
handro Posted October 18, 2007 Author Posted October 18, 2007 (edited) ah i see, $DirN=StringSplit($Split[3],".") $Split=StringSplit($Lineread2,",") Those are the strings I forgot to mention, I am sorry Edited October 18, 2007 by handro
handro Posted October 18, 2007 Author Posted October 18, 2007 The file can be read that isn't the problem :S
PsaltyDS Posted October 18, 2007 Posted October 18, 2007 ah i see, $DirN=StringSplit($Split[3],".") $Split=StringSplit($Lineread2,",") Those are the strings I forgot to mention, I am sorry I didn't get that you seemed to get $Split and $Split2 both equal to the same array. So, is this what it's supposed to look like? $Line2 = 0 Do $Line2 += 1 $LineRead2 = FileReadLine("Database.txt", $Line2) If @error = -1 Then ExitLoop $Split = StringSplit($LineRead2, ",") If IsArray($Split) And $Split[0] >= 2 Then $DirN = StringSplit($Split[3], ".") $Replace = FileReadLine("C:\Test\" & $DirN[1] & "." & $Split[1] & "\cap2.htm", 48) $Worked = StringReplace($Replace, "John Williams", $Split[2], 0, 1) $File = FileOpen("C:\Test\" & $DirN[1] & "." & $Split[1] & "\cap2.htm", 1) FileWriteLine($File, $Worked) FileClose($File) EndIf Until $LineRead2 = "" Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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