472,952 Members | 2,223 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,952 software developers and data experts.

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

115 100+
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
0 2065

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

Similar topics

67
by: Steven T. Hatton | last post by:
Some people have suggested the desire for code completion and refined edit-time error detection are an indication of incompetence on the part of the programmer who wants such features. ...
13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
9
by: ckerns | last post by:
I want to loop thru an array of controls,(39 of them...defaults = 0). If value is null or non-numeric I want to assign the value of "0". rowString = "L411" //conrol name if (isNaN(eval...
17
by: Ange T | last post by:
Hi there, I'm having pain with the VB behind an Access form. The form is used to create reports in Excel based on the details entered in the form. This has always worked without error on my...
4
by: javatopia | last post by:
Hello, I am trying to show a Crystal Reports 10 Enterprise report in an ASP.NET page (C#). I can run the report via the admin console just fine. When I try to show the report, after setting up...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
2
by: Suresh | last post by:
Hello All, Can anyone help me with this error? I have developed an application using VB Express Edition. The backend being Oracle XE. The application is been published on the server, installation...
1
by: Chubbly Geezer | last post by:
I have an application that has previously been working correctly. However, having made some code changes today, the app still publishes correctly but when I try to run it I get the following...
22
by: subramanian100in | last post by:
Consider the following program #include <limits.h> #include <stddef.h> int main(void) { size_t size; size_t bytes = sizeof(size_t);
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.