Click here to Skip to main content
Rate this: bad
good
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
v2

1 solution

Rate this: bad
good
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.
  Permalink  
v2
Comments
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
   
no
 
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)

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Afzaal Ahmad Zeeshan 82
4 Sergey Alexandrovich Kryukov 75
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web04 | 2.8.1411022.1 | Last Updated 23 Jan 2013
Copyright © CodeProject, 1999-2014
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