Save and Write out a text file

Chrism2

New member
Joined
Mar 22, 2008
Messages
1
Programming Experience
Beginner
Despite some amount of searching, I've spent hours trying to get this right, but I'm failing horribly: Any help would be great, because it sounds so easy!

I have a form with some Textboxes on it.

txtLegal
txtPhone
txtFax

I want to be able to save the contents of these textboxes to a .txt file in the fashion:

legal = this is the legal transcript
phone = 001433 483838
fax = 001433 232322
...etc

I've been fiddling around for hours with Streamwriter, but I'm either getting an empty text file or a file called "1" with the info I need in it.

Heck, I'm lost. :-( Here's how far I have got....

VB.NET:
Private Sub butExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExport.Click

        'Dialog to Save



        Dim legal As String
        Dim phone As String
        Dim fax As String
        Dim gfx As String
        Dim url As String
        Dim FileName As String
        Dim sw As System.IO.StreamWriter

        legal = Me.legal.Text
        phone = Me.phone.Text
        fax = Me.fax.Text
        gfx = Me.gfx.Text
        url = Me.url.Text



        With SaveFileDialog1
            .Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                FileName = SaveFileDialog1.FileName



                sw.Write("legal =" & legal)
                sw.Write("phone =" & phone)
                sw.Write("fax =" & fax)
                sw.Write("gfx =" & gfx)
                sw.Write("url =" & url)

                sw.Close()

            End If

        End With

        Me.Close()

        frmEntry.Show()
    End Sub
End Class


Any help always appreciated!
 
use
VB.NET:
sw.WriteLine("legal =" & legal)
sw.WriteLine("phone =" & phone)
sw.WriteLine("fax =" & fax)
sw.WriteLine("gfx =" & gfx)
sw.WriteLine("url =" & url)

Not

VB.NET:
sw.Write("legal =" & legal)
sw.Write("phone =" & phone)
sw.Write("fax =" & fax)
sw.Write("gfx =" & gfx)
sw.Write("url =" & url)

And

VB.NET:
sw = New IO.StreamWriter(SaveFileDialog1.FileName)
VB.NET:
Imports System.IO
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExport.Click
'Dialog to Save



Dim legal As String
Dim phone As String
Dim fax As String
Dim gfx As String
Dim url As String
' Delete that --> Dim FileName as String
'Use sw instead of FileName
Dim sw As System.IO.StreamWriter

legal = Me.legal.Text
phone = Me.phone.Text
fax = Me.fax.Text
gfx = Me.gfx.Text
url = Me.url.Text



With SaveFileDialog1
.Filter = "Text files (*.txt)|*.txt|" & "All files|*.*"
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
'NOT FileName = SaveFileDialog1.FileName
sw = New System.IO.StreamWriter(SaveFileDialog1.FileName)


'Use WriteLine NOT Write
sw.WriteLine("legal: " & legal)
sw.WriteLine("phone: " & phone)
sw.WriteLine("fax: " & fax)
sw.WriteLine("gfx: " & gfx)
sw.WriteLine("url: " & url)

sw.Close()

MsgBox("File Export ok", MsgBoxStyle.OkOnly)
Else
MsgBox("File NOT Exportet ", MsgBoxStyle.Critical)

End If

End With


Dim a As String
a = MsgBox("Do you want to close your Application", MsgBoxStyle.YesNo)
If a = vbYes Then
Me.Close()
Else
frmEntry.Show()
End If


End Sub
End Class
 
Last edited by a moderator:
Back
Top