Consulting

Results 1 to 4 of 4

Thread: Solved: How to eliminate part of message

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    10
    Location

    Solved: How to eliminate part of message

    I wanna eliminate part of message like a comma or a word at the end of message. How can I do it.

    For example,

    [vba]Sub messagetry()
    Dim msg As String, i As Integer

    For i = 1 To 5
    msg = msg + CStr(i) + ", "
    Next i

    MsgBox msg

    End Sub[/vba]
    The output of this is :
    1, 2, 3, 4, 5,

    How can I eliminate the comma behind 5.
    There can only be "+" but no "-" in the equation [msg = ......]

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub messagetry()
    Dim msg As String, i As Integer

    For i = 1 To 5
    msg = msg + CStr(i) + ", "
    Next i
    msg = Left$(msg, Len(msg) - 2)

    MsgBox msg

    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Dec 2008
    Posts
    10
    Location
    That is a clever method ~ Thanks!

  4. #4
    VBAX Expert
    Joined
    Aug 2007
    Location
    Windermere, FL, a 'burb in the greater Orlando metro area.
    Posts
    567
    Location
    garyc,

    Here's another way to solve your problem:
    [vba]Sub messagetry1()
    Dim msg As String, i As Integer

    msg = CStr(1)
    For i = 2 To 5
    msg = msg + ", " + CStr(i)
    Next i

    MsgBox msg

    End Sub[/vba]

    Cheers,
    Ron
    Windermere, FL

Posting Permissions

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