Results 1 to 8 of 8

Thread: String Help

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2000
    Location
    Carolina, Puerto Rico, USA
    Posts
    227

    String Help

    Hello.


    Im creating an interface like MS Access to create MySQL tables, it is almost done, BUT i have a "small" problem with a string concat, here is the code.

    Code:
    strSQL = "CREATE TABLE " & txtTableName & " ( "
    
    For dimintRow = 1 To 19
        For dimintCol = 1 To 2
            TempStr = fgMySQLAccess.TextMatrix(dimintRow, dimintCol)
            strSQL = strSQL & " " & TempStr
            DoEvents
        Next dimintCol
        If TempStr <> "" Then
        strSQL = strSQL & " , "
        End If
    Next dimintRow
    strSQL = strSQL & " )"
    txtSQLQuery = strSQL
    I need to separate the table fields with a comma (","), but the way im doing it i always get an undesired come at the end of the sql

    Code:
    CREATE TABLE MyTable (  OneField Text ,  AnotherField Text ,  EvenAnotherField Text ,                                  )

    Is there a way to get rid of it?


    Thanks in advance!
    NievesJ

  2. #2
    Frenzied Member blindlizard's Avatar
    Join Date
    Feb 2001
    Location
    Austin, TX - United States of America
    Posts
    1,141
    If you add the first field to the string before the loop and then add the commas before the fields in the loop, you will not have any extra commas.
    I drink to make other people more interesting!
    [vbcode]On Error GoTo Bar[/vbcode]
    http://www.monsterlizard.com

  3. #3
    Addicted Member Sully's Avatar
    Join Date
    Nov 2002
    Location
    Lost in the far recesses of one's own mind.
    Posts
    165
    Something like this outside the loop structure:


    txtsqlstr = Left(strsql, Len(Trim(strsql)) - 1) & ")"


    JS
    Disclaimer:

    * The preceding message was in no means meant to be critical, mean spirited, insincere, or facetious.

    Disclaimer for disclaimer:

    The preceding disclaimer may in fact be facetious in nature.

    Thanks,
    Jim

  4. #4
    Hyperactive Member Granty's Avatar
    Join Date
    Mar 2001
    Location
    London
    Posts
    439
    Code:
    strSQL = "CREATE TABLE " & txtTableName & " ( "
    
    For dimintRow = 1 To 19
        For dimintCol = 1 To 2
            TempStr = fgMySQLAccess.TextMatrix(dimintRow, dimintCol)
            strSQL = strSQL & " " & TempStr
            DoEvents
        Next dimintCol
        If TempStr <> "" Then
        strSQL = strSQL & " , "
        End If
    Next dimintRow
    strSQL = left(strSQL, len(strSQL) - 2)
    strSQL = strSQL & " )"
    txtSQLQuery = strSQL
    Should fix it

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: String Help

    this will remove the last character from your string.. do this before you execute the SQL statement
    VB Code:
    1. strSQL = left(strSQL,len(strSQL) - 2)

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    That's easy,
    you put a comma after each strSQL (if its not empty).
    So also do this for the last one, which you don't want to have. One way to get rid of it is to remove the last three characters of the strSQL just before you put the ")" at the end.
    VB Code:
    1. strSQL=right(strSQL,len(strSQL-3))
    It's 3 char'S because you add " , ", which are 3 char's.


    There are other ways to do it, but.....
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863
    Kleinma he added " , " not only " ," !
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    Originally posted by opus
    Kleinma he added " , " not only " ," !
    well i think that they would get the idea.. you are correct however

    even though it should work with 1 space in there anyway

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