output to txt file

  • Re: output to txt file


    Marc,



    This now exports all lines from the first group containing an order number that appears in the Excel file.


    :)
    Alan.

  • Re: output to txt file


    Alan -


    Thanks very much for your excellent help
    Works perfectly.
    How can I re-pay you?


    Thanks
    -marc

  • Re: output to txt file


    Hi Alan-


    Sorry to bother you again
    Have come across another problem with the archive file:


    CSV file saves as .txt contains order details from SQL server
    An order may contain 1 to 00 [google] lines [ I call this set a group]
    Each line needs to be written out


    If Grouping occurs again, it should be ignored [every time]
    Or deleted [one time]


    The file is not sorted, but needs to be
    Problem is, if I sort it, when I write out the order
    The order details will duplicate or more


    Current code stops writing when change in order number
    So when I reconcile the SQL detail file to dump file from
    accounting I have a variance


    Can anyone help me how to sort this file and either skip or delete
    duplicate groups.


    Sample file attached
    Thanks
    -marc

  • Re: output to txt file


    Marc,


    I wondered if this might be something we ended up doing. It was a way that I thought initially of getting rid of duplicates and limiting the size of the archive file.


    There are two ways that we can do this. The first is to use the DOS Sort command. Very fast for text files, the second is to import the data into Excel and then sort and deduplicate it. I favour the DOS method simply because you state the file will continue to grow, and could conceivably be greater that 65000 rows. (Although I suspect after deduping we may find it is alot smaller.)


    The code in the first code panel sorts the archive, dedupes it and then passes the resulting file to the process previously used. Only this time it should not have to worry about a new group of order numbers. Whether you continue to use the original archive file or the archive2.txt file is up to you. I have not deleted any of the interim files as these may be required for an audit trail. I suggest that you replace all previously supplied code with code panel 1 as there are several lines that have been modified.


    The second code panel provides the ShellAndWait code published at http://www.xcelfiles.com/VBA_01.html#anchor_14263 so due credit to the author of the code which I have not altered. This should be placed in another module such as mdlShellAndWait.


    HTH,


    Alan.




  • Re: output to txt file


    Thanks Alan
    Awesome as always :)


    Quote


    Whether you continue to use the original archive file or the archive2.txt file is up to you


    If I use archive.txt, code errors out here

    Code
    '    On Error GoTo DiskError
         'Open input and output files
        intFileIn = FreeFile()
        Open strArchiveFilename2 For Input As #intFileIn


    If I use archive2.txt, the code executes


    I copied a few lines of interspersed records into archive.txt
    I then opened with xl as csv,sorted and manually checked for uniqueness


    In my sample of order 6024, I found 7 unique lines.
    Col AE = qty
    Col AG = unit price
    Col AO = SKU


    The Catering sales people or customer used SKU ...171 twice, but the quantity was different. Don't know why they would do this, but then I'm just an accounting/data geek.


    I searched for 6024 on the full archive file
    Textpad returned occurrences at these rows
    2404
    2408
    2409
    2412
    2413
    2414
    2415
    7 lines as expected
    No other groupings were found during the manual search


    I ran the code, 2 lines were written out to "orders"
    SKU460-180-184 line 5 of sample
    SKU460-180-181 line 6 of sample


    Sorry so long
    Thanks again for all of your efforts :)
    -marc

  • Re: output to txt file


    Marc,


    I am sorry, I do not quite follow. Are you saying taht only two lines were output and you were expecting 7?


    If so could you send me the archive file and the list of order numbers that are in the xl file. I will then run them and see what I get.


    I have undertaken a similar exercise and not had any problems. The only records that were missed were duplicates and ones corresponding to order numbers not in the xl file.


    With respect to my comment on using archive or archive2. Once you have run the process and you are happy with the results then I would delete the old archive.txt and rename the file archive2.txt to archive.txt. Then append future archive data to that. This will limit the ongoing growth of the archive file. For an audit trail at the moment I would not change the process.


    Cheers,


    Alan.

  • Re: output to txt file


    Alan -

    Quote


    Are you saying 'that' only two lines were output and you were expecting 7?


    Yes.


    Quote


    With respect to my comment on using archive or archive2. Once you have run the process and you are happy with the results then I would delete the old archive.txt and rename the file archive2.txt to archive.txt. Then append future archive data to that. This will limit the ongoing growth of the archive file. For an audit trail at the moment I would not change the process.


    Sounds good. Thanks.


    Files are attached
    Thanks
    -marc

  • Re: output to txt file


    Marc,


    When I use your files I do not have a problem. 7 records are output.


    I notice that your file does not have a header line. This may cause problems as the code expects a header line, although I did not change the code.


    I think a little more info may be required. I checked the sort function in DOS to make sure that it does not have a cutoff of 255 or 512 characters, I guess I should check for a cutoff at 1024 as the strings are longer than that.


    Please try again and let me know what happens.


    Alan.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!