Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4,VB5,VB6,VBS
Expertise: Intermediate
Apr 1, 2000

JoinQuote2 - A Join variant that works with 2-dimensional arrays and quoted strings

' Join variant that works with
' bi-dimensional arrays of any type
' and that encloses string values between quotes
'
' ARR is the 2-dimensional array whose element must be joined
' ROWSEPARATOR is the separator for rows (default is CRLF)
' COLSEPARATOR is the separator fol columns (default is comma)
' QUOTED is the character used to quote string values
'     use a two-char string (eg "{}") if the openining
'     and closing quote chars are different
'     use a null string to suppress quoting feature

Function JoinQuoted2(arr As Variant, Optional ByVal RowSeparator As String = _
    vbCrLf, Optional ByVal ColSeparator As String = ",", _
    Optional ByVal Quotes As String = """") As String
    Dim res As String
    Dim r As Long
    Dim c As Long
    
    For r = LBound(arr) To UBound(arr)
        For c = LBound(arr, 2) To UBound(arr, 2)
            If VarType(arr(r, c)) <> vbString Then
                res = res & arr(r, c)
            Else
                ' the following code works correctly if
                ' LEN(Quotes) is 0,1,2
                res = res & Left$(Quotes, 1) & arr(r, c) & Right$(Quotes, 1)
            End If
            If c < UBound(arr, 2) Then res = res & ColSeparator
        Next
        If r < UBound(arr) Then res = res & RowSeparator
    Next
    
    JoinQuoted2 = res

End Function

Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date