Writing to a Sequential text file

chinaboy

Member
Joined
May 12, 2007
Messages
5
Programming Experience
Beginner
Ok, what am i doing wrong? I have a text box that the user enters employees names and when you press the write button it saves each name entered into the text box to a text file on seperate lines. When I hit the write button it locks up my computer. Help!!!

VB.NET:
Private Sub writeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles writeButton.Click
        ' writes the contents of the list box to a sequential access file

        Dim name As String = "Names"
        Dim path As String = "C:\Documents and Settings"

        If My.Computer.FileSystem.FileExists(path & "names.txt") Then
            My.Computer.FileSystem.WriteAllText(path & "names.txt", String.Empty, False)
        End If

        Do While name <> String.Empty
            nameTextBox = nameTextBox
            My.Computer.FileSystem.WriteAllText("names.txt", name & ControlChars.NewLine, True)

        Loop
    End Sub
 
VB.NET:
Dim name As String = "Names"
Do While name <> String.Empty
[COLOR="Red"][B]'means do this FOREVER[/B][/COLOR]
Loop
 
I don't want it to go on forever, but just need it to save when text is entered into the text box. How should I handle this?
 
set nameTextbox to multiline so user can write one name each line, then just write its Text property (not loop):
VB.NET:
My.Computer.FileSystem.WriteAllText("names.txt", nameTextBox.Text , False)
So this is then the only line of code you need in the button click event handler.
 
Back
Top