hereson 发表于 2013-1-27 05:12:00

BBS脚本的lib(vb script, telnet, bbs)

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
goUp = Chr(27) + "[A"
goDown = Chr(27) + "[B"
goRight = Chr(27) + "[C"
goLeft = Chr(27) + "[D"

Function ReconnectHost()
    LoginHost = 0
    Dim nScrH, strLine, strLeft, strRight, strKey
    '连接
    Dim outFlag
    outFlag = 0
    StermScript.Disconnect()
    Do
        StermScript.Reconnect()
        Dim i
        i = 10
        While ( i <> 0)
                'StermScript.Delay(100)
                If StermScript.IsConnected() Then
                    i = 0
                Else
                i = i-1
                End If
        Wend
        If Not StermScript.IsConnected() Then
            StermScript.Disconnect()
        Else
            outFlag = 1
        End if
    Loop Until ( outFlag = 1 )
End Function
'##############################################################
 
'************************************************************
'* Function: TrimAll(strIn)                                 *
'* Return Value:                                            *
'* 除去字符串中所有可能的空格,tab等                        *
'************************************************************
Function TrimAll(strIn)
 Dim s,c, i
 s = Trim(strIn) '去掉前后空格
 TrimAll = ""
 for i = 1 to Len(s)
  c = Mid(s, i, 1)
  If (Asc(c) = 9) Then
  Else
   TrimAll = TrimAll + c
  End if
 Next
End Function
 
'************************************************************
'* Function: ExpectCursor(ByRef str, ByVal TimeOut)         *
'* Return Value: True 出现   False 未出现                   *
'* 判断在一定时间内,光标所在行是否出现指定字符串           *
'************************************************************
Function ExpectCursor(ByRef str, ByVal TimeOut)
 Dim starttime
 starttime = Timer
 While (Not InStr(STermScript.GetBuffer(STermScript.GetCursorY()), str) > 0)
  STermScript.Delay (200)
  If (Abs(Timer - starttime) > TimeOut) Then
   ExpectCursor = False
   ' MsgBox (str + " not found, timeout")
   Exit Function
  End If
 Wend
 ExpectCursor = True
End Function

'************************************************************
'* Function: Expect(ByRef str, ByVal l, ByVal TimeOut)      *
'* Return Value: True 出现   False 未出现                   *
'* 判断在一定时间内,指定行是否出现指定字符串               *
'************************************************************
Function Expect(ByRef str, ByVal linenum, ByVal TimeOut)
 Dim starttime
 starttime = Timer
 While (Not InStr(STermScript.GetBuffer(linenum), str) > 0)
  STermScript.Delay (200)
  If (Abs(Timer - starttime) > TimeOut) Then
   Expect = False
   ' MsgBox (str + " not found, timeout")
   Exit Function
  End If
 Wend
 Expect = True
End Function

'************************************************************
'* Function: WaitUntil(ByRef str, ByVal TimeOut)            *
'* Return Value: True 出现   False 未出现                   *
'* 等待光标所在行是否指定字符串                             *

'************************************************************
Function WaitUntil(ByRef str, ByVal TimeOut)
    Dim starttime
    Dim strLine
 starttime = Timer
    Do
  If (Abs(Timer - starttime) > TimeOut) Then
   WaitUntil = False
   'MsgBox (str + " not found, timeout")
   Exit Function
  End If
        StermScript.Delay(100) '每次延时0.1秒
        strLine = StermScript.GetBuffer(STermScript.GetCursorY())
    Loop Until (InStr(strLine, str) > 0) '等待出现的字符串
   
    WaitUntil = True
End Function
页: [1]
查看完整版本: BBS脚本的lib(vb script, telnet, bbs)