Code Snippets


Public Sub Str_ToArray(ByVal sText As String, _ 
                       ByRef vArrayName As Variant, _
                       Optional ByVal sSeparateChar As String = ";")
Dim snextentry As String
Dim iarraycount As Integer
Dim inoofchars As Integer
   On Error GoTo AnError
   inoofchars = Str_CharsNoOf(sText, sSeparateChar)
   If (inoofchars > 0) Then
      ReDim vArrayName(inoofchars, 1)
      iarraycount = 1
      Do While (Len(sText) > 0)
         If InStr(1, sText, sSeparateChar) = 0 Then
            snextentry = sText
            sText = ""
         Else
            snextentry = Left(sText, InStr(1, sText, sSeparateChar) - 1)
            sText = Right(sText, Len(sText) - Len(snextentry) - 1)
         End If
         vArrayName(iarraycount, 1) = snextentry
         iarraycount = iarraycount + 1
      Loop
   End If
   If gbDEBUG = False Then Exit Sub
AnError:
   Call Error_Handle("Str_ToArray", msMODULENAME, 1, _
        "split up the string" & vbCrLf & sText & vbCrLf & _
        "separated by " & sSeparateChar & " and place them in an array")
End Sub

Public Function Str_CharsNoOf(ByVal sText As String, _ 
                              ByVal sSeparateChar As String) As Integer
Dim icount As Integer
Dim ichar As Integer
   On Error GoTo AnError
   icount = 0
   Do While (InStr(1, sText, sSeparateChar) > 0)
      ichar = InStr(1, sText, sSeparateChar)
      icount = icount + 1
      sText = Right(sText, Len(sText) - ichar - 1)
   Loop
   Str_CharsNoOf = icount
   If gbDEBUG = False Then Exit Function
AnError:
   Call Error_Handle("Str_CharsNoOf", msMODULENAME, _
        "find the number of occurrences of the character '" & sSeparateChar & "'")
End Function

© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext