Solved

Define a private Structure within a class

Posted on 2004-08-24
4
294 Views
Last Modified: 2008-03-06
Folks:

My goal is to be able to create a private structure within a class.  What I have done so far is:

    Private Structure SESSION_STATUS
        Private chShortSessionName As Char
        Private strLongSessionName As String
        Private chSessionType As Char
        Private bSessionCharacteristics As Byte
        Private iNumRows As Int16
        Private iNumCols As Int16
        Private iHostCodePageNum As Int16
    End Structure

    Private MySession as SESSION_STATUS

    MySession.chSessionType = "X"
C:\john\VBScreenScrape1\HostSession.vb(396): 'VBScreenScrape1.MySession.SESSION_STATUS.chSessionType' is not accessible in this context because it is 'Private'.


my problem is - when I attempt to access the data items (example MySession.chSessionType) from within the class, I get a compile error telling me the data item is private.  I've attempted to change the protection of the structure members to protected - but that is not allowed.  My bet is if I change to public it will work - but I don't want any of that detail to be visible outside the class.

If my structure is private but data members public - will the data members be visible outside the class?

Is this the best way to achieve the behaviour I am after - ability to manipulate within the class - but invisible outside the class?  If not, what is?

0
Comment
Question by:jflanner
  • 2
4 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11885721
I think that to provide the best answer here, I would need to know what you are trying to accomplish by using a structure.  You can have a private structure that stores values for public properties, but you don't need them.  You could just define private fields:

Private _chShortSessionName As Char

Public Property ShortSessionName() As Char
  Get
     Return _chShortSessionName
  End Get
  Set(Value As Char)
     _chShortSessionName = Value
  End Set
End Property

Bob
0
 
LVL 3

Accepted Solution

by:
DJ_Back-Q earned 250 total points
ID: 11885737
   Private Structure SESSION_STATUS
        Private chShortSessionName As Char
        Private strLongSessionName As String
        Private chSessionType As Char
        Private bSessionCharacteristics As Byte
        Private iNumRows As Int16
        Private iNumCols As Int16
        Private iHostCodePageNum As Int16
    End Structure

To fix your problem change all the private of your property to public.

        Public chShortSessionName As Char
        Public strLongSessionName As String
        Public chSessionType As Char
        Public bSessionCharacteristics As Byte
        Public iNumRows As Int16
        Public iNumCols As Int16
        Public iHostCodePageNum As Int16

The problem occurs because in the dotnet environment, the structure is almost the same as a class. So by having the properties private, they are only accessible within the structure.

Andre, MCSD
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11885807
>> If my structure is private but data members public - will the data members be visible outside the class?

No they won't.

Idle_Mind
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 11885881
If the structure is private, then any variables declared of that type in your class must also be private and therefore not accessible outside the class.

Futhermore, anything outside the class will have no knowledge of the private structure inside the class.

Idle_Mind
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question