VB.NET - several small issues hoping to get cleared up

Asked By jenn on 17-Apr-10 05:30 PM
Fairly new at this and am using visual Studio 2008.

I am putting together my first little program and these are the issues I am running across during debug:

NotePad..the notepad that I put in I installed the OpenFileDialog Contoller..
in debug, the Open Option works and it will allow me to choose a txt doc..but on the Notepad, the file txt file that I chose for it to open- appears on my notepad as a bunch of blocks :(.

This is the code I have:

Private


Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

'Check if there's text added to the textbox


If TextBox1.Modified Then


'If the text of notepad changed, the program will ask the user if they want to save the changes


Dim ask As MsgBoxResult

ask = MsgBox(

"Do you want to save the changes", MsgBoxStyle.YesNoCancel, "Open Document")

If ask = MsgBoxResult.No Then

OpenFileDialog1.ShowDialog()

TextBox1.Text =

My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)

ElseIf ask = MsgBoxResult.Cancel Then


ElseIf ask = MsgBoxResult.Yes Then

SaveFileDialog1.ShowDialog()


My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, False)

TextBox1.Clear()


End If


Else


'If textbox's text is still the same, notepad will show the OpenFileDialog

OpenFileDialog1.ShowDialog()

TextBox1.Text =

My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)

End If


End Sub

I am wondering if anyone can tell me why or what I am doing wrong?

Do I need to maybe change some application settings on the OpenDialog1 Properties Box?? as I have left all of that at default..
Mohan Raj Aryal replied to jenn on 17-Apr-10 06:31 PM
Try something like this:

'Check if there's text added to the textbox
 
        If TextBox1.Modified Then
            'If the text of notepad changed, the program will ask the user if they want to save the changes
            Dim ask As MsgBoxResult
            ask = MsgBox("Do you want to save the changes", MsgBoxStyle.YesNoCancel, "Open Document")
            'If ask = MsgBoxResult.No Then
            '    OpenFileDialog1.ShowDialog()
            '    TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
            'ElseIf ask = MsgBoxResult.Cancel Then
 
            If ask = MsgBoxResult.Yes Then
                SaveFileDialog1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFileDialog1.FileName, TextBox1.Text, False)
                'TextBox1.Clear()
            End If
            TextBox1.Modified = False
        Else
            'If textbox's text is still the same, notepad will show the OpenFileDialog
            OpenFileDialog1.ShowDialog()
            TextBox1.Text = My.Computer.FileSystem.ReadAllText(OpenFileDialog1.FileName)
        End If

jenn replied to Mohan Raj Aryal on 17-Apr-10 07:26 PM

Mohan Raj Aryal  thank you I am going to use your code if you dont mind, LOL..for starters it is much neater than mine :)

my husband (who is a pc genius/tech) came over to see what I was gettin all excited about and so I showed him...LOL..the poor guy looks at me all funky like and says " it aint workin cuz your tryin to open a word doc in notepad...which is like trying to put a elephant into a volkswagon! LOL...so..there ya go heheheheee

thank ya so much for your help :)