Advertisement
Guest User

CIA.bas

a guest
Oct 21st, 2016
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.97 KB | None | 0 0
  1. Attribute VB_Name = "CIA2"
  2. Option Explicit
  3. Public Chars As String, HCDChars As String
  4. Public Function CIA2Connect(ByVal IP As String) As Boolean
  5.     Dim MyTime As Long
  6.     '
  7.     FHZConnectorForm.Socket.Close
  8.     FHZConnectorForm.Socket.RemoteHost = IP
  9.     FHZConnectorForm.Socket.Connect
  10.     MyTime = Int(Timer)
  11.     Do
  12.         DoEvents
  13.         If MyTime > Int(Timer) Then
  14.             MyTime = MyTime - 86400 'catch daychange
  15.         End If
  16.         Sleep 10
  17.     Loop While FHZConnectorForm.Socket.State <> sckConnected And MyTime + 5 > Int(Timer)
  18.     If FHZConnectorForm.Socket.State <> sckConnected Then
  19.         CIA2Connect = False
  20.     Else
  21.         CIA2Connect = True
  22.     End If
  23. End Function
  24. Public Function SendCIA2Socket(sData As String, WaitFor As String, Optional CloseConnection As Boolean = True, _
  25.  Optional NoWait As Boolean = False) As Boolean
  26.     Dim MyTime As Long
  27.     Dim RetryCounter As Integer
  28.     Dim i As Integer
  29.     '
  30.     On Error Resume Next
  31.     Chars = ""
  32. RETRY:
  33.     For i = 1 To Len(sData)
  34.         FHZConnectorForm.Socket.SendData Mid(sData, i, 1)
  35.         DoEvents
  36.         If NoWait = False Then
  37.             Sleep 50
  38.         End If
  39.     Next i
  40.     'fhzconnectorform.socket.SendData sData
  41.     On Error GoTo 0
  42.     MyTime = Int(Timer)
  43.     Do
  44.         DoEvents
  45.         If MyTime > Int(Timer) Then
  46.             MyTime = MyTime - 86400 'catch daychange
  47.         End If
  48.         Sleep 10
  49.     Loop While InStr(Chars, WaitFor) = 0 And MyTime + 2 > Int(Timer)
  50.     'Debug.Print Chars
  51.     If InStr(Chars, WaitFor) = 0 Then
  52.         If RetryCounter < 3 Then
  53.             RetryCounter = RetryCounter + 1
  54.             GoTo RETRY
  55.         End If
  56.         SendCIA2Socket = False
  57.         If CloseConnection = True Then
  58.             FHZConnectorForm.Socket.Close
  59.         End If
  60.         Exit Function
  61.     Else
  62.         SendCIA2Socket = True
  63.         If CloseConnection = True Then
  64.             FHZConnectorForm.Socket.Close
  65.         End If
  66.     End If
  67. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement