Use color in Rich text

Source: Internet
Author: User
Tags exit chr comments mail sin

ADD VB code in a rich text control call Initcolorize call
Colorizewords (Rtfvbcode)
Now your VB code in your Rich text control is colorized
Source Code:
#VBIDEUtils #************************************************************
*programmer Name:waty Thierry
* Web site:www.geocities.com/researchtriangle/6311/
* E-mail:waty.thierry@usa.net
* DATE:30/10/98
* time:14:47
* Module Name:colorize_module
* Module Filename:Colorize.bas
**********************************************************************
*comments:colorize in black, blue, green the VB keywords
*
*
**********************************************************************
Option Explicit
Private Gsblackkeywords as String
Private Gsbluekeywords as String
Public Sub colorizewords (RTF as RichTextBox)
#VBIDEUtils #************************************************************
* Programmer Name:waty Thierry
* Web site:www.geocities.com/researchtriangle/6311/
* E-mail:waty.thierry@usa.net
* DATE:30/10/98
* time:14:47
* Module Name:colorize_module
* Module Filename:Colorize.bas
* Procedure Name:colorizewords
* Parameters:
* RTF as RichTextBox
**********************************************************************
* Comments:colorize in black, blue, green the VB keywords
*
*
**********************************************************************
Dim Sbuffer as String
Dim NI as Long
Dim NJ as Long
Dim Stmpword as String
Dim Nstartpos as Long
Dim Nsellen as Long
Dim Nwordpos As Long Dim chourglass As Class_hourglass
Set Chourglass = New class_hourglas br> sbuffer = rtf. Text Stmpword = "" With RTF
For NI = 1 to Len (sbuffer)
Select Case Mid (Sbuffer, NI, 1)
Case ' A ' to ' Z ', ' a ' to ' Z ', ' _ '
If Stmpword = "" Then Nstartpos = NI
Stmpword = Stmpword & Mid (Sbuffer, NI, 1)
Case CHR (34)
Nsellen = 1
For NJ = 1 to 9999999
If Mid (Sbuffer, ni + 1, 1) = Chr Then ni = ni + 2
Exit for
Else
Nsellen = Nsellen + 1
Ni = ni + 1
End If
Next
Case CHR (39).
SelStart = nI-1
Nsellen = 0
For NJ = 1 to 9999999
If Mid (Sbuffer, NI, 2) = VbCrLf Then
Exit for
Else
Nsellen = Nsellen + 1
Ni = ni + 1
End If
Next
. SelLength = Nsellen
. Selcolor = RGB (0, 127, 0)
Case Else
If Not (Len (Stmpword) = 0) Then
. SelStart = nStartPos-1
. SelLength = Len (Stmpword)
Nwordpos = INSTR (1, Gsblackkeywords, "*" & Stmpword & "*", 1)
If nwordpos <> 0 Then
. Selcolor = RGB (0, 0, 0)
. SelText = Mid (gsblackkeywords, Nwordpos + 1, Len (Stmpword))
End If
Nwordpos = INSTR (1, Gsbluekeywords, "*" & Stmpword & "*", 1)
If nwordpos <> 0 Then
. Selcolor = RGB (0, 0, 127)
. SelText = Mid (gsbluekeywords, Nwordpos + 1, Len (Stmpword))
End If
If UCase (Stmpword) = "REM" Then
. SelStart = nI-4
. SelLength = 3
For NJ = 1 to 9999999
If Mid (Sbuffer, NI, 2) = VbCrLf Then
Exit for
Else
. SelLength =. SelLength + 1
Ni = ni + 1
End If
Next
. Selcolor = RGB (0, 127, 0)
. SelText = LCase (. SelText)
End If End If
Stmpword = ""
End Select
Next
. SelStart = 0
End With
End Sub
Public Sub initcolorize ()
#VBIDEUtils #************************************************************
* Programmer Name:waty Thierry
* Web site:www.geocities.com/researchtriangle/6311/
* E-mail:waty.thierry@usa.net
* DATE:30/10/98
* time:14:47
* Module Name:colorize_module
* Module Filename:Colorize.bas
* Procedure Name:initcolorize
* Parameters:
**********************************************************************
* Comments:initialize the VB keywords
*
*
**********************************************************************
Gsblackkeywords = "*abs*add*additem*appactivate*array*asc*atn*"
Gsblackkeywords =gsblackkeywords+ "beep*begin*beginproperty*"
Gsblackkeywords =gsblackkeywords+ "chdir*chdrive*choose*"
Gsblackkeywords =gsblackkeywords+ "chr*clear*collection*command*cos*createobject*"
Gsblackkeywords =gsblackkeywords+ "curdir*dateadd*datediff*datepart*dateserial*datevalue*"
Gsblackkeywords =gsblackkeywords+ "Day*ddb*deletesetting*dir*doevents"
Gsblackkeywords =gsblackkeywords+ "*endproperty*environ*eof*err*"
Gsblackkeywords =gsblackkeywords+ "EXP*FILEATTR*FILECOPY*FILEDATETIME*FILELEN*FIX*FORMAT*FV
Gsblackkeywords =gsblackkeywords+ "*getallsettings*" getattr*getobject*getsetting*hex*hide*hour* "
Gsblackkeywords =gsblackkeywords+ "Inputbox*instr*int*int*ipmt*irr*isarray"
Gsblackkeywords =gsblackkeywords+ "*isdate*isempty*iserror*"
Gsblackkeywords =gsblackkeywords+ "Ismissing*isnull*isnumeric*isobject*item*kill"
Gsblackkeywords =gsblackkeywords+ "*lcase*left*len*load*"
Gsblackkeywords =gsblackkeywords+ "loc*lof*log*ltrim*me*mid*minute*"
Gsblackkeywords =gsblackkeywords+ "mirr*mkdir*month*now*nper*npv*oct*"
Gsblackkeywords =gsblackkeywords+ "Pmt*ppmt*pv*qbcolor*raise*randomize"
Gsblackkeywords =gsblackkeywords+ "*rate*remove*removeitem*reset*rgb*"
Gsblackkeywords =gsblackkeywords+ "Right*rmdir*rnd*rtrim*savesetting"
Gsblackkeywords =gsblackkeywords+ "*second*sendkeys*setattr*sgn*shell*"
Gsblackkeywords =gsblackkeywords+ "Sin*sin*sln*space*sqr*str*strcomp"
Gsblackkeywords =gsblackkeywords+ "*strconv*switch*syd*tan*text*time*time*"
Gsblackkeywords =gsblackkeywords+ "Timer*timeserial*timevalue*trim*typename"
Gsblackkeywords =gsblackkeywords+ "*ucase*unload*val*vartype*weekday*"
Gsblackkeywords =gsblackkeywords+ "width*year*"
Gsbluekeywords = "* #Const * #Else * #ElseIf * #End"
Gsbluekeywords = gsbluekeywords+ "if* #If *alias*alias*and*as*base"
Gsbluekeywords = gsbluekeywords+ "*binary*boolean*byte*b"
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.