A.1. Disk I/O: ReadingThe "Open a File" button displays an Open File dialog window to allow users to select a file. Once you've selected a file, you will read its content and display it in a message box: '=================================================== ' Open a File '=================================================== Private Sub btnOpenFile_Click( _ ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles btnOpenFile.Click '---Create an OpenFileDialog to request a file to open--- Dim openFile1 As New OpenFileDialog() '---Initialize the OpenFileDialog to look for txt files--- openFile1.DefaultExt = "*.txt" openFile1.Filter = "Text Files|*.txt" '---Determine whether the user selected a file from the ' OpenFileDialog--- If (openFile1.ShowDialog() = _ System.Windows.Forms.DialogResult.OK) _ And (openFile1.FileName.Length > 0) Then '---Read the content of file--- MsgBox("Content of file: "&_ My.Computer.FileSystem.ReadAllText(openFile1.FileName)) End If End Sub |