You are here: PSPad forum > English discussion forum > How to use aAutoRefresh
Posted by: Cricri | Date: 2015-05-17 12:09 | IP: IP Logged
Hello,
Can anyone explain how to use aAutoRefresh? The documentation is lacking and doesn't help.
Is it similar to the VBA instruction "Application.ScreenUpdating" in Excel? I'm trying to speed up my code by disabling screen refresh until the code has finished.
Thanks!
Posted by: pspad | Date: 2015-05-17 14:10 | IP: IP Logged
Autorefresh switches on/off automatical editor refresh in specific interval - e.g. if you open any log and you want to see how it changes without pressing Ctrl+R
There is nothing like BeginUpdate and EndUpdate available in scripting.
What exactly do you want to do?
Posted by: Cricri | Date: 2015-05-17 18:43 | IP: IP Logged
Thanks.
I wrote some scripts that manipulate text files. I've typically got 1000s of lines in this text file, and the script can take several minutes to complete.
I know that in Excel, disabling screen update while running the code (and reacivating it once the code has finished) significantly boost the speed. So I was wondering if aAutoRefresh is an equivalent in PSPad, or if not, if there was an equivalent.
Posted by: pspad | Date: 2015-05-17 19:28 | IP: IP Logged
I understand.
The best method is load content of the file into memory, manipulate it as you need and replace whole text back. If possible.
Each manipulation in PSPad causes writing into undo/redo buffers e.t.c.
Posted by: Cricri | Date: 2015-05-17 19:40 | IP: IP Logged
Thanks again Jan!
I did that when I could already, and it does help. I was wondering if there was any other tricks such as the screen refresh one.
That's fine, I still can wait few minutes for my code to run
Posted by: pspad | Date: 2015-05-17 20:13 | IP: IP Logged
Few minutes?
Can you tell me what do you do in your code? Maybe there can be better solution or algorithm to speed up your task.
Posted by: Cricri | Date: 2015-05-17 20:37 | IP: IP Logged
Well today I ran the code against 900 lines, and for each lines, it looks for a keyword match in another file of 20000 lines!
So to speed it up, I first load the 20000 "keywords" into an array (which strangely takes a lot of time on its own, maybe close to 1 minute):
Dim KeywordsCount
KeywordsCount = KeywordsDoc.linesCount
Dim KeywordsList()
redim KeywordsList(KeywordsCount)
For j = 1 To KeywordsCount
KeywordsDoc.caretY(j)
KeywordsList(j-1) = KeywordsDoc.lineText
Next
You're right that there might be a better way to do it!
Then I check each line of my document against this list. If it finds it contains one of the keywords, it deletes the line.
For i = 1 To ProcessDoc.linesCount
ProcessDoc.caretY(i)
ProcessString = ProcessDoc.lineText
IsOK = False
For j = 1 To KeywordsCount
If InStr(ProcessString, KeywordsList(j-1)) > 0 Then
IsOK = True
Exit For
End If
Next
If Not IsOK Then ProcessDoc.lineText(vbNullString)
Next
Since I only read each line once in this second section, I couldn't see a benefit into loading the contents into memory.
Edited 1 time(s). Last edit at 2015-05-17 20:39 by Cricri.
Posted by: pspad | Date: 2015-05-17 20:50 | IP: IP Logged
In case you read lines you are right, it has no sense.
You can speed up your code a little. Instead of the moving caret and read current string, you can use construction from .\Script\Readme.rtf:
Quote:' here is presented access to editor lines line by line
dim item
for each item in obj1
MsgBox item
next
Posted by: Cricri | Date: 2015-05-17 21:01 | IP: IP Logged
Awesome, I'll try that when I get a chance.
Thanks for the tip!
Posted by: Cricri | Date: 2015-05-17 21:35 | IP: IP Logged
Works great!
Dim item
Dim arr1()
ReDim arr1(0)
For Each item In MyDoc
arr1(UBound(arr1)) = item
ReDim Preserve arr1(UBound(arr1) + 1)
Next
Time for 20000 rows: pretty much instantaneous
Dim KeywordsCount
KeywordsCount = MyDoc.linesCount
Dim arr2()
redim arr2(KeywordsCount)
Dim i
For i = 1 To KeywordsCount
MyDoc.caretY(i)
arr2(i-1) = MyDoc.lineText
Next
Time for the same 20000 rows: more than 2 minutes!
Great tip, thanks again Jan!
Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR