标题: [问题求助] 代码换位则无法正常输出 [打印本页]
作者: securite 时间: 2015-2-8 19:04 标题: 代码换位则无法正常输出
如下是正常的代码- Rem MaximeSkipLineToLookFor3GB.vbs
- Dim strSearch
- Dim strText
- Dim strFile
- Dim objFSO
- Dim objFile
- Const ForReading=1
- Const ForWriting=2
- Const ForAppending=8
- strFile="c:\kugou.ini"
- subLook
-
- Function funLookUp(strText,strSearch)
- Const blnInsensitive=1
- If Instr(1,strText,strSearch,blnInsensitive) Then
- funLookUp=strSearch & " was found"
- Else
- funLookUp=strSearch & " was not found"
- End If
- End Function
-
- Sub subLook
- Dim strLine
- Dim strText
- Dim intLine
- strSearch="["
- Set objFSO=CreateObject("Scripting.FileSystemObject")
- Set objFile=objFSO.OpenTextFile(strFile,ForReading)
-
- Do Until objFile.AtEndOfStream
- strText=objFile.ReadLine
- strLine=funLookUp(strText,strSearch)
- If InStr(strLine,"not") Then
- intLine=objFile.Line-1
- WScript.Echo intLine & " not at the beginning of the ini"
- Else
- intLine=objFile.Line-1
- Wscript.Echo intLine & " is the beginning of the ini"
- objFile.Close
- Exit Do
- End If
- Loop
- WScript.Echo "Opening the file a second time..."
- Set objFile=objFSO.OpenTextFile(strFile,ForReading)
- Do Until objFile.AtEndOfStream
- If objFile.Line < intLine Then
- objFile.SkipLine
- ElseIf objFile.Line=intLine Then
- WScript.Echo "The beginning of the ini file is: "
- WScript.Echo objFile.ReadLine
- Else
- WScript.Echo "The script is over"
- objFile.Close
- WScript.Quit
- End If
- Loop
- End Sub
复制代码
正确的输出是:
Microsoft (R) Windows Script Host Version 5.8
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
1 not at the beginning of the ini
2 not at the beginning of the ini
3 not at the beginning of the ini
4 not at the beginning of the ini
5 not at the beginning of the ini
6 not at the beginning of the ini
7 is the beginning of the ini
Opening the file a second time...
The beginning of the ini file is:
[ActiveTab]
The script is over
但是换一下,就是把sub函数中的第二个until循环放到外面,无法正常输出- Rem MaximeSkipLineToLookFor3GB.vbs
- Dim strSearch
- Dim strText
- Dim strFile
- Dim objFSO
- Dim objFile
- Const ForReading=1
- Const ForWriting=2
- Const ForAppending=8
- strFile="c:\kugou.ini"
- subLook
- Set objFSO=CreateObject("Scripting.FileSystemObject")
- Set objFile=objFSO.OpenTextFile(strFile,ForReading)
- WScript.Echo "Opening the file a second time..."
- Do Until objFile.AtEndOfStream
- If objFile.Line < intLine Then
- objFile.SkipLine
- ElseIf objFile.Line=intLine Then
- WScript.Echo "The beginning of the ini file is: "
- WScript.Echo objFile.ReadLine
- Else
- WScript.Echo "The script is over"
- objFile.Close
- WScript.Quit
- End If
- Loop
-
- Function funLookUp(strText,strSearch)
- Const blnInsensitive=1
- If Instr(1,strText,strSearch,blnInsensitive) Then
- funLookUp=strSearch & " was found"
- Else
- funLookUp=strSearch & " was not found"
- End If
- End Function
-
- Sub subLook
- Dim strLine
- Dim strText
- Dim intLine
- strSearch="["
- Set objFSO=CreateObject("Scripting.FileSystemObject")
- Set objFile=objFSO.OpenTextFile(strFile,ForReading)
-
- Do Until objFile.AtEndOfStream
- strText=objFile.ReadLine
- strLine=funLookUp(strText,strSearch)
- If InStr(strLine,"not") Then
- intLine=objFile.Line-1
- WScript.Echo intLine & " not at the beginning of the ini"
- Else
- intLine=objFile.Line-1
- Wscript.Echo intLine & " is the beginning of the ini"
- objFile.Close
- Exit Do
- End If
- Loop
-
- End Sub
复制代码
错误的输出
Microsoft (R) Windows Script Host Version 5.8
版权所有(C) Microsoft Corporation 1996-2001。保留所有权利。
1 not at the beginning of the ini
2 not at the beginning of the ini
3 not at the beginning of the ini
4 not at the beginning of the ini
5 not at the beginning of the ini
6 not at the beginning of the ini
7 is the beginning of the ini
Opening the file a second time...
The script is over
其中kugou.ini文件内容如下
Activate
Activate=1
DeepActivate=1
NewActivate=1
PlayCnt=12
[ActiveTab]
TabName=musicclub
[Collect]
NetConnectivity=1
[Crash]
LastCrashExe=
[DBCheck]
CommitError=0
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |