Option Explicit
Sub TestFunction()
Dim vTest As Variant
vTest = Array("String", "Long", "Byte", "Integer", "Variant", "Boolean")
MsgBox ArrayToDelimited(vTest, ";")
End Sub
' \\ Function to convert a given array to a delimited string
' \\ If not specified the delimiter is ","
Public Function ArrayToDelimited(vArray As Variant, _
Optional sDelim As String = ",") _
As String
Dim sDelimString As String
Dim lCounter As Long
' \\ Loop through array from the lower boud to the upper bound
For lCounter = LBound(vArray) To UBound(vArray)
' \\ As long as lCounter is smaller then the upper bound of the array
' \\ add the value of that item to the string sDelimString and add delimiter
sDelimString = sDelimString & _
CStr(vArray(lCounter)) & IIf(lCounter < UBound(vArray), sDelim, "")
Next
' \\ Return delimited string
ArrayToDelimited = sDelimString
End Function
|