PDA

View Full Version : Solved: How to eliminate part of message



garyc
12-15-2008, 06:21 AM
I wanna eliminate part of message like a comma or a word at the end of message. How can I do it.

For example,

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

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

MsgBox msg

End Sub
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!

Bob Phillips
12-15-2008, 06:24 AM
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

garyc
12-15-2008, 06:29 AM
That is a clever method ~ Thanks!

RonMcK
12-15-2008, 08:20 AM
garyc,

Here's another way to solve your problem:
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

Cheers,