如何读取一个文本文件啊,我的文本文件格式是:
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
如何循环一行一行的读取啊,执行完一行再读下一行。
高分求解
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
如何循环一行一行的读取啊,执行完一行再读下一行。
高分求解
dim s as string
hFile = FreeFile()
open "C:\temp\1.txt" for input as #hFile
while not eof(hfile)
Line Input #hFile, s
Debug.Print s
wend
close #hFile
Dim i As Long
Dim strFile As String
Dim arr() As String
Open "c:\1.txt" For Binary As #1
strFile = Space(LOF(1))
Get #1, , strFile
Close #1
arr = Split(strFile)
For i = 0 To UBound(arr) - 1
MsgBox arr(i)
Next i
End Sub
Private Sub Form_Load()
Dim a()
Open "C:\111.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve a(i)
Line Input #1, a(i)
MsgBox a(i) '一行
i = i + 1
Loop
Close #1
MsgBox Join(a(), vbCrLf) '全部
End Sub
Private Sub Command1_Click()
Dim fso As Object, fil As Object, iStr As String
Set fso = CreateObject("scripting.filesystemobject")
Set fil = fso.opentextfile("c:\1.txt")
While Not fil.AtEndOfStream
iStr = fil.ReadLine '一行一行读
Debug.Print iStr '一行一行显示
Wend
End Sub