Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: VB.NET
Private Structure ResponseFrame
       Dim InPtr As Byte
       Dim Outptr As Byte
       Dim TxBuff(RESPONSE_BUFF_SIZE, 12) As Byte
       Dim TxIpAddress(RESPONSE_BUFF_SIZE) As String
       Dim TxPortNo(RESPONSE_BUFF_SIZE) As String
       Dim TxSize As Byte
   End Structure

in bold part i getting error

And RESPONSE_BUFF_SIZE is my constant   out side structure
Private Const RESPONSE_BUFF_SIZE As Byte = 200
Posted 23-Jan-13 4:15am
Edited 23-Jan-13 4:16am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

What error are you getting??
The first thing that comes to mind is that you cannot declare an array with a specified size as a structure member. You have to initialize the array in the constructor of the structure, but this is a bit of a hack because you must declare a New with a parameter, even if you don't use the parameter:
Private Structure ResponseFrame
    Dim InPtr As Byte
    Dim Outptr As Byte
    Dim TxBuff(,) As Byte
    Dim TxIpAddress() As String
    Dim TxPortNo() As String
    Dim TxSize As Byte
    ' dummy is never used
    Sub New(dummy As Integer)
        ReDim TxBuff(RESPONSE_BUFF_SIZE, 12)
        ReDim TxIpAddress(RESPONSE_BUFF_SIZE)
        ReDim TxPortNo(RESPONSE_BUFF_SIZE)
    End Sub
End Structure
Now, when you use the Struct, you have to new up an instance of the structure to get its New method to run:
    Dim myInstance As New ResponseFrame(0) ' Pass in dummy value
The second thing that comes to mind is that RESPONSE_BUFF_SIZE is not visible to the structure. Since it's Private, it's only visible to the container that it's defined in.
The better way around this is to convert the structure to a class since, in order to use it, you'll be treating the structure like a class anyway.
Chittaranjan Moolya at 23-Jan-13 23:31pm
thanx a lot for rply me
but how to use class
which will be better option for this
will u elaborates me
Dave Kreskowiak at 24-Jan-13 0:06am
You're kidding right?
Just remove where it says Struct and replace it with Class!
Chittaranjan Moolya at 24-Jan-13 0:10am
i am try to say
wht d difference between class n struct
Dave Kreskowiak at 24-Jan-13 0:38am
You don't have the restrictions on defining arrays as member variables that you do if using a structure.
Chittaranjan Moolya at 24-Jan-13 0:45am
thanx you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Advertise | Privacy | Mobile
Web03 | 2.8.150327.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100