Sebiix3 Posted April 26, 2018 Share Posted April 26, 2018 Hey guys! First of all, i wanna say "Hi" to all of you I am not actually new, but i just didn't register on this forum yet because i never had to post something(most of my problems was already asked and solved by other users :3). Lets come to my problem, My script does the following: expandcollapse popup$ToLine123 = _IEDocReadHTML ($oIE) _IELoadWait($oIE) FileDelete("ToLine123.txt") FileWrite("ToLine123.txt",$ToLine123) _FileWriteToLine("ToLine123.txt",704,'',1) _FileWriteToLine("ToLine123.txt",705,'',1) _FileWriteToLine("ToLine123.txt",706,'',1) _FileWriteToLine("ToLine123.txt",707,'',1) _FileWriteToLine("ToLine123.txt",708,'',1) _FileWriteToLine("ToLine123.txt",709,'',1) _FileWriteToLine("ToLine123.txt",710,'',1) _FileWriteToLine("ToLine123.txt",711,'',1) _FileWriteToLine("ToLine123.txt",712,'',1) _FileWriteToLine("ToLine123.txt",713,'',1) _FileWriteToLine("ToLine123.txt",714,'',1) _FileWriteToLine("ToLine123.txt",715,'',1) _FileWriteToLine("ToLine123.txt",716,'',1) _FileWriteToLine("ToLine123.txt",717,'',1) _FileWriteToLine("ToLine123.txt",718,'',1) _FileWriteToLine("ToLine123.txt",719,'',1) _FileWriteToLine("ToLine123.txt",720,'',1) _FileWriteToLine("ToLine123.txt",721,'',1) _FileWriteToLine("ToLine123.txt",722,'',1) _FileWriteToLine("ToLine123.txt",723,'',1) _FileWriteToLine("ToLine123.txt",724,'',1) _FileWriteToLine("ToLine123.txt",725,'',1) _FileWriteToLine("ToLine123.txt",726,'',1) _FileWriteToLine("ToLine123.txt",727,'',1) _FileWriteToLine("ToLine123.txt",728,'',1) _FileWriteToLine("ToLine123.txt",729,'',1) _FileWriteToLine("ToLine123.txt",730,'',1) _FileWriteToLine("ToLine123.txt",731,'',1) _FileWriteToLine("ToLine123.txt",732,'',1) _FileWriteToLine("ToLine123.txt",733,'',1) _FileWriteToLine("ToLine123.txt",734,'',1) _FileWriteToLine("ToLine123.txt",735,'',1) _FileWriteToLine("ToLine123.txt",736,'',1) _FileWriteToLine("ToLine123.txt",737,'',1) _FileWriteToLine("ToLine123.txt",738,'',1) _FileWriteToLine("ToLine123.txt",739,'',1) $ReadToLine123 = FileRead("ToLine123.txt") _IEDocWriteHTML($oIE, $ReadToLine123);Uploaden Its works quite fine, but it takes ALOT of time to replace all the lines. Is there any way to make it faster or even an alternative for this? I would be happy for any help! Link to comment Share on other sites More sharing options...
BrewManNH Posted April 26, 2018 Share Posted April 26, 2018 Why not put all the text into an array, then use _FileWriteFromArray? You can declare your array sized to how ever many lines you're going to need, and then just set the elements with the values you're using. Sebiix3 1 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
therks Posted April 27, 2018 Share Posted April 27, 2018 In your case, your best bet would be to avoid the _FileWriteToLine function. Every time you call that function it re-reads the entire file to an array, replaces one line, then rewrites the file. Also, if you're just filling multiple consecutive lines with blanks you could use a for-loop. I would suggest this: Read the file with FileReadToArray. For loop 704 to 739, replacing array items with blanks. Write the array to file using _FileWriteFromArray (as BrewMan suggested). Something like the following: $aFileLines = FileReadToArray('ToLine123.txt') For $i = 704 To 739 $aFileLines[$i] = '' Next _FileWriteFromArray('ToLine123.txt', $aFileLines) That's untested, and you would want to add error checking, but it should give you an idea where to start. Sebiix3 1 My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Zedna Posted April 27, 2018 Share Posted April 27, 2018 (edited) This should be very fast version doing the same: $sFileText = FileRead('ToLine123.txt') $iStart = StringInStr($sFileText,@CRLF,1,704) $iEnd = StringInStr($sFileText,@CRLF,1,739) If $iStart > 0 And $iEnd > 0 Then $sFileLines1 = StringLeft($sFileText, $iStart-1) $sFileLines2 = '' For $i = 1 To 36 ; 739-704+1 $sFileLines2 &= @CRLF Next $sFileLines3 = StringMid($sFileText, $iEnd+1) FileDelete('ToLine123.txt') FileWrite('ToLine123.txt', $sFileLines1 & $sFileLines2 & $sFileLines3) EndIf EDIT: And this should be even faster $sFileText = FileRead('ToLine123.txt') $iStart = StringInStr($sFileText,@CRLF,1,704) ;~ $iEnd = StringInStr($sFileText,@CRLF,1,739) If $iStart > 0 Then $iEnd = StringInStr($sFileText,@CRLF,1,35,$iStart+1) ; 35=739-704 If $iEnd > 0 Then $sFileLines1 = StringLeft($sFileText, $iStart-1) $sFileLines2 = '' For $i = 1 To 36 ; 739-704+1 $sFileLines2 &= @CRLF Next $sFileLines3 = StringMid($sFileText, $iEnd+1) FileDelete('ToLine123.txt') FileWrite('ToLine123.txt', $sFileLines1 & $sFileLines2 & $sFileLines3) EndIf EndIf Edited April 27, 2018 by Zedna aa2zz6 and Sebiix3 1 1 Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Sebiix3 Posted April 27, 2018 Author Share Posted April 27, 2018 Thanks guys! You helped me alot, much appreciated! @Zedna's way seems to be the fastest in this case. I also realized that some other parts of my script could be much better using _FileWriteFromArray. Thanks! 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