|
-
Apr 14th, 2006, 06:20 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] concatenating the content of a listbox
Hi
I have a listbox that contains filenames,the listbox can contain 1 filename or more(up to 10).I want the content of the listbox to be displayed in a string Msg as follow:
If the listbox contains File1,File2 and File3,I want the string Msg to be:
Msg="File1,File2,File3"
but if the listbox contains only one filename,let's Msg be:
Msg="File1"
I tried a code but I obtained a comma at the the end of the string like
Msg="File1,".So how can I avoid the last comma?
thanks
-
Apr 14th, 2006, 06:23 AM
#2
Re: concatenating the content of a listbox
VB Code:
msg = left(msg,len(msg)-1)
-
Apr 14th, 2006, 06:25 AM
#3
Re: concatenating the content of a listbox
I think the easiest way is to remove the last comma.
VB Code:
Private Sub Command1_Click()
Dim Msg As String
Dim i As Integer
For i = 0 To List1.ListCount - 1
Msg = Msg & List1.List(i) & ","
Next
If Len(Msg) > 0 Then
Msg = Left(Msg, Len(Msg) - 1)
End If
MsgBox Msg
End Sub
-
Apr 14th, 2006, 06:58 AM
#4
Re: concatenating the content of a listbox
Or you can use an array and the Join() function specifying a comma delimeter. It might be too much for now, but this approach helps when your dealing with string arrays from Split(), etc, so it might be useful to know in advance just in case.
VB Code:
Dim srrFileNames() As String
Dim i As Integer
ReDim srrFileNames(List1.ListCount - 1)
For i = 0 To List1.ListCount - 1
srrFileNames(i) = List1.List(i)
Next
Msg = Join(srrFileNames, ",")
-
Apr 14th, 2006, 12:37 PM
#5
Thread Starter
Fanatic Member
Re: concatenating the content of a listbox
Hi
thanks to you all,Leinad31,Frans C and JMACP
it was what I wanted
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|