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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值