Solved

find next and select

Posted on 2002-07-06
6
157 Views
Last Modified: 2012-05-04
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
0
Comment
Question by:pantoner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 3

Expert Comment

by:SirNick
ID: 7134153
Hello pantoner

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
0
 

Author Comment

by:pantoner
ID: 7134183
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
0
 
LVL 2

Expert Comment

by:yongyih
ID: 7134345
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. ^_^
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:yongyih
ID: 7134352
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.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7990787
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8053121
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
String manipulation in Visual Basic 7 81
Copy a row 12 69
Getting warning: You are about to delete 1 row(s) 9 53
using web browser with BING 40 135
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question