- Option Explicit
-
- OpenBaidu GetRandomLine("k.txt")
-
-
-
- Sub OpenBaidu(sKey)
- Dim oShell
- Set oShell = CreateObject("WScript.Shell")
- oShell.Run "iexplore http://www.baidu.cn/s?wd=" + sKey
- Set oShell = Nothing
- End Sub
-
- Function GetRandomLine(sFile)
- Dim oFso, oFile, iLineNo
- Set oFso = CreateObject("Scripting.FileSystemObject")
- Set oFile = oFso.OpenTextFile(sFile)
- iLineNo = GetRandom(GetFileLineCount(sFile))
- Do Until oFile.AtEndOfLine
- If iLineNo = oFile.Line Then
- GetRandomLine = oFile.ReadLine
- Exit Do
- Else
- oFile.SkipLine
- End If
- Loop
- oFile.Close
- Set oFile = Nothing
- Set oFso = Nothing
- End Function
-
- Function GetFileLineCount(sFile)
- Dim oFso, oFile
- Set oFso = CreateObject("Scripting.FileSystemObject")
- Set oFile = oFso.OpenTextFile(sFile)
- While Not oFile.AtEndOfLine
- oFile.SkipLine
- Wend
- GetFileLineCount = oFile.Line
- oFile.Close
- Set oFile = Nothing
- Set oFso = Nothing
- End Function
-
- Function GetRandom(n)
- Randomize
- GetRandom = Int(Rnd * n + 1)
- End Function
复制代码
[ 本帖最后由 rat 于 2008-11-23 15:40 编辑 ] |