|
-
Nov 15th, 2005, 03:41 PM
#1
[RESOLVED] improve my code
Hello
Ive only been learning VB for a half year now so my knowledge is very ...basic ..., and I wrote this code to color all html tags (all words within < and >) within a rich text box in red...but I know its quite bad and I knew it wouldnt work when having ALOT of code...so can some of you pro's please improve it? 
Thanks
VB Code:
Dim start_p As Long
Dim end_p As Long
For a = 1 To Len(RT.Text)
If Mid(RT.Text, a, 1) = "<" Then
start_p = a
End If
If Mid(RT.Text, a, 1) = ">" Then
end_p = a
RT.SelStart = start_p - 1
RT.SelLength = (end_p - start_p)
RT.SelColor = RGB(255, 0, 0)
End If
Next a
Last edited by Atheist; Nov 15th, 2005 at 05:18 PM.
-
Nov 15th, 2005, 04:03 PM
#2
Re: improve my code
its a bit faster using FIND (Built into rtb).. but also.. using the LockWindowUpdate API
will keep it from flickering or scrolling like crazy
VB Code:
Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As Long
Private Sub Command1_Click()
LockWindowUpdate RTB1.hWnd
Dim Loc As Long
Loc = 0
Loc = RTB1.Find("<", Loc) + 1
Do
RTB1.SelStart = Loc
RTB1.SelLength = InStr(Loc, RTB1.Text, ">") - Loc - 1
RTB1.SelColor = vbRed
Loc = RTB1.Find("<", Loc) + 1
Loop While Loc > 0
RTB1.SelStart = 0
LockWindowUpdate 0&
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 15th, 2005, 04:10 PM
#3
Hyperactive Member
Re: improve my code
make a bool called "DoRed"
Then in your keypress event for your rich text box do this;
VB Code:
Private Sub RT_KeyPress(KeyAscii As Integer)
If Chr(KeyAscii) = "<" Then DoRed = True
If DoRed Then
RT.SelColor = RGB(255, 0, 0)
Else
RT.SelColor = RGB(0, 0, 0)
End If
If Chr(KeyAscii) = ">" Then DoRed = False
End Sub
-
Nov 15th, 2005, 04:14 PM
#4
Re: improve my code
Thanks static, works like a charm..expect the LockWindowUpdate API...it says "object required" each time i try to run...any idea why?
-
Nov 15th, 2005, 04:16 PM
#5
Re: improve my code
Moved to code it better...
-
Nov 30th, 2005, 04:01 PM
#6
Re: improve my code
 Originally Posted by Atheist
Thanks static, works like a charm..expect the LockWindowUpdate API...it says "object required" each time i try to run...any idea why?
Did you change this line "RTB1.hWnd" to the name of your rich text box? Maybe you forgot to add the .hWnd after?
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
|