ANStrFind_AndOrAdd

Checks if an item was found in list of items and return 1 if yes, 0 if not found.
If not found, it can add that missing item to list if caller sets AddItemIfNotFound to 1.
Uses ANString style, where ANStrList is list of strings with defined separator which will be returned as well updated with new item.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function ANStrFind_AndOrAdd(ThisItem, ByRef ANStrList, Optional AddItemIfNotFound = 1, Optional Sepa = "|")
    ' Checks if an item was found in list of items and return true if yes, false if not
    '    With option to add the new item to list if not found
    '
    ' Set AddItemIfNotFound to 1 if you want function to add item to list if it was not found
    '        Where the list will be updated, hence "ByRef" is used
    ' Needs CutString3
    Rett = 0
    ItemID = 1
    Do
        Cut3 = CutString3(AnStrList, ItemID, Sepa)
        If Cut3 = "" Or Cut3 = AnStrList Then Exit Do
        If IsNumeric(ThisItem) Then
            If Val(ThisItem) = Val(Cut3) Then
                Rett = 1
                Exit Do
            End If
        Else
            If UCase(Trim(ThisItem)) = UCase(Trim(Cut3)) Then
                Rett = 1
                Exit Do
            End If
        End If
        ItemID = ItemID + 1
    Loop
    If Rett = 0 And AddItemIfNotFound = 1 Then
        If AnStrList > "" Then AnStrList = AnStrList & Sepa
        AnStrList = AnStrList & ThisItem
    End If
    ANStrFind_AndOrAdd = Rett
End Function

ThisItem, ByRef ANStrList, Optional AddItemIfNotFound = 1, Optional Sepa = "|"

Views 112

Downloads 46

CodeID
DB ID