Skip to main content
gamedev.net
🔒 Locked

VB.net - saving textfiles

Started by _Danneman_ May 15, 2004 at 8:38 PM 2 replies 1.9k views
Original Post
_Danneman_
_Danneman_
Im doing a really pathetic little app that basically only saves different texts into textfiles. Well, I thought Id go with VB.net. The following code (which I dont understand all that well) is crooked in some way, but I just cant figure out how. Can you help, please?
 '' SAVE FILE
    Private Sub MenuItem_Save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem_Save.Click

        Dim myStream As System.IO.StreamWriter
        Dim saveFileDialog1 As New SaveFileDialog

        saveFileDialog1.Filter = "txt files (*.txt)|*.txt"
        saveFileDialog1.FilterIndex = 2
        saveFileDialog1.RestoreDirectory = True

        If saveFileDialog1.ShowDialog() = DialogResult.OK Then

            '' HERES A COMPILER ERROR !! 
            myStream = System.IO.StreamWriter(saveFileDialog1.FileName)
            If Not (myStream Is Nothing) Then
                Dim myString As String
                myString = txt_Lektion().Text
                myStream.Write(myString)
                myStream.Close()
            End If
        End If

    End Sub

[/CODE]   
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac
Badmi
Badmi
I do not know much about VB.net but from what I know this may work:
myStream =new System.IO.StreamWriter(saveFileDialog1.FileName)
SiCrane
SiCrane
A StreamWriter class needs to be associated with a Stream class in order to function. In this case you should probably create a new FileStream object with the filename you get from the dialog, and pass the FileStream to the StreamWriter. ex:

Dim sb As New FileStream(saveFileDialog1.FileName, FileMode.OpenOrCreate)
Dim sw As New StreamWriter(sb)
_Danneman_
_Danneman_
Thanks for both replies. Actually, Badmi suggestion worked great. Just add a little "New"

Thanks again!
------------------------Why of course the people don’t want war. ... That is understood. But after all it is the leaders of the country who determine the policy, and it is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship ...Voice or no voice, the people can always be brought to the bidding of the leaders. That is easy. All you have to do is to tell them they are being attacked, and denounce the pac

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.