Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Filter a textfile

I'm rather new to vb6 and experience some problems on how to filter a textfile.
I have a text file wich I want to import in acces through vb.
This is not a problem, but before I want to import the text file I need to filter the text file.
What I want is to replace the fields containing a value of "120" with "E13" and replace the fields containing "sp001" with " " (nothing, just delete the value)
The textfile is comma seperated...

Thanks in advance

Best regards,
Boomer

0
boomer001
Asked:
boomer001
  • 2
1 Solution
 
aelatikCommented:
Const SOURCE As String = "c:\file1.txt"
Const TARGET As String = "c:\file2.txt"

Open SOURCE For Input As #1
    Open TARGET For Output As #2
    While Not EOF(1)
        Line Input #1, MyLine
        Print #2, Replace(Replace(MyLine, "120", "E13"), "sp001", "")
    Wend
    Close #2
Close #1
0
 
dbrckoviCommented:
Try this:

---------------------------------------------------------------------------
Function FileFilter(ByVal FileName As String) As Boolean
    On Error Resume Next
    Dim FileLine() As String
   
    ReDim FileLine(0 To 0)
    Open FileName For Input As #1
        Do
            ReDim Preserve FileLine(0 To UBound(FileLine) + 1)
            Line Input #1, FileLine(UBound(FileLine))
        Loop Until EOF(1)
    Close #1
    'file is now saved in line array
   
    For X = 1 To UBound(FileLine)
        FileLine(X) = Replace(FileLine(X), "120", "E13")
        FileLine(X) = Replace(FileLine(X), "sp001", " ")
    Next X
   
    Open FileName For Output As #1
        For X = 1 To UBound(FileLine)
            Print #1, FileLine(X)
        Next X
    Close #1
   
    If Err = 0 Then         'return False if error occures
        FileFilter = True
    Else
        FileFilter = False
    End If

End Function
----------------------------------------------------------------------
To use you can type:  
     MsgBox  FileFilter ("e:\test\aa.txt")

If it was fully succesfull, it will return True, otherwise it will return False
0
 
dbrckoviCommented:
Thanks!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now