ItemCount




Public Function ItemCount(ByVal sOrigStr As String, ByVal sDelim As String) As Long
'

' Returns the number of occurances of sDelim in szStr)

'

Dim lCount As Long
Dim lPos As Long
Dim lPos2 As Long
Dim bOver As Boolean
Dim lDelim As Long

On Error GoTo vbErrorHandler

lPos = 0
lCount = 0

If sOrigStr = "" Then
ItemCount = 0
Exit Function
End If
lDelim = Len(sDelim)

Do
lPos2 = InStr(lPos + lDelim, sOrigStr, sDelim)
If lPos2 = 0 And lPos = 0 Then
lCount = 1
Exit Do
Else
If lPos2 = 0 Then
If Mid$(sOrigStr, lPos + lDelim, 1) <> "" Then
lCount = lCount + 1
End If
Exit Do
End If
End If
lCount = lCount + 1
lPos = lPos2
Loop
ItemCount = lCount
Exit Function

vbErrorHandler:
'

' Handle Error Here !

'

End Function










( itemcount.html )- by Paolo Puglisi - Modifica del 17/12/2023