Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
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


VB
And RESPONSE_BUFF_SIZE is my constant   out side structure

Private Const RESPONSE_BUFF_SIZE As Byte = 200
Posted
Updated 23-Jan-13 3:16am
v2

1 solution

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.
 
Share this answer
 
v2
Comments
AnnuBhai 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 24-Jan-13 0:06am    
You're kidding right?

Just remove where it says Struct and replace it with Class!
AnnuBhai 24-Jan-13 0:10am    
no

i am try to say
wht d difference between class n struct
Dave Kreskowiak 24-Jan-13 0:38am    
You don't have the restrictions on defining arrays as member variables that you do if using a structure.
AnnuBhai 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900