?
Solved

Define a private Structure within a class

Posted on 2004-08-24
4
Medium Priority
?
300 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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 86

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 86

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

771 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