帮你研究出来了
建个access数据库来存你要的关键字
结构为:
字段名 Keys
表名 dictionary
数据库 table
原理是:
接收到richtextbox改变的时候把改变值进行数据查找,找到就用颜色标出来,代码中我用的是红色,高光你自己设置
先引用
Microsoft ActiveX Data Objects 2.1 Library
代码为:
Dim Cnn As ADODB.Connection
Dim dataset As Recordset
Private Sub RichTextBox1_Change()
Dim strsql As String
Static have As Integer
If have > 0 Then
strsql = Right(RichTextBox1.Text, have + 1)
Set dataset = Cnn.Execute("select * from dictionary where keys like '%" & strsql & "%'")
If Not dataset.EOF Then
have = have + 1
Else
have = 0
Exit Sub
End If
If dataset.Fields(0) = strsql Then '找到了
RichTextBox1.Find strsql
RichTextBox1.SelColor = &HFF&
RichTextBox1.SelStart = Len(RichTextBox1.Text)
RichTextBox1.SelColor = vbBlack
have = 0
End If
Else
strsql = Right(RichTextBox1.Text, 1)
Set dataset = Cnn.Execute("select * from dictionary where keys like '%" & strsql & "%'")
If Not dataset.EOF Then
have = have + 1
Else
have = 0
End If
End If
Set dataset = Nothing
End Sub
Sub ConDatabase(ByVal DataPath As String) '连接Access数据库
Dim strsql As String
Set Cnn = New ADODB.Connection
If Cnn.State = adStateOpen Then Cnn.Close
strsql = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & DataPath & ";Persist Security Info=False"
Cnn.ConnectionString = strsql
Cnn.CursorLocation = adUseClient
Cnn.CommandTimeout = 60
Cnn.Open
End Sub
Private Sub Form_Load()
Call ConDatabase(App.Path & "\table.mdb")
End Sub
如果还不清楚就发消息给我,把e-mail给我,我把代码寄给你