CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Feb 2020
    Posts
    46

    Filter a txt file based on an Excel template

    I have a text file composed of n records each of which consists of six numbers separated by a space, I need to filter this file to generate a new file that contains only the records that satisfy a specific condition set through a template made in excel .

    Each line of the file to be filtered must comply with a condition that is :
    the total of numbers present in each group as set in row 44 (I44, L44, O 44, R44 .... BE44) must satisfy a minimum and a maximum of presence as well as specified in BB7 / BC7 for the specific record analyzed to be validated.

    For example, the record reported as test (3 30 47 67 68 89) highlights a string of attendances equal to 0 0 0 1 0 4 3 3 3 3 1 0 0 (groups in which there are no numbers are not considered) which to the conditional string of line 44 it confirms the presence of a min of 4 and a max of 4 conditions met (see the 4 green stripes placed in correspondence with the occurrences that represent compliance with the condition).

    While for example the record 3 8 10 47 48 84 will be discarded and therefore not present in the Outputfile.txt file as it satisfies only 3 conditions instead of the minimum 4 provided.

    The file provided as an example 'ToPurgeFile.txt' consists of 6545 records and theoretically should be reduced by more than 50% with the excel template attached.

    link to download the sample files (data and template ) : https://we.tl/t-uVQesKTnDR

    thanks

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Filter a txt file based on an Excel template

    And what is your problem? Your question?
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2020
    Posts
    46

    Re: Filter a txt file based on an Excel template

    right

    as I can't write the code, my knowledge is too poor, I ask if someone can write it for me

    thanks for the right observation

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Filter a txt file based on an Excel template

    Quote Originally Posted by RIC63 View Post
    ...
    as I can't write the code, my knowledge is too poor, I ask if someone can write it for me
    ...
    It is not a good idea.
    If your knowledge is too poor, then try to improve it! So learn the C/C++ programming!
    Victor Nijegorodov

  5. #5
    Join Date
    Feb 2020
    Posts
    46

    Re: Filter a txt file based on an Excel template

    Hi VictorN

    in the past there was someone to whom I explained a similar problem and he kindly wrote me 20 lines of code, I'm not here to ask others to work for me and with a spirit of altruism everyone - if he wants - makes available to others their knowledge ... in this way everyone has the opportunity to learn something more .. with your approach no.
    If my request disturbs you, feel free to cancel my request

    with respect

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Filter a txt file based on an Excel template

    With respect but it seems a lot like homework.

  7. #7
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Filter a txt file based on an Excel template

    It's not homework. In a previous thread (https://forums.codeguru.com/showthre...t=#post2237550) I converted some Excel VBA code to C++ to speed up processing files.

    I've PM'd him indicating I might have time to do this in the next few days. But if any other guru can help, please do.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  8. #8
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Filter a txt file based on an Excel template

    Quote Originally Posted by RIC63 View Post
    I have a text file composed of n records each of which consists of six numbers separated by a space, I need to filter this file to generate a new file that contains only the records that satisfy a specific condition set through a template made in excel .

    Each line of the file to be filtered must comply with a condition that is :
    the total of numbers present in each group as set in row 44 (I44, L44, O 44, R44 .... BE44) must satisfy a minimum and a maximum of presence as well as specified in BB7 / BC7 for the specific record analyzed to be validated.

    For example, the record reported as test (3 30 47 67 68 89) highlights a string of attendances equal to 0 0 0 1 0 4 3 3 3 3 1 0 0 (groups in which there are no numbers are not considered) which to the conditional string of line 44 it confirms the presence of a min of 4 and a max of 4 conditions met (see the 4 green stripes placed in correspondence with the occurrences that represent compliance with the condition).

    While for example the record 3 8 10 47 48 84 will be discarded and therefore not present in the Outputfile.txt file as it satisfies only 3 conditions instead of the minimum 4 provided.

    The file provided as an example 'ToPurgeFile.txt' consists of 6545 records and theoretically should be reduced by more than 50% with the excel template attached.

    link to download the sample files (data and template ) : https://we.tl/t-uVQesKTnDR

    thanks
    I've now had a look at this. Sorry, but I don't understand the requirement. If you're unable to provide working VBA code for conversion to C++ as previously, you're going to have to be much more specific without using specific terminology - and possibly provide a worked example of how you would filter manually (using pen/paper) given the spreadsheet and sample input file lines.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  9. #9
    Join Date
    Feb 2020
    Posts
    46

    Re: Filter a txt file based on an Excel template

    Hi 2kaud how are you? I hope everything is OK

    Again with reference to this thread

    I would like to combine/merge the 4 codes (which I customized based on the one you kindly provided) into one and insert a further condition that filters the data entered in the 'OutPutFile' file, i.e. I would like the sum of the 4 minimums (BB7, BB47, BB87 BB127) plus the sum of the 4 maximums (BC7, BC47, BC87 BC127) is between two specific values (SuperMino 'BH2' and SuperMax 'BI2').

    Do you think that due to the characteristics of the 4 excel templates present in 'xxx_15_30_45_60_01.xlsm' it is possible? Can you possibly give me a code trace useful for the purpose?

    here the reference files : https://we.tl/t-QUPpDfia9k


    Thanks in advance

    Greetings

  10. #10
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,822

    Re: Filter a txt file based on an Excel template

    Sorry, but I haven't time at the moment to look further into this for a few weeks. It's probably possible as you're just reading values from an array obtained from spreadsheet(s) and filtering the data from the file(s) based upon these.

    It's probably time that you learnt c++ (or at least that needed for this) so that you can understand and maintain the code.
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

  11. #11
    Join Date
    Feb 2020
    Posts
    46

    Re: Filter a txt file based on an Excel template

    morning 2kaud

    ok I understand, thanks anyway
    have a good day

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

Featured