Solved

Filter a textfile

Posted on 2004-04-07
3
305 Views
Last Modified: 2010-05-02
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
Comment
Question by:boomer001
[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 14

Expert Comment

by:aelatik
ID: 10773913
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
 
LVL 11

Accepted Solution

by:
dbrckovi earned 50 total points
ID: 10773927
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
 
LVL 11

Expert Comment

by:dbrckovi
ID: 10778548
Thanks!
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
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…
Suggested Courses
Course of the Month11 days, 8 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