Attribute VB_Name = "Module1"
Option Explicit
Public Declare Function GetTickCount Lib "kernel32" () As Long
Public Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, _
ByVal ySrc As Long, ByVal dwRop As Long) As Long



Sub TimeDelay(DT As Long)
  Dim TT As Long
  TT = GetTickCount()
  Do
    DoEvents
    If GetTickCount - TT < 0 Then TT = GetTickCount
  Loop Until GetTickCount - TT >= DT
End Sub

'等待RS字串傳回，或是時間到達
'Comm是通訊元件名稱
'RS是欲等待的字元
'DT是最常的等待時間
'正常時傳回值是所得的完整字串，不正常時傳回值是空字串
Function WaitRS(Comm As MSComm, RS As String, DT As Long) As String
  Dim buf$, TT As Long
  buf = ""
  TT = GetTickCount
  Do
    buf = buf & Comm.Input
  Loop Until InStr(1, buf, RS) > 0 Or GetTickCount - TT >= DT
  If InStr(1, buf, RS) > 0 Then
    WaitRS = buf
  Else
    WaitRS = ""
  End If
End Function

 
