我正在使用Visual Basic 2008 Express Edition,这对我来说很新。我有一个浏览按钮,我添加代码的方式是当我单击浏览按钮时浏览文件并在标签框中显示其路径。
同样,我希望我选择的文件的内容显示在文本框中。我使用以下代码:
Imports System.IO.StreamReader
Dim oReader As StreamReader
OpenFileDialog1.CheckFileExists = True
OpenFileDialog1.CheckPathExists = True
OpenFileDialog1.DefaultExt = "txt"
OpenFileDialog1.FileName = ""
OpenFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*"
OpenFileDialog1.Multiselect = False
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
oReader = New StreamReader(OpenFileDialog1.FileName, True)
RichTextBox1.Text = oReader.ReadToEnd
End If
但是我得到了该Imports
行的语法错误,并且StreamReader未声明。我该如何解决这个问题?