方法1: Dim tReadStr As String Dim tFileNumber As IntegertFileNumber=FreeFile Open pFileName For Input As #tFileNumber Do Line Input #tFileNumber,tReadStr ……执行指令tReadStr…… Loop Until EOF(tFileNumber) Close #tFileNumber方法2:Dim tReadStr As String Set tFSO=CreateObject("Scripting.FileSystemObject") Set tF=OpenTextFile(pFileName,2,1) Do tReadStr=tF.ReadLine ……执行指令tReadStr…… Loop Until tF.AtEndOfStream tF.Close Set tF=Nothing Set tFSO=Nothing
line input #1,ss
从已打开的顺序文件中读出一行并将它分配给 String变量。语法Line Input #filenumber, varnameLine Input # 语句的语法具有以下几个部分:部分 描述
filenumber 必要。任何有效的文件号。
varname 必要。有效的 Variant 或 String 变量名。
说明通常用 Print # 将 Line Input # 语句读出的数据从文件中写出来。Line Input # 语句一次只从文件中读出一个字符,直到遇到回车符 (Chr(13)) 或回车–换行符 (Chr(13) + Chr(10)) 为止。回车–换行符将被跳过,而不会被附加到字符串上。
Dim tReadStr As String
Dim tFileNumber As IntegertFileNumber=FreeFile
Open pFileName For Input As #tFileNumber
Do
Line Input #tFileNumber,tReadStr
……执行指令tReadStr……
Loop Until EOF(tFileNumber)
Close #tFileNumber方法2:Dim tReadStr As String
Set tFSO=CreateObject("Scripting.FileSystemObject")
Set tF=OpenTextFile(pFileName,2,1)
Do
tReadStr=tF.ReadLine
……执行指令tReadStr……
Loop Until tF.AtEndOfStream
tF.Close
Set tF=Nothing
Set tFSO=Nothing