vb,通过对话框让text显示的问题
来源:百度知道 编辑:UC知道 时间:2024/06/08 02:58:40
对话框我已经做好了,就差怎么让text上面显示了
Private Sub Command1_Click()
Dim path As String
On Error Resume Next
Me.CommonDialog1.Filter = "*.txt|*.txt"
Me.CommonDialog1.ShowOpen
path = Me.CommonDialog1.FileName
Dim tempString
Dim result As String
Open path For Input As #1
Do While Not EOF(1)
Line Input #1, tempString
result = result & tempString
Loop
Close #1
Me.Text1.Text = result
End Sub
我以前做过的程序是从指定的TXT文件中,逐行读取txt中的字符串,然后储存到一个数组中,最后将数组中的内容输出到3个TEXTBOX中.
只要将你从对话框中获得的文件路径替换我这里的文件路径就可以了.
Dim strInput(2) As String
Dim FileHandle As Long
Dim strFileName As String
Dim strBuffer As String
Dim i As Integer
i = 0
FileHandle = FreeFile
Open App.Path & "\test.txt" For Input As #FileHandle
Do While Not EOF(FileHandle)
Line Input #FileHandle, strBuffer
strInput(i) = strBuffer
i = i + 1
Loop
txtFirst.Text = strInput(0)