|
-
Dec 22nd, 2006, 02:07 AM
#1
Thread Starter
Member
[RESOLVED] Syntax checker makes my program run slow, how to make it faster?
I'm using this syntax checker and it works.
But this code will make my program run slowly.
Any suggestion?
(KeywordList and ObjectTagList are array.)
VB Code:
Dim iPos As Integer
'save the current cursor position
iPos = rtfText.SelStart
'prevent the window from changing
LockWindowUpdate rtfText.hwnd
'clear all highlighted
rtfText.SelStart = 0
rtfText.SelLength = Len(rtfText.Text)
rtfText.SelColor = vbBlack
rtfText.SelBold = False
'Search over RTB
For i = 0 To Len(rtfText.Text) - 1
For s = 0 To UBound(KeywordList)
hlstr = KeywordList(s)
res = rtfText.Find(hlstr, i, Len(rtfText.Text), 14)
If res <> -1 Then
rtfText.SelStart = res
rtfText.SelLength = Len(hlstr)
rtfText.SelColor = vbBlue
End If
Next
Next
For i = 0 To Len(rtfText.Text) - 1
For s = 0 To UBound(ObjectTagList)
hlstr = ObjectTagList(s)
res = rtfText.Find(hlstr, i, Len(rtfText.Text), 14)
If res <> -1 Then
rtfText.SelStart = res
rtfText.SelLength = Len(hlstr)
rtfText.SelBold = True
End If
Next
Next
'restore the cursor position
rtfText.SelStart = iPos
'unlock the window
LockWindowUpdate 0
-
Dec 22nd, 2006, 02:15 AM
#2
Re: Syntax checker makes my program run slow, how to make it faster?
One thing...I would store the .SelStart position (iPos) in a Long variable as opposed to integer. It's common for large code to exceed 32KB.
Also, it looks like you're looping through the entire RTB each time.
The trick is to only check the current line that is being edited (or the previous line when Enter is pressed).
You're also looping twice. One to check for keywords, and one to check for tags. You could put that all into one loop.
-
Dec 22nd, 2006, 02:22 AM
#3
Thread Starter
Member
Re: Syntax checker makes my program run slow, how to make it faster?
Can you show me how to check only one line?
I tried to check only one line.But when I paste some paragraphs, it will not check these paragraphs!
-
Dec 24th, 2006, 08:41 AM
#4
Re: Syntax checker makes my program run slow, how to make it faster?
I'm curious, what's the text in the RTB? HTML? And what are the data in KeywordList() and ObjectTagList()?
-
Dec 24th, 2006, 11:27 PM
#5
Re: Syntax checker makes my program run slow, how to make it faster?
Please mark you thread resolved using the Thread Tools as shown
-
Dec 25th, 2006, 02:56 AM
#6
Thread Starter
Member
Re: Syntax checker makes my program run slow, how to make it faster?
My problem is the program will run slow when the text in the textbox is more than 10 line.
The KeywordList() and ObjectTagList() is two array.
I've made a code to search for keyword list over two file:
keywords.dat and objects.dat
Both are keywords list file and this is not my problem.
Also, how to multiple undo/redo for my rtf textbox?
-
Dec 25th, 2006, 03:32 AM
#7
Re: Syntax checker makes my program run slow, how to make it faster?
See this link for multiple redo and undo
Please mark you thread resolved using the Thread Tools as shown
-
Dec 25th, 2006, 04:52 AM
#8
Re: Syntax checker makes my program run slow, how to make it faster?
This will speed up the program
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_GETTEXTLENGTH As Long = &HE
Private Function Getlength(rich As RichTextBox) As Long
'Function To get the length of the text box
Getlength = SendMessage(rich.hwnd, WM_GETTEXTLENGTH, 0&, 0&)
End Function
Dim iPos As Integer
'save the current cursor position
iPos = rtfText.SelStart
'prevent the window from changing
LockWindowUpdate rtfText.hwnd
'clear all highlighted
rtfText.SelStart = 0
rtfText.SelLength = Getlength(rtfText)
rtfText.SelColor = vbBlack
rtfText.SelBold = False
'Search over RTB
For i = 0 To Len(rtfText.Text) - 1
For s = 0 To UBound(KeywordList)
hlstr = KeywordList(s)
res = rtfText.Find(hlstr, i, Getlength(rtfText), 14)
If res <> -1 Then
rtfText.SelStart = res
rtfText.SelLength = Len(hlstr)
rtfText.SelColor = vbBlue
End If
Next
Next
For i = 0 To Len(rtfText.Text) - 1
For s = 0 To UBound(ObjectTagList)
hlstr = ObjectTagList(s)
res = rtfText.Find(hlstr, i, Getlength(rtfText), 14)
If res <> -1 Then
rtfText.SelStart = res
rtfText.SelLength = Len(hlstr)
rtfText.SelBold = True
End If
Next
Next
'restore the cursor position
rtfText.SelStart = iPos
'unlock the window
LockWindowUpdate 0
Please mark you thread resolved using the Thread Tools as shown
-
Dec 25th, 2006, 05:02 AM
#9
Thread Starter
Member
Re: Syntax checker makes my program run slow, how to make it faster?
danasegarane, this code is still slowing my programs!
-
Dec 25th, 2006, 05:09 AM
#10
Thread Starter
Member
Re: Syntax checker makes my program run slow, how to make it faster?
 Originally Posted by ZenDisaster
VB Code:
RTF1.Visible = False
For iKey = 0 To UBound(KeyWordList)
TryAgain:
lFound = RTF1.Find(KeyWordList(iKey), lFound, , 14)
If lFound <> -1 Then
RTF1.SelStart = lFound
RTF1.SelLength = Len(KeyWordList(iKey))
RTF1.SelColor = vbBlue
lFound = lFound + Len(KeyWordList(iKey)) + 1
GoTo TryAgain
End If
lFound = 0
Next iKey
RTF1.Visible = True
Down from over 2 minutes to 0.140999999999622 seconds to complete.
My first line is missing, why??
-
Dec 25th, 2006, 06:30 AM
#11
Re: Syntax checker makes my program run slow, how to make it faster?
Have you found ,why is your program is slow down.As for as I can tell one thing.If you read the length of line which is more , then it will slow.For Getting the length
you have to use this function
VB Code:
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_GETTEXTLENGTH As Long = &HE
Private Function Getlength(rich As RichTextBox) As Long
'Function To get the length of the text box
Getlength = SendMessage(rich.hwnd, WM_GETTEXTLENGTH, 0&, 0&)
End Function
Please mark you thread resolved using the Thread Tools as shown
-
Dec 25th, 2006, 06:38 PM
#12
Re: Syntax checker makes my program run slow, how to make it faster?
One of the best speed ups you can make is to stop working dierctly on the richtextbox control itself.
That is very slow.
Store it in a String instead then work with the string to find the keywords and their positions.
Then go back and make the changes.
You can make it even faster by making the changes to a string variable then putting it back into the richtextbox as TextRTF.
But to do that you have to parse the documents color table and add the color tags yourself.
It's a little like learning to write HTML.
There's a good example of it at planet source code by a guy called Bobo(?)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|