pantoner
asked on
find next and select
I am using a macro program which accommodates snippets of code. In order to speed up my process I need the code which does exactly what "Find" does in Notepad.
Searching from the cursor location. I would like to hard code the word to search for and the direction 'up or down' and leave the found word selected in notepad.
Thanks
Searching from the cursor location. I would like to hard code the word to search for and the direction 'up or down' and leave the found word selected in notepad.
Thanks
ASKER
This is what I have so far. But instead of the code giving a msg box that says "found" I need it to select the word. Also I need to be able to search for the word up or down from where the cursor is currently located in the document.
Sub Main
Dim strTemp As String
Dim txtFind As String
txtFind = "function" 'word to find
FileName = "c:\test.txt"
If Dir(FileName) <> "" Then
Open FileName For Input As 1
While Not EOF(1)
Line Input #1, strTemp
txtFile = txtFile & strTemp & vbCrLf
Wend
If InStr(txtFile, txtFind) <> 0 Then
MsgBox "found"
'code to do what you want if text found
Else
MsgBox "Not found"
'code to do what you want if text not found
End If
Close #1
Else
MsgBox "File not found" 'if the text file is not found
End If
End Sub
Sub Main
Dim strTemp As String
Dim txtFind As String
txtFind = "function" 'word to find
FileName = "c:\test.txt"
If Dir(FileName) <> "" Then
Open FileName For Input As 1
While Not EOF(1)
Line Input #1, strTemp
txtFile = txtFile & strTemp & vbCrLf
Wend
If InStr(txtFile, txtFind) <> 0 Then
MsgBox "found"
'code to do what you want if text found
Else
MsgBox "Not found"
'code to do what you want if text not found
End If
Close #1
Else
MsgBox "File not found" 'if the text file is not found
End If
End Sub
May be you can use line number in VB.
line is a Read-only property that returns the current line number in a TextStream file.
Syntax
object.Line
The object is always the name of a TextStream object.
Remarks
After a file is initially opened and before anything is written, Line is equal to 1.
To search up or down, may be u just increase or decrease the line number..
hope this can help, good luck. ^_^
line is a Read-only property that returns the current line number in a TextStream file.
Syntax
object.Line
The object is always the name of a TextStream object.
Remarks
After a file is initially opened and before anything is written, Line is equal to 1.
To search up or down, may be u just increase or decrease the line number..
hope this can help, good luck. ^_^
sorry, the property is read only, i think you cannot set the line value directly.
but you can store the line value for later use.
but you can store the line value for later use.
Hi pantoner,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Refund points and save as a 0-pt PAQ.
pantoner, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit. Explain why.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:
Refund points and save as a 0-pt PAQ.
pantoner, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit. Explain why.
==========
DanRollins -- EE database cleanup volunteer
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The following links should point you in the right direction.
Find string in text file
http://www.freevbcode.com/ShowCode.Asp?ID=2740
Read a text file into a Rich text box and find string
http://www.freevbcode.com/ShowCode.Asp?ID=2524
Find/Replace dialog box demo
http://www.freevbcode.com/ShowCode.Asp?ID=3304
If the above doesn't help then do a search at:
http://www.planetsourcecode.com