Dim TempFile As Long Dim LoadBytes() As Byte Dim LoadStr As StringTempFile=FreeFile Open 文件名 For Binary As #TempFile Redim LoadBytes(1 To Lof(TempFile)) As Byte Get #TempFile,,LoadBytes Close TempFileLoadStr=StrConv(LoadBytes,vbUniCode)位置=LenB(StrConv(Left$(InStr(LoadStr, 查找字符串)), vbFromUniCode))
用RichTextBox 首先进行文本文件的调入:Private Sub Command1_Click() On Error GoTo woops Dim sfile As String With CommonDialog1 .Flags = cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNFileMustExist + cdlOFNHideReadOnly .DialogTitle = "Open File" .CancelError = True 'if the user cancels sends us to woops .Filter = "Text files (*.txt)¦*.txt¦All files¦*.*" .ShowOpen If Len(.FileName) = 0 Then Exit Sub sfile = .FileName End With RTB.LoadFile sfile CurrentFile = sfile 'used by the mod to save changes made woops: Exit Sub End Sub然后再进行数据发现:Function FindIt(RTF As RichTextBox, txt As String) As Integer RTF.Refresh 'RTF.Find (Txt,0) textfound = RTF.Find(txt, 0) If textfound <> -1 Then FoundIt = True 'lets the form know we found it 'RTF.SetFocus 'OK we've found it so select it to show the user FindIt = RTF.SelStart Exit Function 'lets' get out of here Else FoundIt = False 'lets the form know we cant find it Exit Function End If End Function第二次发现的子程序 Function FinditNext(RTF As RichTextBox, txt As String) As Integer 'the text has already been found once. We want the next occurrence
textfound = RTF.Find(txt, RTF.SelStart + Len(txt)) If textfound <> -1 Then 'Found it ! FoundIt = True 'let the form know we succeeded 'RTF.SetFocus 'show it to the user FinditNext = RTF.SelStart Exit Function 'lets bail out now Else FoundIt = False 'let the form know we cant find it Exit Function 'lets bail out now End IfEnd Function以上代码不是我写的,是我从一个地方copy的,所以没有经过我的测试,如果你要全部内容(包括一部分调用)可以参考 http://www.csdn.net/expert/topic/497/497654.shtm 那个主题不是查找,但是利用了这个功能,程序就是出自那里的!!
Dim LoadBytes() As Byte
Dim LoadStr As StringTempFile=FreeFile
Open 文件名 For Binary As #TempFile
Redim LoadBytes(1 To Lof(TempFile)) As Byte
Get #TempFile,,LoadBytes
Close TempFileLoadStr=StrConv(LoadBytes,vbUniCode)位置=LenB(StrConv(Left$(InStr(LoadStr, 查找字符串)), vbFromUniCode))
首先进行文本文件的调入:Private Sub Command1_Click()
On Error GoTo woops
Dim sfile As String
With CommonDialog1
.Flags = cdlOFNAllowMultiselect + cdlOFNExplorer + cdlOFNFileMustExist + cdlOFNHideReadOnly
.DialogTitle = "Open File"
.CancelError = True 'if the user cancels sends us to woops
.Filter = "Text files (*.txt)¦*.txt¦All files¦*.*"
.ShowOpen
If Len(.FileName) = 0 Then Exit Sub
sfile = .FileName
End With
RTB.LoadFile sfile
CurrentFile = sfile 'used by the mod to save changes made
woops: Exit Sub
End Sub然后再进行数据发现:Function FindIt(RTF As RichTextBox, txt As String) As Integer
RTF.Refresh
'RTF.Find (Txt,0)
textfound = RTF.Find(txt, 0)
If textfound <> -1 Then
FoundIt = True 'lets the form know we found it
'RTF.SetFocus 'OK we've found it so select it to show the user
FindIt = RTF.SelStart
Exit Function 'lets' get out of here
Else
FoundIt = False 'lets the form know we cant find it
Exit Function
End If
End Function第二次发现的子程序
Function FinditNext(RTF As RichTextBox, txt As String) As Integer
'the text has already been found once. We want the next occurrence
textfound = RTF.Find(txt, RTF.SelStart + Len(txt))
If textfound <> -1 Then 'Found it !
FoundIt = True 'let the form know we succeeded
'RTF.SetFocus 'show it to the user
FinditNext = RTF.SelStart
Exit Function 'lets bail out now
Else
FoundIt = False 'let the form know we cant find it
Exit Function 'lets bail out now
End IfEnd Function以上代码不是我写的,是我从一个地方copy的,所以没有经过我的测试,如果你要全部内容(包括一部分调用)可以参考
http://www.csdn.net/expert/topic/497/497654.shtm
那个主题不是查找,但是利用了这个功能,程序就是出自那里的!!