Consulting

Results 1 to 3 of 3

Thread: Question with FSO filtering - snb

  1. #1
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location

    Question with FSO filtering - snb

    snb - I am wondering if the below code can have multiple filter conditions?
    Sub M_snb() 
        With createobject("scripting.filesystemobject") 
            .createtextfile("G:\OF\Filtered.csv").write  join(filter(split(.opentextfile("G:\OF\sample.csv").readall,vbcrlf),"dd-mm-yyyy")),vbcrlf) 
        End With 
        workbooks.open "G:\OF\Filtered.csv" 
    End Sub
    The filter for above is the date section, can I have another filtering criteria added to it? For example, if I wanted two dates on a "or" condition. How about "and" condition.

    The main reason why I wanted this is that some of my SCADA file dump are really bastardize, so with the above code, I can extract my pertinent rows of information, however, I need multiple filter conditions - sometimes with "or" and "and".

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,646
    You can use "and' filters

    all records in which the date "-1970" _1971,1972 ,etc ... 1979 occurs.

    result as array:
    sn =filter(c00,"-197")
    result as string
    c00 =join(filter(c00,"-197"),vblf)
    all records in the seventies in march: "AND"
    result as array
    sn =filter(filter(c00,"-197"),"-03-")
    result as string
    c00 =join(filter(filter(c00,"-197"),"-03-"))

    To use "or"
    All records in the seventies and the nineties:

    result as string:
    c00=join(filter(c00,"-197"),vblf) & vblf & join(filter(c00,"-199"),vblf)
    result as array:
    sn=  split(join(filter(c00,"-197"),vblf) & vblf & join(filter(c00,"-199"),vblf),vblf)
    NB. You can also use the very important "Is Not" filter
    All records except those from the seventies.
    sn=filter(c00,"-197",0)

  3. #3
    VBAX Expert
    Joined
    Aug 2004
    Posts
    810
    Location
    thank you for the in depth explanations and examples, I will definitely take a out for a spin next week. Have a great weekend.

Posting Permissions

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