Vbscript 写线/读线
我正在尝试获取一个脚本来读取文件并显示内容。但是,我只需要在每个窗口显示5行。如何限制文件的显示Vbscript 写线/读线,vbscript,Vbscript,我正在尝试获取一个脚本来读取文件并显示内容。但是,我只需要在每个窗口显示5行。如何限制文件的显示 Set MyFile = fso.OpenTextFile(FileName, ForReading) Do While MyFile.AtEndOfStream <> True TextLine = MyFile.ReadLine MsgBox TextLine,0, "Student Information" Loop MyFile.Close 解决方
Set MyFile = fso.OpenTextFile(FileName, ForReading)
Do While MyFile.AtEndOfStream <> True
TextLine = MyFile.ReadLine
MsgBox TextLine,0, "Student Information"
Loop
MyFile.Close
解决方案:
我找到解决办法了!来了:
Set MyFile = fso.OpenTextFile(FileName, ForReading)
Do While MyFile.AtEndOfStream <> True
TextLine = textline & MyFile.ReadLine & VBCR
counter = counter + 1
if (counter mod 5 = 0) then
MsgBox TextLine,0, "Petar Moraliev"
textline = ""
end if
Loop
MsgBox TextLine,0, "Petar Moraliev"
MyFile.Close
您需要一个cnLines数组,例如5个元素来存储文件中的每个行范围。如果该环形缓冲区已满,请执行输出,例如MsgBox。最后要小心:缓冲区中还有行吗 代码:
Option Explicit
Const cnLines = 5
Dim nUB : nUB = cnLines - 1
Dim tsIn : Set tsIn = CreateObject("Scripting.FileSystemObject").OpenTextFile(".\23117849.txt")
Dim nIdx : nIdx = nUB
ReDim aLines(nUB)
Do Until tsIn.AtEndOfStream
nIdx = (tsIn.Line - 1) Mod cnLines
aLines(nIdx) = tsIn.ReadLine()
If nIdx = nUB Then
WScript.Echo Join(aLines, " * ") ' MsgBox Join(aLines, vbCrLf)
End If
Loop
tsIn.Close
If Not nIdx = nUB Then
ReDim Preserve aLines(nIdx)
WScript.Echo Join(aLines, " * ") ' MsgBox Join(aLines, vbCrLf)
End If
11行文件的输出:
cscript 23117849.vbs
1 * 2 * 3 * 4 * 5
6 * 7 * 8 * 9 * 10
11
设置MyFile=fso.opentextfilefilefilefilename,用于读取Do,而MyFile.AtEndOfStream True TextLine=TextLine&MyFile.ReadLine&VBCR counter=counter+1如果计数器mod 5=0,则MsgBox TextLine,0,Petar Moraliev TextLine=end如果循环MsgBox TextLine,0,Petar Moraliev MyFile。关闭