Solved

search text file

Posted on 2001-06-21
3
121 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

751 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