0
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        'Using writer As System.IO.StreamWriter = New System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory), "Word List.Txt", True)
        Using writer As System.IO.StreamWriter = New System.IO.StreamWriter("C:\Users\Home\Desktop\lessons Word\Word List.Txt", True)
            Dim curLine As String = TextBox1.Text
            If (TextBox1.Text.Count > 1) Then
                curLine = ""
                For Each line As String In TextBox1.Text
                    curLine = curLine & "" & line
                Next
                curLine = curLine.Trim()
            End If
            writer.WriteLine(curLine)
        End Using

    End Sub

And i am write above code it is work but,if i active fist line and deactivate second line code not work,i want active fist line .he said cant find the path.

please help me

thank you

wansa

2
Contributors
3
Replies
30
Views
5 Months
Discussion Span
Last Post by tinstaafl
1

Your problem is you're not paying attention to what the New constructor for StreamWriter wants and what GetfolderPath is supplying. The constructors that accept a string, only accept one string, the full path of the file to open. GetFolderPath only supplies the path of the directory you specify, which, in your case, means that you need to specify the subfolder as well as the path delimiter:

Using writer As System.IO.StreamWriter = New System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\lessons Word\Word List.Txt", True)

On a side note, every time you concatenate a string(&), a new string is created, the old isn't added to. I would suggest either use, a StringBuilder or write each line to the file separately.

Edited by tinstaafl

0

Dear sir.
its working 100% thank you for your support.
thank you
wansa

Imports System.IO
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Using writer As System.IO.StreamWriter = New System.IO.StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory) & "\lessons Word\Word List.Txt", True)
            Dim curLine As String = TextBox1.Text
            If (TextBox1.Text.Count > 1) Then
                curLine = ""
                For Each line As String In TextBox1.Text
                    curLine = curLine & "" & line
                Next
                curLine = curLine.Trim()
            End If 
            writer.WriteLine(curLine)
        End Using
    End Sub

End Class

Edited by Karuna_2

Attachments work.JPG 64 KB
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.