Google Answers Logo
View Question
 
Q: Please parse this simple text file for me ( No Answer,   0 Comments )
Question  
Subject: Please parse this simple text file for me
Category: Computers > Programming
Asked by: lochness-ga
List Price: $10.00
Posted: 28 Oct 2003 08:36 PST
Expires: 29 Oct 2003 23:43 PST
Question ID: 270442
I need someone to write a piece of code that parses the content of a
file called sales.txt and put (append) five pieces of information in
another file called sales2.txt with each value separated by a comma.
You can use visual basic or visual c++ or whatever. i can compile the
code using my visual studio. The sales.txt file looks exactly
(including the blank lines) like this:
Acme Corp               
555-1212
|-------------------------------------|
|          End of Day Report          |
|               x07/08/93x            |
|             Daily Totals            |
|-------------------------------------|


Sales Amount:
     Non-Tax            x330.00x
     Taxable 1          x269.98x
     Taxable 2            0.00
     Taxable 3            0.00
                     Total       599.98

Labor Fees:                        0.00
Repair Part Fees:                  0.00
Rental Fees:                       0.00
License Sales:                     0.00

Return Amount:
     Non-Tax              x11.00x
     Taxable 1            x30.00x

Just grab the numbers betwen the x. The x is not included in the
sales.txt. I included the x to point out the data items that I want.
The date is always in MM/DD/YY format.

So sales2.txt should look like:

07/08/93,330.00,269.98,11.00,30.00

Request for Question Clarification by molloch-ga on 29 Oct 2003 13:48 PST
Hi,

Is it always Non-Tax and Taxable 1 that you want? Is there ever an
occasion where you might want Taxable 2 and taxable 3? If so, does
this also add lines to the bottom of the report under return amount?

Thanks
Molloch

Clarification of Question by lochness-ga on 29 Oct 2003 16:36 PST
no. i only need those files specified.

thanks

Request for Question Clarification by googleexpert-ga on 29 Oct 2003 18:45 PST
When you said "whatever", does that mean you will accept Perl Scripts as an answer?

Clarification of Question by lochness-ga on 29 Oct 2003 23:43 PST
Sorry to close this question. I kinda need the answer to prepare my
quarterly taxes so I had to write it myself to run in Excel. Not
elegant but does the job. Thanks everyone!

Sub doit()

    'Please change file name and path
    csvName = "C:\finance\data.TXT"
    i = 1
    j = 1
    rw = 1
    Application.ScreenUpdating = False
    momax = 31
'3 months: Jul, Aug, sept
For q = 1 To 3
If q = 3 Then momax = 30

For numdays = 1 To momax
  If numdays <= 9 Then
    sNumDay = "0" & numdays
  Else
    sNumDay = numdays
  End If
  If q = 1 Then sMonth = "07"
  If q = 2 Then sMonth = "08"
  If q = 3 Then sMonth = "09"
  
'data is stored in a zip file. Unzip and data.txt can be seen
  sfile = "pkunzip.exe -o c:\finance\" & sMonth & "-" & sNumDay &
"-03.zip c:\finance"
  Shell sfile
'wait 1 sec
  Application.Wait Now + TimeValue("00:00:01")
  j = 1
  i = 1
    Open csvName For Input As #1 'was unzipped above
    Do Until EOF(1)
    Line Input #1, tmpline
    field = Replace(tmpline, " ", "")
If (i = 5 Or i = 11 Or i = 12 Or i = 23 Or i = 24 Or i = 30 Or i = 31)
Then
        If i = 5 Then
         field = Replace(field, "|", "")
        End If
        If i = 11 Then
         field = Right(field, Len(field) - 7)
        End If
        If i = 12 Then
         field = Right(field, Len(field) - 8)
        End If
        If i = 23 Then
         field = Right(field, Len(field) - 7)
        End If
        If i = 24 Then
         field = Right(field, Len(field) - 8)
        End If
        If i = 30 Then
         field = Right(field, Len(field) - 7)
        End If
        If i = 31 Then
         field = Right(field, Len(field) - 8)
        End If
       
        Worksheets("Sheet1").Activate
        Range(Cells(rw, j), Cells(rw, j)).FormulaR1C1 = field
j = j + 1
 End If
    i = i + 1
    Loop
    Close #1
    rw = rw + 1
Next

Next
    Application.ScreenUpdating = True
End Sub
Answer  
There is no answer at this time.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy