Results 1 to 4 of 4

Thread: [RESOLVED] How to Write Listbox Items to One Line?

  1. #1

    Thread Starter
    Lively Member SLeePYG72786's Avatar
    Join Date
    Sep 2010
    Posts
    66

    Resolved [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.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,418

    Re: How to Write Listbox Items to One Line?

    try this:

    vb Code:
    1. myWriter.WriteLine("set sv_mapRotation " & String.Join(" ", ListBox1.Items.Cast(Of String).ToArray))

  3. #3
    Hyperactive Member mbutler755's Avatar
    Join Date
    May 2008
    Location
    Peoria, AZ
    Posts
    417

    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:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim ListboxCount As Integer
    3.         ListboxCount = ListBox2.Items.Count
    4.         Dim myString As String = "set sv_mapRotation "
    5.         Dim myMaps As String = Nothing
    6.  
    7.         For i = 1 To ListboxCount
    8.             myMaps = myMaps + " " + ListBox2.Items.IndexOf(i).ToString
    9.         Next
    10.         myString = myString + myMaps
    11.         MsgBox(myString)
    12.     End Sub

    The Line MsgBox(myString) just gives you a way to verify the string when you are finished.
    Regards,

    Matt Butler, MBA, BSIT/SE, MCBP
    Owner, Intense IT, LLC
    Find us on Facebook
    Follow us on Twitter
    Link up on LinkedIn
    mb (at) i2t.us

    CODE BANK SUBMISSIONS: Converting Images to Base64 and Back Again

  4. #4

    Thread Starter
    Lively Member SLeePYG72786's Avatar
    Join Date
    Sep 2010
    Posts
    66

    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
  •  



Click Here to Expand Forum to Full Width