All pastes #405926 Raw Edit

Untitled

public text v1 · immutable
·published 2007-03-22 01:11 UTC
rendered paste body
Option Explicit

Private sOutbound As String, sInbound As String, sPosition As Long

Public Sub ClearOut()
    sOutbound = vbNullString
End Sub

Public Sub ClearIn(index As String)
    sInbound = vbNullString
    sPosition = 1
End Sub

Public Sub InsertBYTE(ByVal value As Byte)
    sOutbound = sOutbound & Chr$(value)
End Sub

Public Sub InsertWORD(ByVal value As Integer)
    Dim NewValue As String * 2
    CopyMemory ByVal NewValue, value, 2
    sOutbound = sOutbound & NewValue
End Sub

Public Sub InsertDWORD(ByVal value As Long)
    Dim NewValue As String * 4
    CopyMemory ByVal NewValue, value, 4
    sOutbound = sOutbound & NewValue
End Sub

Public Sub InsertBSTR(ByVal value As String)
    sOutbound = sOutbound & value
End Sub

Public Sub InsertCSTR(index As Integer, ByVal value As String)
    sOutbound = sOutbound & value & vbNullChar
End Sub

Public Sub SendData(index As Integer)
    If frmMain.wsBNCS(index).State = sckConnected Then
        frmMain.wsBNCS(index).SendData sOutbound
        sOutbound(index) = vbNullString
    End If
End Sub

Public Sub SendPacket(index As String, ByVal ID As Byte, Optional UseBNLS As Boolean = False)
    Dim NewValue As String * 2
    If UseBNLS = False Then
        If frmMain.wsBNCS(index).State = sckConnected Then
            CopyMemory ByVal NewValue, (Len(sOutbound) + 4), 2
            frmMain.wsBNCS(index).SendData Chr(&HFF) & Chr(ID) & NewValue & sOutbound
            'AddChat vbWhite, ">> BNCS: " & Hex(ID)
            'Debug.Print ">> BNCS: " & Hex(ID)
        End If
    Else
        If frmMain.wsBNLS.State = sckConnected Then
            CopyMemory ByVal NewValue, (Len(sOutbound) + 3), 2
            frmMain.wsBNLS.SendData NewValue & Chr(ID) & sOutbound
            'AddChat vbWhite, ">> BNLS: " & Hex(ID)
            'Debug.Print ">> BNLS: " & Hex(ID)
        End If
    End If
    sOutbound = vbNullString
End Sub

Public Sub SetData(ByVal value As String)
    sInbound = value
    sPosition = 1
End Sub

Public Function GetDATA(index As Integer) As String
    GetDATA(index) = sInbound
End Function

Public Function Skip(index As Integer, ByVal Bytes As Long)
    sPosition = sPosition + Bytes
End Function

Public Function GetBYTE(index As Integer) As Byte
    GetBYTE = Asc(Mid$(sInbound, sPosition, 1))
    sPosition = sPosition + 1
End Function

Public Function GetWORD(index As Integer) As Integer
    Dim NewValue As Integer
    CopyMemory NewValue, ByVal Mid$(sInbound, sPosition, 2), 2
    GetWORD(index) = NewValue
    sPosition = sPosition + 2
End Function

Public Function GetDWORD(index As Integer) As Long
    Dim NewValue As Long
    CopyMemory NewValue, ByVal Mid$(sInbound, sPosition, 4), 4
    GetDWORD(index) = NewValue
    sPosition = sPosition + 4
End Function

Public Function GetBSTR(index As Integer, ByVal value As Integer) As String
    GetBSTR(index) = Mid$(sInbound, sPosition, value)
    sPosition = sPosition + Len(GetBSTR(index))
End Function

Public Function GetCSTR(index As Integer) As String
    GetCSTR(index) = Split(Mid$(sInbound, sPosition), vbNullChar)(0)
    sPosition = sPosition + Len(GetCSTR(index)) + 1
End Function