如何把txt文档中数据导入到 VB 的textbox中

2025-01-01 04:57:14
推荐回答(3个)
回答1:

首先你需要把文本框text1的Multiline属性设置为true,这样就可以换行了,点击按钮出现对话框,然后选择文件打开,读入它里边的内容Private Sub Command1_Click()With CommonDialog1
.DialogTitle = "打开"
.FileName = "" '打开当前工作路径
.MaxFileSize = 32767 '缓存区
.Filter = "文本文件 (*.txt)|*.txt"
.ShowOpen
End With
Open CommonDialog1.FileName For Input As #1Do While EOF(1)Line Input #1, Str
text1.Text = text1.Text & Str & vbCrLfLoopClose #1End Sub

回答2:

open "路径" for input as #1do while eof(1)line input #1,strtext1.text=text1.text & str & vbcrlfloopclose #1

回答3:

Open "test.txt" For Input As #1
Input #1, str1

Close #1text1.text=str1