vb如何读取多行txt文本?

2025-02-06 12:43:41
推荐回答(3个)
回答1:

1、对于文件的操作vb提供了open语句、print #语句、input #语句等语句来处理文件。

2、读取多行文本,可以使用Line input #语句,一行行读取,再连接在一起,这种方法对大一点txt文件效率不高。

3、下面提供一个高效率、一次性读入所有文本的vb6示例:

Private Sub Command1_Click()
  Dim r
  Open "d:\readme.txt" For Binary As #1
  r = StrConv(InputB(LOF(1), 1), vbUnicode)
  Close #1
  
  Debug.Print r
  
End Sub

回答2:

Dim str, sstr As String,password As String
str = "d:\pass.txt"
Open str For Input As #1
Do While EOF(1) = False
Line Input #1, sstr
password = password & sstr & vbcrlf '加一个回车
Loop
Close #1

回答3:

你把你的text设置为接受多行文件就行啦