Skip to content

Commit 3496143

Browse files
committed
Deprecated: Filter2 method
1 parent 3088efc commit 3496143

File tree

3 files changed

+20
-143
lines changed

3 files changed

+20
-143
lines changed

docs/api/methods/filter.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ The `Pattern` parameter is evaluated according to the number of records in the C
6060
* To reference a field value, the user must type something like `f#` where `f` is a required identifier and `#` is the numeric position of the desired field. For example, `f1>5` indicates the selection of records whose first field value is greater than `5`.
6161
* If the user needs to compare literal strings, the values must be enclosed in apostrophes. Example, `Region = 'Central America'` is a valid string assigned to the variable `Region`.
6262
* User can use functions in the `Pattern` definition, including custom UDFs (refer to [VBAexpressions documentation](https://github.com/ws-garcia/VBA-Expressions)). I.e.: `min(f5;f2)>=100`
63+
* The LIKE operator (`$`) comparison is influenced by the `Option Compare` statement (one of: `Option Compare Binary` or `Option Compare Text`). The binary compare is case sensitive, the text compare is not. The following table describes the special characters to be used when creating patterns; all other characters match themselves:
64+
*
65+
|Character|Meaning|
66+
|:------:|:-----|
67+
|?|Any single character|
68+
|\*|Zero or more characters|
69+
|#|Any single digit (0-9)|
70+
|\[list\]|Any single character in list|
71+
|\[!list\]|Any single character not in list|
72+
|\[\]|A zero-length string ("")|
73+
* 'list' matches a group of characters in `patterns` to a single character in the string and can contain almost all available characters, including digits.
74+
* Use a hyphen (-) in 'list' to create a range of characters that matches a character in the string: e.g. [A-D] matches A,B,C, or D at that character position in the string. Multiple ranges of characters can be included in 'list' without the use of a delimiter: e.g. \[A-DJ-L\].
75+
* Use the hyphen at the start or end of 'list' to match to itself. For example, \[-A-G\] matches a hyphen or any character from A to G.
76+
* The exclamation mark in the "pattern" match is similar to the negation operator. For example, [!A-G] matches all characters except characters A through G.
77+
* The exclamation mark outside the bracket matches itself.
78+
* To use any special character as a matching character, enclose the special character in brackets. For example, to match a question mark, use \[?\].
6379

6480
When the `FilePath` argument is omitted, the method will proceed to filter the data stored in the current instance, otherwise it will filter the content of the CSV file specified with the referred argument.
6581

@@ -76,8 +92,8 @@ Sub FilterCSV()
7692
CSVint.parseConfig.Headers = False 'The file has no header record/row
7793
CSVint.parseConfig.path = path
7894
If path <> vbNullString Then
79-
Set FilteredData = CSVint.Filter("f1='Asia' & f9>20 & f9<=50", path) 'Select "Units sold" greater than 20 and less or
80-
'equal to 50 from Asian customers
95+
Set FilteredData = CSVint.Filter("f1='Asia' & f9>20 & f9<=50 & f8 $ '10/*/2014'", path) 'Select "Units sold" greater than 20 and less or
96+
'equal to 50 from Asian customers in October 2014
8197
Set CSVint = Nothing
8298
Set FilteredData = Nothing
8399
End If

docs/api/methods/filter2.md

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/CSVinterface.cls

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -692,57 +692,8 @@ Public Function Filter(Pattern As String, Optional FilePath As String = vbNullSt
692692
End If
693693
End If
694694
End Function
695-
''' <summary>
696-
''' Filter imported data using VBA like patterns.
697-
''' </summary>
698-
''' <param name="fieldIndex">Field to apply the filter.</param>
699-
''' <param name="patterns">A valid list of VBA string patterns.</param>
700-
Public Function Filter2(fieldIndex As Long, ParamArray patterns() As Variant) As CSVArrayList
701-
Dim UB As Long
702-
Dim LB As Long
703-
Dim cIndex As Long
704-
Dim rCount As Long
705-
Dim mettsPattern As Boolean
706-
707-
On Error GoTo ErrHandler_Filter
708-
If P_SUCCESSFUL_IMPORT Then
709-
Select Case fieldIndex
710-
Case 0 To P_VECTORS_REGULAR_BOUND
711-
UB = UBound(patterns)
712-
If UB >= 0 Then
713-
Set Filter2 = New CSVArrayList
714-
LB = LBound(patterns)
715-
For rCount = 0 To P_CSV_DATA.count - 1
716-
cIndex = LB
717-
Do
718-
mettsPattern = FilterAchievement(P_CSV_DATA(rCount)(fieldIndex), patterns(cIndex))
719-
cIndex = cIndex + 1
720-
Loop While Not mettsPattern And cIndex <= UB
721-
If mettsPattern Then
722-
Filter2.Add P_CSV_DATA(rCount)
723-
End If
724-
Next rCount
725-
Else
726-
Set Filter2 = P_CSV_DATA
727-
End If
728-
Case Else
729-
GoTo OutOfBounds_Filter
730-
End Select
731-
End If
732-
Exit Function
733-
ErrHandler_Filter:
734-
P_ERROR_DESC = "[CSV Field Insert]: " & err.Description
735-
P_ERROR_NUMBER = err.Number
736-
P_ERROR_SOURCE = "CSVinterface"
737-
Exit Function
738-
OutOfBounds_Filter:
739-
err.Raise Number:=vbObjectError + 9016, _
740-
Source:="CSVinterface Class", _
741-
Description:="The specified index is out of bounds. Please check and try again."
742-
Resume ErrHandler_Filter
743-
End Function
744-
Private Function FilterAchievement(aValue As Variant, Pattern As Variant) As Boolean
745-
FilterAchievement = aValue Like Pattern
695+
Private Function FilterAchievement(AValue As Variant, Pattern As Variant) As Boolean
696+
FilterAchievement = AValue Like Pattern
746697
End Function
747698
Public Function GetDataFromCSV(csvPathAndFilename As String) As String
748699

0 commit comments

Comments
 (0)