By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,652 Members | 1,358 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,652 IT Pros & Developers. It's quick & easy.

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

100+
P: 115
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.

Expand|Select|Wrap|Line Numbers
  1. Form1_Load(.....................
  2.  
  3.  Q_KDSPort = &H8000&
  4.  Q_MyPort = Q_KDSPort + &H100&
  5.  Q_Address = ADDRESS_ANY
  6.  Q_CreateSocketPort
  7.  
Expand|Select|Wrap|Line Numbers
  1. Module QSockB
  2.  
  3.     Declare Function QSOCKNETINIT Lib "QSockB" () As Long
  4.  
  5.     Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
  6.           (ByRef hndSocket As Long, ByVal lngPort As Long, _
  7.           ByVal szIPAddress As String) As Long
  8.  
  9.     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
  10.  
  11.  
  12.     Public Const ADDRESS_ANY As String = "AnyAddress"
  13.  
  14.     Structure KDS_HEADER
  15.         Dim lngFunction As Long
  16.         Dim lngSubFunction As Long
  17.     End Structure
  18.  
  19.  
  20.     Structure KDS_TRANSACTION_HEADER
  21.         Dim lngTransactionNumber As Long
  22.         Dim lngTerminalNumber As Long
  23.         Dim lngDestination As Long
  24.         Dim lngSystemTime As SystemTime
  25.         Dim lngTableNumber As Long
  26.         Dim lngServerId As Long
  27.         Dim lngCourse As Long
  28.         Dim lngReserved1 As Long
  29.         Dim lngReserved2 As Long
  30.         Dim lngReserved3 As Long
  31.         Dim lngReserved4 As Long
  32.         Dim lngReserved5 As Long
  33.         Dim lngReserved6 As Long
  34.         Dim lngReserved7 As Long
  35.         Dim lngReserved8 As Long
  36.         <VBFixedString(31)> Dim lpszServerName As String
  37.         <VBFixedString(31)> Dim lpszCustomerName As String
  38.         Dim lngFlags As Long
  39.     End Structure
  40.  
  41.     Structure HEADER_MSG
  42.         Dim Hdr As KDS_HEADER
  43.         Dim Data As KDS_TRANSACTION_HEADER
  44.     End Structure
  45.  
  46.     Public Function Q_CreateSocketPort()
  47.         Dim ReturnCode As Long
  48.  
  49.            Q_CreateSocketPort = False
  50.  
  51.         ReturnCode = QSOCKNETINIT
  52.  
  53.         If ReturnCode = SOCK_ERROR_NONE Then
  54.              ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
  55.              If ReturnCode = SOCK_ERROR_NONE Then
  56.                  Q_Connected = True
  57.                  Q_CreateSocketPort = True
  58.              End If
  59.         End If
  60.     End Function
  61.  
  62.  
  63.     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
  64.         Dim Header As HEADER_MSG
  65.  
  66.   With Header.Hdr
  67.          .lngFunction = RDS_FUNCTION_POS_VB
  68.          .lngSubFunction = RDS_MESSAGE_HEADER
  69.        End With
  70.  
  71.        With Header.Data
  72.          .lngTransactionNumber = TransactionNumber
  73.          .lngTerminalNumber = Terminal 'must be non-zero
  74.          .lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
  75.          .lngTableNumber = UniqueTableID
  76.          .lngServerId = ServerID
  77.          .lngCourse = Course
  78.          .lngReserved1 = 0
  79.          .lngReserved2 = 0
  80.          .lngReserved3 = 0
  81.          .lngReserved4 = 0
  82.          .lngReserved5 = 0
  83.          .lngReserved6 = 0
  84.          .lngReserved7 = 0
  85.          .lngReserved8 = 0
  86.  
  87.          ' We must Add a Chr(0) to the end of each string to NULL terminate
  88.          If Len(Trim(ServerName)) > 0 Then
  89.            .lpszServerName = Trim(ServerName) + Chr(0)
  90.          Else
  91.             .lpszServerName = Chr(0)
  92.          End If
  93.  
  94.          If Len(Trim(HoldName)) > 0 Then
  95.  .lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)        
  96.          Else
  97.             .lpszCustomerName = Chr(0)
  98.          End If
  99.  
  100.      End With
  101.  
  102.       Q_SendHeader = QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
  103.     End Function
  104.  
  105. End Module
  106.  


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.

Expand|Select|Wrap|Line Numbers
  1. Public objQ As clsQSockB
  2.  
  3. Private Sub Form1_Load(
  4.     objQ = New clsQSockB
  5.     objQ.Q_KDSPort = &H8000&
  6.     objQ.Q_MyPort = objQ.Q_KDSPort + &H100&
  7.     objQ.Q_Address = clsQSockB.ADDRESS_ANY
  8.     objQ.Q_CreateSocketPort()
  9. End Sub
  10.  
  11. Private Sub btnStart_Click(
  12.         objQ.Q_SendHeader(100, 33, 1, 100, 3, 1, "Server", 100, Now.Date)
  13. End Sub
  14.  
Expand|Select|Wrap|Line Numbers
  1. Public Class clsQSockB
  2.  
  3.     Declare Function QSOCKNETINIT Lib "QSockB" () As Int32
  4.  
  5.     Declare Function QSOCKOPENSOCKETEX Lib "QSockB" _
  6.           (ByRef hndSocket As Int32, ByVal lngPort As Int32, _
  7.           ByVal szIPAddress As String) As Int32
  8.  
  9.     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
  10.  
  11.     Public Q_Socket As Int32
  12.     Public Q_MyPort As Int32
  13.     Public Q_KDSPort As Int32
  14.     Public Q_Address As String
  15.  
  16.     Public Const ADDRESS_ANY As String = "AnyAddress"
  17.  
  18.     Structure KDS_HEADER
  19.         Dim lngFunction As Int32
  20.         Dim lngSubFunction As Int32
  21.     End Structure
  22.  
  23.     Structure KDS_TRANSACTION_HEADER
  24.         Dim lngTransactionNumber As Int32
  25.         Dim lngTerminalNumber As Int32
  26.         Dim lngDestination As Int32
  27.         Dim lngSystemTime As SystemTime
  28.         Dim lngTableNumber As Int32
  29.         Dim lngServerId As Int32
  30.         Dim lngCourse As Int32
  31.         Dim lngReserved1 As Int32
  32.         Dim lngReserved2 As Int32
  33.         Dim lngReserved3 As Int32
  34.         Dim lngReserved4 As Int32
  35.         Dim lngReserved5 As Int32
  36.         Dim lngReserved6 As Int32
  37.         Dim lngReserved7 As Int32
  38.         Dim lngReserved8 As Int32
  39.         <VBFixedString(31)> Dim lpszServerName As String
  40.         <VBFixedString(31)> Dim lpszCustomerName As String
  41.         Dim lngFlags As Int32
  42.     End Structure
  43.  
  44.     Structure HEADER_MSG
  45.         Dim Hdr As KDS_HEADER
  46.         Dim Data As KDS_TRANSACTION_HEADER
  47.     End Structure
  48.  
  49.     Public Function Q_CreateSocketPort() As Boolean
  50.         Try
  51.             Dim ReturnCode As Long
  52.             'Attempt to initial QSockB.DLL
  53.             ReturnCode = QSOCKNETINIT()
  54.             If ReturnCode = SOCK_ERROR_NONE Then
  55.                 ReturnCode = QSOCKOPENSOCKETEX(Q_Socket, Q_MyPort, Q_Address)
  56.                 If ReturnCode = SOCK_ERROR_NONE Then
  57.                     Q_Connected = True
  58.                     Return True
  59.                 End If
  60.             End If
  61.         Catch ex As Exception
  62.             Return False
  63.         End Try
  64.     End Function
  65.  
  66.  
  67.     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
  68.         Try
  69.             Dim Header As HEADER_MSG
  70.  
  71.             With Header.Hdr
  72.                 .lngFunction = RDS_FUNCTION_POS_VB
  73.                 .lngSubFunction = RDS_MESSAGE_HEADER
  74.             End With
  75.  
  76.             With Header.Data
  77.                 .lngTransactionNumber = TransactionNumber
  78.                 .lngTerminalNumber = Terminal 'must be non-zero
  79.                 .lngDestination = VideoChannel 'as defined in the KDS (Destination ID's)
  80.                 .lngTableNumber = UniqueTableID
  81.                 .lngServerId = ServerID
  82.                 .lngCourse = Course
  83.                 .lngReserved1 = 0
  84.                 .lngReserved2 = 0
  85.                 .lngReserved3 = 0
  86.                 .lngReserved4 = 0
  87.                 .lngReserved5 = 0
  88.                 .lngReserved6 = 0
  89.                 .lngReserved7 = 0
  90.                 .lngReserved8 = 0
  91.  
  92.                 ' We must Add a Chr(0) to the end of each string to NULL terminate
  93.                 If Len(Trim(ServerName)) > 0 Then
  94.                     .lpszServerName = Trim(ServerName) + Chr(0)
  95.                 Else
  96.                     .lpszServerName = Chr(0)
  97.                 End If
  98.  
  99.                 If Len(Trim(HoldName)) > 0 Then
  100.                     .lpszCustomerName = Left(Trim(HoldName), 30) + Chr(0)
  101.                 Else
  102.                     .lpszCustomerName = Chr(0)
  103.                 End If
  104.  
  105.             End With
  106.  
  107.             Return QSOCKSENDMESSAGEEX(Q_Socket, Q_KDSPort, Q_Address, Header, Len(Header))
  108.  
  109.         Catch ex As Exception
  110.             Return -1
  111.         End Try
  112.     End Function
  113. End Class
  114.  

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 QSOCKSENDMESSAGEEX(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.
Apr 30 '09 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.