Error : Value does not fall within the expected range VB.Net 2005

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • remya1000
    New Member
    • Apr 2007
    • 115

    #1

    Error : Value does not fall within the expected range VB.Net 2005

    i'm using VB.Net 2005 application program.

    i'm trying to convert VB6 code to VB.Net 2005. QSockB is DLL file.

    this is the code i used for VB6. This is code i'm using to create socket, when program runs... and when i hit start button it calls Q_SendHeader function.

    Code:
    Form1_Load(.....................
    
     Q_KDSPort = &H8000&
     Q_MyPort = Q_KDSPort + &H100&
     Q_Address = ADDRESS_ANY
     Q_CreateSocketPort
    Code:
    Module QSockB
    
        Declare Function QSOCKNETINIT Lib "QSockB" () As Long
    
        Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
              (ByRef hndSocket As Long, ByVal lngPort As Long, _
              ByVal szIPAddress As String) As Long
    
        Declare Function QSOCKSENDMESSAGEEX Lib "QSockB" (ByVal hndSocket As Long, ByVal lngPort As Long, ByVal szIPAddress As String, ByRef szData As Any, ByVal lngDataLength As Long) As Long
    
        
        Public Const ADDRESS_ANY As String = "AnyAddress"
    
        Structure KDS_HEADER
            Dim lngFunction As Long
            Dim lngSubFunction As Long
        End Structure
    
    
        Structure KDS_TRANSACTION_HEADER
            Dim lngTransactionNumber As Long
            Dim lngTerminalNumber As Long
            Dim lngDestination As Long
            Dim lngSystemTime As SystemTime
            Dim lngTableNumber As Long
            Dim lngServerId As Long
            Dim lngCourse As Long
            Dim lngReserved1 As Long
            Dim lngReserved2 As Long
            Dim lngReserved3 As Long
            Dim lngReserved4 As Long
            Dim lngReserved5 As Long
            Dim lngReserved6 As Long
            Dim lngReserved7 As Long
            Dim lngReserved8 As Long
            <VBFixedString(31)> Dim lpszServerName As String
            <VBFixedString(31)> Dim lpszCustomerName As String
            Dim lngFlags As Long
        End Structure
    
        Structure HEADER_MSG
            Dim Hdr As KDS_HEADER
            Dim Data As KDS_TRANSACTION_HEADER
        End Structure
    
        Public Function Q_CreateSocketPort()
            Dim ReturnCode As Long
    
         	  Q_CreateSocketPort = False
    
            ReturnCode = QSOCKNETINIT
    
            If ReturnCode = SOCK_ERROR_NONE Then
                 ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
                 If ReturnCode = SOCK_ERROR_NONE Then
                     Q_Connected = True
                     Q_CreateSocketPort = True
                 End If
            End If
        End Function
    
    
        Public Function Q_SendHeader(ByVal TransactionNumber, ByVal Terminal, ByVal VideoChannel, ByVal UniqueTableID, ByVal ServerID, ByVal Course As Long, ByVal ServerName, ByVal HoldName As String, ByVal TimeHeld As Date) As Long
            Dim Header As HEADER_MSG
    
      With Header.Hdr
             .lngFunction = RDS_FUNCTION_POS_VB
             .lngSubFunction = RDS_MESSAGE_HEADER
           End With
    
           With Header.Data
             .lngTransactionNumber = TransactionNumber
             .lngTerminalNumber = Terminal 'must be non-zero
             .lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
             .lngTableNumber = UniqueTableID
             .lngServerId = ServerID
             .lngCourse = Course
             .lngReserved1 = 0
             .lngReserved2 = 0
             .lngReserved3 = 0
             .lngReserved4 = 0
             .lngReserved5 = 0
             .lngReserved6 = 0
             .lngReserved7 = 0
             .lngReserved8 = 0
    
             ' We must Add a Chr(0) to the end of each string to NULL terminate
             If Len(Trim(ServerName)) > 0 Then
               .lpszServerName = Trim(ServerName) + Chr(0)
             Else
                .lpszServerName = Chr(0)
             End If
    
             If Len(Trim(HoldName)) > 0 Then
     .lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)        
             Else
                .lpszCustomerName = Chr(0)
             End If
    
         End With
    
          Q_SendHeader = QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
        End Function
    
    End Module


    this is the code i'm using for VB.Net 2005.

    This is code i'm using to create socket, when program runs... and when i hit button start, its calling Q_SendHeader function.

    Code:
    Public objQ As clsQSockB
    
    Private Sub Form1_Load(……………………………………
        objQ = New clsQSockB
        objQ.Q_KDSPort = &H8000&
        objQ.Q_MyPort = objQ.Q_KDSPort + &H100&
        objQ.Q_Address = clsQSockB.ADDRESS_ANY
        objQ.Q_CreateSocketPort()
    End Sub
    
    Private Sub btnStart_Click(………………………………
            objQ.Q_SendHeader(100, 33, 1, 100, 3, 1, "Server", 100, Now.Date)
    End Sub
    Code:
    Public Class clsQSockB
    
        Declare Function QSOCKNETINIT Lib "QSockB" () As Int32
        
        Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
              (ByRef hndSocket As Int32, ByVal lngPort As Int32, _
              ByVal szIPAddress As String) As Int32
    
        Declare Function QSOCKSENDMESSAGEEX Lib "QSockB" (ByVal hndSocket As Int32, ByVal lngPort As Int32, ByVal szIPAddress As String, ByVal szData As Object, ByVal lngDataLength As Int32) As Int32
    
        Public Q_Socket As Int32
        Public Q_MyPort As Int32
        Public Q_KDSPort As Int32
        Public Q_Address As String
    
        Public Const ADDRESS_ANY As String = "AnyAddress"
        
        Structure KDS_HEADER
            Dim lngFunction As Int32
            Dim lngSubFunction As Int32
        End Structure
    
        Structure KDS_TRANSACTION_HEADER
            Dim lngTransactionNumber As Int32
            Dim lngTerminalNumber As Int32
            Dim lngDestination As Int32
            Dim lngSystemTime As SystemTime
            Dim lngTableNumber As Int32
            Dim lngServerId As Int32
            Dim lngCourse As Int32
            Dim lngReserved1 As Int32
            Dim lngReserved2 As Int32
            Dim lngReserved3 As Int32
            Dim lngReserved4 As Int32
            Dim lngReserved5 As Int32
            Dim lngReserved6 As Int32
            Dim lngReserved7 As Int32
            Dim lngReserved8 As Int32
            <VBFixedString(31)> Dim lpszServerName As String
            <VBFixedString(31)> Dim lpszCustomerName As String
            Dim lngFlags As Int32
        End Structure
    
        Structure HEADER_MSG
            Dim Hdr As KDS_HEADER
            Dim Data As KDS_TRANSACTION_HEADER
        End Structure
    
        Public Function Q_CreateSocketPort() As Boolean
            Try
                Dim ReturnCode As Long
                'Attempt to initial QSockB.DLL
                ReturnCode = QSOCKNETINIT()
                If ReturnCode = SOCK_ERROR_NONE Then
                    ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
                    If ReturnCode = SOCK_ERROR_NONE Then
                        Q_Connected = True
                        Return True
                    End If
                End If
            Catch ex As Exception
                Return False
            End Try
        End Function
    
    
        Public Function Q_SendHeader(ByVal TransactionNumber As Object, ByVal Terminal As Object, ByVal VideoChannel As Object, ByVal UniqueTableID As Object, ByVal ServerID As Object, ByVal Course As Int32, ByVal ServerName As Object, ByVal HoldName As String, ByVal TimeHeld As Date) As Int32
            Try
                Dim Header As HEADER_MSG
    
                With Header.Hdr
                    .lngFunction = RDS_FUNCTION_POS_VB
                    .lngSubFunction = RDS_MESSAGE_HEADER
                End With
    
                With Header.Data
                    .lngTransactionNumber = TransactionNumber
                    .lngTerminalNumber = Terminal 'must be non-zero
                    .lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
                    .lngTableNumber = UniqueTableID
                    .lngServerId = ServerID
                    .lngCourse = Course
                    .lngReserved1 = 0
                    .lngReserved2 = 0
                    .lngReserved3 = 0
                    .lngReserved4 = 0
                    .lngReserved5 = 0
                    .lngReserved6 = 0
                    .lngReserved7 = 0
                    .lngReserved8 = 0
    
                    ' We must Add a Chr(0) to the end of each string to NULL terminate
                    If Len(Trim(ServerName)) > 0 Then
                        .lpszServerName = Trim(ServerName) + Chr(0)
                    Else
                        .lpszServerName = Chr(0)
                    End If
    
                    If Len(Trim(HoldName)) > 0 Then
                        .lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)
                    Else
                        .lpszCustomerName = Chr(0)
                    End If
    
                End With
    
                Return QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
                
            Catch ex As Exception
                Return -1
            End Try
        End Function
    End Class

    Creating Socket works fine. but when i call Q_SendHeader, getting error.

    Error i'm getting is
    Value does not fall within the expected range.
    when it reach this line in Q_SendHeader, its getting error...
    Return QSOCKSENDMESSAG EEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
    This works fine in VB6... but Q_SendHeader is not working in VB.Net 2005.

    anything wrong with the code... if you have any idea what's wrong with the code, please help me... please.....

    Thanks in advance.
Working...