Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Okay I am making a form in my program that is a Friends list application for use on xbox.com. It works like this. When the form loads it it loads my.settings.friends into a textbox if my.settings.friends is not empty. Then it adds each line from that textbox to a different item in a listbox. That all works perfectly but I am having one problem. When I load the text into the textbox from my.settings.friends it makes the last line empty and then it creates an empty item in the listbox for that empty line. When the form closes it adds all of the items back to the textbox and then saves the textbox.text to the my.settings.friends and it obviously adds the empty items back so if I don't delete it next time I open it there will be two empty items and so on. Here is the code I am using to make it all work.

Form Load:
VB
Try
            TextBox2.Text = My.Settings.Friends
            TextBox2.Text.TrimEnd()
            Dim NewArray() As String = TextBox2.Text.Split(vbNewLine)
            If Not TextBox2.Text = "" Or Nothing Then
                For Each item As String In NewArray
                    If item = "" Or Nothing Then
                    Else
                        ListBox1.Items.Add(item)
                    End If

                Next
                ListBox1.Items.Remove(ListBox1.Items.Count - 1)
            End If

        Catch ex As Exception

        End Try


Form Closing:
VB
TextBox2.Text = ""
        For Each thing As Object In ListBox1.Items
            TextBox2.AppendText(thing.ToString & vbNewLine)
        Next
        TextBox2.Text.TrimEnd()
        My.Settings.Friends = TextBox2.Text


Could someone please help me? I want it to not make this empty line at the end of the textbox. All of the TextBox2.Text.TrimEnd are my attempt to erase it but they aren't working.
Posted
Comments
[no name] 9-Sep-12 22:29pm    
Lookup the string.IsNullOrEmpty function
Zack Mcintosh 9-Sep-12 22:45pm    
I got it thanks to slight help from you. It works with String.IsNullOrWhiteSpace
If String.IsNullOrWhiteSpace(item) Then
Else
ListBox1.Items.Add(item)
End If

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900