VB提问(急)

来源:百度知道 编辑:UC知道 时间:2024/05/30 07:09:52
怎么在Text1.text里加入一个1.Txt(文本文件)
用ShowOpen来打开文件(文件不确定)

部件--添加--mircosoft common dialog control
一个text 一个按钮 代码如下
Private Sub Command1_Click()
Text1.MultiLine = True
CommonDialog1.ShowOpen
Open CommonDialog1.FileName For Input As #1
Do While Not EOF(1)
Line Input #1, s
Text1.Text = Text1.Text & s
Loop
End Sub

Dim A, S As String

Dim FreeNum As Integer
FreeNum = FreeFile
'Freenum表示一个空闲的文件号
open "D:\1.txt" for input as #FreeNum
'这步是打开“date.txt”,for input表示以输入方式(即读取文件)打开
Do Until eof(FreeNum) '循环,直到文件结尾。Eof函数用来判断文件是否读完
Line Input #FreeNum, A
S = S + A 'S用来保存整个文件
Loop
Close FreeNum

Text1.text = S

Private Sub Command1_Click()
Dim hFreeNumber As Integer
Dim tmp As String
hFreeNumber = FreeFile
Open "c:\a.txt" For Input As #hFreeNumber
While Not EOF(hFreeNumber)
Line Input #hFreeNumber, tmp
Text1.