Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to declare a structure in a class and how do you access it?

Status
Not open for further replies.

WomanPro

Programmer
Nov 1, 2012
180
GR
Hello everybody again,
Is it possible to create a class with a structure type variable? And how can I access it through the class???
I mean something like that. Or is the best way to declare in a simple way these 2 variables?

Structure CheckerBelongTo
Public UserChecker As Boolean
Public PcChecker As Boolean
End Structure

Thank you in advanced.
 
You could declare it in a class like:
Code:
Public Class Class1
    Public Structure CheckerBelongTo
        Public UserChecker As Boolean
        Public PcChecker As Boolean
    End Structure

End Class

And call it like this:
Code:
 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim myStruct As New Class1.CheckerBelongTo
        myStruct.UserChecker = True
        myStruct.PcChecker = False


 End Sub

Personally I would only have on "checker" variable. If UserChecker is True then it's the users, if it's false then it not the user so it's the PC's checker. Think that would make things simpler than make sure two different variables are set.
 
Thank you Randy once more, I was wandering if I can do something like that, but I don't know the way and if it's possible.
But it doesn't sound bad at the moment to do in simple way as you told me above!!!

Public Class Checker
Structure CheckerBelongTo
Public UserChecker As Boolean
Public PcChecker As Boolean
End Structure

Private m_Position As Byte
Public Sub New()
m_Position = 1
CheckerBelongTo. [highlight #8AE234]What I could say there? there are 2 methods, equals and referenceequals[/highlight]
End Sub

Public Sub New(ByVal Position As Byte)
m_Position = Position
End Sub

What about the structure?

Public Property Position() As Byte
Get
Return m_Position
End Get
Set(ByVal value As Byte)
m_Position = value
End Set
End Property

What about the structure like m_Position?
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top