ANStrRead + ANStrSave + ANStrSearch

Reads and saves data into 1 dim string array, ANStr
ANStr is a string of list of items separated by certain separator (Sepa)
ANStrSave can also remove items from list in addition to save items, it is currently unique list, so all duplications are by default removed.
And as a bonus, we have also ANStrSearch to search for an item in that string and returns its location ID.

CodeFunctionName
What is this?

Public

Tested

Original Work
Function ANStrRead(ANStrList, ItemID, Sepa)
ANStrRead = CutString3(ANStrList, ItemID, Sepa)
End Function
Function ANStrSearch(SearchFor, ANStrList, Sepa)
' Searches for an item in an ANStrList list
' Returns id of item or 0 if not found
' Needs CutString3
Return1 = 0
ItemID = 1
Do
Cut3 = CutString3(ANStrList, ItemID, Sepa)
If UCase(Trim(SearchFor)) = UCase(Trim(Cut3)) Then Return1 = ItemID
If Cut3 = "" Or Cut3 = ANStrList Then Exit Do
If IsNumeric(SearchFor) Then
If Val(SearchFor) = Val(Cut3) Then
Return1 = ItemID
Exit Do
End If
Else
If UCase(Trim(SearchFor)) = UCase(Trim(Cut3)) Then
Return1 = ItemID
Exit Do
End If
End If
ItemID = ItemID + 1
Loop
ANStrSearch = Return1
End Function
Function ANStrSave(ANStrList, Items2Del, Items2Add, Sepa)
' ANStrList = "Strings|seperated|by|Sepa"
' Items2Del = "Strings|seperated|by|Sepa" or blank
' Items2Add = "Strings|seperated|by|Sepa" or blank
' Sepa = "|"
ANStrSave = ANStrList
If Items2Del = "" And Items2Add = "" Then Exit Function
Dim NL, NLAdd, NLDel
NL = ""
For Each Item1 In Split(ANStrList, Sepa) ' Delete items
Item1 = Trim(Item1)
Item4 = Item1
If Item1 > "" Then
Found1 = 0
For Each Item2 In Split(Items2Del, Sepa)
Item2 = Trim(Item2)
If Item2 > "" Then
If UCase(Item1) = UCase(Item2) Then
Item4 = ""
Exit For
End If
End If
Next
End If
If Item4 > "" Then
If NL > "" Then NL = NL & Sepa
NL = NL & Item4
End If
Next
If NL > "" Then ANStrList = NL

For Each Item3 In Split(Items2Add, Sepa) ' Add Items only if not found
Item3 = Trim(Item3)
If Item3 > "" Then
Found1 = 0
For Each Item1 In Split(ANStrList, Sepa)
Item1 = Trim(Item1)
If Item1 > "" Then
If UCase(Item1) = UCase(Item3) Then
Found1 = 1
Exit For
End If
End If
Next
If Found1 = 0 Then
If NL > "" Then NL = NL & Sepa
NL = NL & Item3
End If
End If
Next
ANStrSave = NL
End Function

ANStrList, ItemID, Sepa
or
SearchFor, ANStrList, Sepa
or
ANStrList, Items2Del, Items2Add, Sepa

Views 4,708

Downloads 1,350

CodeID
DB ID