PDA

View Full Version : [SOLVED] Question with FSO filtering - snb



JKwan
02-13-2016, 10:46 AM
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".

snb
02-13-2016, 11:20 AM
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)

JKwan
02-13-2016, 11:37 AM
thank you for the in depth explanations and examples, I will definitely take a out for a spin next week. Have a great weekend.