MenuStrip click event

dinotom

Member
Joined
Sep 5, 2011
Messages
11
Programming Experience
3-5
I have a menu strip which I am trying to write the code for. It doesn't work for what reason I don't know when I click on the menu item.
Literally nothing happens. I put a breakpoint on the first line of code in the event handler and the debugger never got there.

    Private Sub RangeProjectionsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles RangeProjectionsToolStripMenuItem.Click        ' code here to open the file in the textbox
        Dim strFile As String = ""
        If DoesDriveExist("X:\") Then
            strFile = "X:\QueryTxtFiles\RangeProjections.txt"
        Else
            If Mapx() Then
                strFile = "X:\QueryTxtFiles\RangeProjections.txt"
            Else
                strFile = ""
            End If
        End If


        If File.Exists(strFile) Then
            Dim strText As String = File.Open(strFile, FileMode.Open).ToString()
            Debug.Print(strFile)
            tbTextDisplay.Text = strText
        Else
            tbTextDisplay.Text = "The requested file does not exist."
        End If
    End Sub
 
By the way, your method of reading a text file is very, very wrong. File.Open returns a FileStream. Calling ToString on that will just give you the name of the FileStream class, not the text contents of the file. If you want to read all the text from a file in one line then you should be calling File.ReadAllText. Also, displaying an error message in the same TextBox as the contents of a file is bad design.
 
Thanks for the suggestions.. The proper way is handled in one line of code
Private Sub RangeProjectionsToolStripMenuItem_Click(sender As System.Object, e As System.EventArgs) Handles RangeProjectionsToolStripMenuItem.Click

tbTextDisplay.Text = My.Computer.FileSystem.ReadAllText("X:\QueryTxtFiles\RangeProjections.txt")


End Sub
 
Back
Top