IBM Lotus Symphony
|
将顺序文件中的字符串读入变量。
Line Input #FileNumber As Integer, Var As String
FileNumber:包含要读取数据的文件号。该文件必须已预先通过 Open 语句使用关键字 INPUT 打开。
var:存储结果的变量的名称。
使用 Line Input# 语句,可以将打开的文件中的字符串读入变量。逐行读取字符串变量,直到第一个回车符(Asc=13)或换行(Asc=10)。结果字符串中不会包含行末标记。
Sub ExampleWorkWithAFile
Dim iNumber As Integer
Dim sLine As String
Dim aFile As String
Dim sMsg as String
aFile = "c:\data.txt"
iNumber = Freefile
Open aFile For Output As #iNumber
Print #iNumber, "This is a line of text"
Print #iNumber, "This is another line of text"
Close #iNumber
iNumber = Freefile
Open aFile For Input As iNumber
While not eof(iNumber)
Line Input #iNumber, sLine
If sLine <>"" then
sMsg = sMsg & sLine & chr(13)
end if
wend
Close #iNumber
Msgbox sMsg
End Sub