Results 1 to 8 of 8

Thread: Concatenate string with ";"

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    Concatenate string with ";"

    I looping recordset....
    I need to create a string deleimited from ";" for each row in table, but the code dont work correct!

    NEWSQL1 = ""
    NEWSQL = ""
    I = 2
    Do While Not RST.EOF = True
    For J = 0 To RST.Fields.Count - 1
    NEWSQL = Trim(RST.Fields(J).Value)
    NEWSQL1 = NEWSQL & ";"
    Debug.Print NEWSQL1
    Next J
    Print #1, NEWSQL
    RST.MoveNext
    I = I + 1
    Loop

    Note:
    In other case is required the last ";" if i want to import in access datatable the txt file?
    Last edited by luca90; Jul 17th, 2010 at 01:44 PM.

  2. #2
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Concatenate string with ";"

    No, the last field should not have a trailing ";" after it and before the newline.

    Did you MoveFirst before this loop?

    You can use the Recordset's GetString() method to do this, one line at a time or for the entire Recordset.

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    Re: Concatenate string with ";"

    Quote Originally Posted by dilettante View Post
    No, the last field should not have a trailing ";" after it and before the newline.

    Did you MoveFirst before this loop?

    You can use the Recordset's GetString() method to do this, one line at a time or for the entire Recordset.
    Example; possible about getstring()?

  4. #4
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Concatenate string with ";"

    Quote Originally Posted by luca90 View Post
    Example; possible about getstring()?
    Seriously? This is pretty clear in the documentation.
    Code:
    Private Function DumpRecordset() As String
        With rsData
            .MoveFirst
            DumpRecordset = .GetString(adClipString, , ";", vbNewLine, "*null*")
        End With
    End Function
    Attached Files Attached Files

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    Re: Concatenate string with ";"

    Quote Originally Posted by dilettante View Post
    Seriously? This is pretty clear in the documentation.
    Code:
    Private Function DumpRecordset() As String
        With rsData
            .MoveFirst
            DumpRecordset = .GetString(adClipString, , ";", vbNewLine, "*null*")
        End With
    End Function
    good code ... but i work arround a few records.
    Really have 3/4 millions of records and the code go in error "not enauhght memory"

  6. #6
    Addicted Member
    Join Date
    Jul 2010
    Posts
    158

    Re: Concatenate string with ";"

    Hi,

    You need to Clear NewSQL1 for each record...
    Try This :
    vb Code:
    1. Dim FN As Integer
    2. FN = FreeFile
    3. Open "C:\Temp1.txt" For Output As FN
    4. Do While Not RST.EOF = True
    5.    NewSQL1 = ""
    6.    For J = 0 To RST.Fields.Count - 1
    7.       NEWSQL1 = NEWSQL1 & ";" & Trim(RST.Fields(J).Value)
    8.    Next J
    9.    Print #FN, NEWSQL1
    10.    RST.MoveNext
    11. Loop
    12. Close FN

    Regards
    Veena

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,943

    Re: Concatenate string with ";"

    Quote Originally Posted by VeenaMG View Post
    Hi,

    You need to Clear NewSQL1 for each record...
    Try This :
    vb Code:
    1. Dim FN As Integer
    2. FN = FreeFile
    3. Open "C:\Temp1.txt" For Output As FN
    4. Do While Not RST.EOF = True
    5.    NewSQL1 = ""
    6.    For J = 0 To RST.Fields.Count - 1
    7.       NEWSQL1 = NEWSQL1 & ";" & Trim(RST.Fields(J).Value)
    8.    Next J
    9.    Print #FN, NEWSQL1
    10.    RST.MoveNext
    11. Loop
    12. Close FN

    Regards
    Veena
    hI friend, sorry for delay... you tips work fine! Tks.
    But for you, have sense instead to use only the ; to devide the records in txt file, or i need to use ";", similar:

    this:
    ;eeeeee;sdfdsfsdfsdf;dsfdsf;.........

    or:
    "eeeeee";"sdfdsfsdfsdf";"dsfdsf";.........

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Concatenate string with ";"

    Quote Originally Posted by luca90 View Post
    good code ... but i work arround a few records.
    Really have 3/4 millions of records and the code go in error "not enauhght memory"
    If you just look at the documentation you'll find that GetString() has an optional parameter NumRows telling it how many records to "get."

    You can use a loop "getting" 1000 or 10000 records at a time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width