我试图在一个平面文件中找到一个字段值,并根据该值设置一个变量。这是我的代码:
Set file = fso.OpenTextFile(DataFileName, 1)
do until file.AtEndOfStream
if StrComp(left(file.readLine, 3) , "H23") = 0 Then
WScript.Echo file.ReadLine
If StrComp(Split(file.readLine, "~")(4) , "1") = 0 Then
ExportMapName = "ExportMap_1"
Else
ExportMapName = "ExportMap_2"
End If
End If
loop
Wscript.Echo ExportMapName
但是,当它给我
ReadLine
值时,它显示 H24
就像,它直接跳过 H23
行。我确定我的循环嵌套不正确,但我找不到任何可以给我指导的地方。 TIA!
在
ReadLine
返回的 TextStream
对象上调用 OpenTextFile
会使读者前进到下一行。您的问题的简化说明:
do until file.AtEndOfStream
WScript.Echo file.ReadLine 'returns a line
WScript.Echo file.ReadLine 'returns the next line
loop
还要注意逻辑错误:如果第一个
ReadLine
是文件中的最后一行,则第二个ReadLine
会发生错误。