Solved

search text file

Posted on 2001-06-21
3
122 Views
Last Modified: 2010-05-02
I'm looking for a simple way to open a text file and search for any 8 characters and ".exe"

Then it should display whatever the 8 characters are.



0
Comment
Question by:jlymn
[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
  • 2
3 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6214656
Option Explicit

Private Sub Form_Load()
Dim lin As Long, col As Long

If CheckFile("c:\test\test.txt", "andy", lin, col) Then
    Debug.Print "line = ", lin, "col = ", col
End If


End Sub


Public Function CheckFile(sFilePath As String, ByVal sSearch As String, lin As Long, col As Long) As Boolean

    Dim i As Long, sline
    i = FreeFile
    lin = 0
   
    sSearch = sSearch & ".exe"
    Open sFilePath For Input As i
    While Not EOF(i)
        Line Input #i, sline
        lin = lin + 1
        If InStr(sline, sSearch) Then
            col = InStr(sline, sSearch)
            Close i
            CheckFile = True
            Exit Function
        End If
    Wend
   
    Close i
   


End Function
0
 
LVL 3

Expert Comment

by:cmgarnett
ID: 6214683
Sub OpenTextFileTest
    Const ForReading = 1
    Dim fs, f
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.OpenTextFile("c:\testfile.txt", ForReading,TristateFalse)
    strWork = f.ReadAll
    f.Close

    intStart = InStr(strWork,".exe")
    strName = Mid$(strWork, intStart - 8,8)
End Sub

Hope this starts you off.
0
 
LVL 18

Accepted Solution

by:
deighton earned 50 total points
ID: 6214688
Sorry, I think this is what you meant

Option Explicit

Private Sub Form_Load()
Dim lin As Long, col As Long, sdata As String

If CheckFile("c:\test\test.txt", ".exe", lin, col, sdata) Then
    Debug.Print sdata
End If


End Sub


Public Function CheckFile(sFilePath As String, ByVal sSearch As String, lin As Long, col As Long, sdata As String) As Boolean

    Dim i As Long, sline
    i = FreeFile
    lin = 0
   
   
    Open sFilePath For Input As i
    While Not EOF(i)
        Line Input #i, sline
        lin = lin + 1
        If InStr(sline, sSearch) > 8 Then
            col = InStr(sline, sSearch)
            sdata = Mid(sline, col - 8, 8)
            Close i
            CheckFile = True
            Exit Function
        End If
    Wend
   
    Close i
   


End Function
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 19 hours left to enroll

623 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