|
-
Apr 9th, 2011, 12:11 PM
#1
Thread Starter
Lively Member
[RESOLVED] How to Write Listbox Items to One Line?

I need to know how to write the items in the right listbox to a .txt file using StreamWriter. I need the output line to resemble:
Code:
"set sv_mapRotation map mp_abandon map mp_afghan map mp_boneyard map mp_brecourt map mp_checkpoint map mp_complex map mp_crash"
The order should be just like it is in the right listbox.
This is the code that I have set up to begin this:
Code:
myWriter.WriteLine("set sv_mapRotation" + " " + """" + """")
If you need more information please let me know. I'd be more than willing to provide it. Sorry I can't be more detailed at the moment as I'm in a rush.
Any and all help is appreciated.
Last edited by SLeePYG72786; Apr 10th, 2011 at 10:00 AM.
-
Apr 9th, 2011, 12:27 PM
#2
Re: How to Write Listbox Items to One Line?
try this:
vb Code:
myWriter.WriteLine("set sv_mapRotation " & String.Join(" ", ListBox1.Items.Cast(Of String).ToArray))
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Apr 9th, 2011, 12:31 PM
#3
Re: How to Write Listbox Items to One Line?
Assuming that the listbox on the right hand side is listbox2 you can do something like this:
vb Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim ListboxCount As Integer ListboxCount = ListBox2.Items.Count Dim myString As String = "set sv_mapRotation " Dim myMaps As String = Nothing For i = 1 To ListboxCount myMaps = myMaps + " " + ListBox2.Items.IndexOf(i).ToString Next myString = myString + myMaps MsgBox(myString) End Sub
The Line MsgBox(myString) just gives you a way to verify the string when you are finished.
-
Apr 9th, 2011, 01:03 PM
#4
Thread Starter
Lively Member
Re: How to Write Listbox Items to One Line?
@ .paul.
Thank you sooo much. That worked perfectly.
@ mbutler755
Thanks for the input, but .paul.'s code was much more condensed and more suitable for my project.
Thanks to both of you for the quick replies!
Tags for this Thread
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
|