VB代码,打开txt文本并把内容显示在text控件里?

2024-11-29 17:14:40
推荐回答(2个)
回答1:

Private Sub Command1_Click()
x = "C:\Documents and Settings\stu\桌面\11.txt" '你要读取的TXT文件路径
Open x For Input As #1
Do While Not EOF(1)
Input #1, aa
Loop
Text1.Text = aa
End Sub

回答2:

添加一个CommandDialog

dim a as string, inputdata as string
commanddialog1.filename=""
commanddialog1.filter="*.txt|*.txt"
a=commanddialog1.filename
open a for input as #1
do while not EOF(1)
input #1,inputdata
loop
text1.text=inputdata & vbcrlf