Results 1 to 4 of 4

Thread: Extracting from then to writing .txt

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    17

    Extracting from then to writing .txt

    Hi,

    I aim to do this in an Access 97 form as I dont have access to VB6.

    Anyway, I would like some tips on how to extract info from a text file and write it to another.
    I am aware of how to open,read and then write to a text file but I am unsure how I pick out the position of the info i want.

    here we go...

    I require to extract a ten digit number from a text file which occurs on the 5th line of every section and is five spaces in from the left margin.


    example of text file:

    customer 1
    blah blah
    blah blah
    blah blah
    blah:177690303 (this is the number i need)
    blah blah
    blah blah
    blah blah
    blah blah

    customer 2
    blah blah
    blah blah
    blah blah
    blah:897690302 (this is the number i need)
    blah blah
    blah blah
    blah blah
    blah blah

    customer 3
    blah blah
    blah blah
    blah blah
    blah:3857690334 (this is the number i need)
    blah blah
    blah blah
    blah blah
    blah blah

    On the whole the positioning of the numbers stays static but if it didnt is there a way of searching for a cluster of ten numbers and extracting those?

    Once extracted I then would like to save the info to another text file as tab delimited.

    Any thoughts guys?

  2. #2
    VB Addict Pradeep1210's Avatar
    Join Date
    Apr 2004
    Location
    Inside the CPU...
    Posts
    6,614

    Re: Extracting from then to writing .txt

    Open file.
    Use SEEK to locate your record
    read it into a variable
    Open another file
    write to other file.

    Or else read the whole file into a variable and use string opreations to locate the info you want.

    Pradeep
    Pradeep, Microsoft MVP (Visual Basic)
    Please appreciate posts that have helped you by clicking icon on the left of the post.
    "A problem well stated is a problem half solved." — Charles F. Kettering

    Read articles on My Blog101 LINQ SamplesJSON ValidatorXML Schema Validator"How Do I" videos on MSDNVB.NET and C# ComparisonGood Coding PracticesVBForums Reputation SaverString EnumSuper Simple Tetris Game


    (2010-2013)
    NB: I do not answer coding questions via PM. If you want my help, then make a post and PM me it's link. If I can help, trust me I will...

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Extracting from then to writing .txt

    Access VBA question moved to Office Development.

  4. #4
    Fanatic Member dannymking's Avatar
    Join Date
    Jul 2005
    Location
    Darlington, North East UK
    Posts
    677

    Re: Extracting from then to writing .txt

    I'm guessing that these are normal text files, therefore the SEEK method will return the byte position and not the text as in the Random access files..

    If the position will never change then the best method would be to read in the first four lines and then concentrate on the 5th..

    VB Code:
    1. Dim strIn As String
    2.   Dim FFile As Integer
    3.   Dim i As Long
    4.   FFile = Freefile
    5.   Open "MyFile.txt" For Input As #FFile
    6.   For i = 1 to 4
    7.     Line Input #FFile, strIn
    8.   Next
    9.   'concentrate on the next line..
    10.   Line Input #FFile, strIn
    11.   'Close file as no longer needed
    12.   Close #FFile
    13.   strIn = Mid(strIn,5,10)
    14.   msgbox strIn

    If however these files may change in the future then address the source of this information and request a special character around the number so it can be picked up no matter where it is placed, something like | or ¬.
    Danny

    Never Think Impossible

    If you find my answer helpful then please add to my reputation

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width