[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Define a private Structure within a class

Posted on 2004-08-24
4
Medium Priority
?
301 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 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