Public Property Using structure

TheWizardofInt

Junior Contributor
Joined
Dec 31, 1969
Messages
333
Location
Orlando, FL
Code:
Private mVariable As struConditions

Public Structure struConditions
   Dim bVisible As Boolean
   Dim sUrl As String
End Structure

Public Property sVariable() As struConditions
        Get
            Return mVariable
        End Get
        Set(ByVal value As struConditions)
            mVariable = value
        End Set
End Property

Doesn't let me reset bVisible to True when I call

Class.sVariable.bVisible.Equals(True)

What am I doing wrong?
 
Equals is a method that checks if the calling objects value is the same as the value passed in as a parameter. Thus you are not actually assigning anything with that line of code. In theory the correct line of code would be
Visual Basic:
Class.sVariable.bVisible = True;
But this won't work because you cannot assign a value to the child of a value type in this manner. You will either have to change the structure to a class or you will have to create a new instance of the structure with the required fields set and assign sVariable as equal to that.
 
Why is it so critical that the thing you have as a struct be a struct? You've used 4 lines of code where you could use 1 if you would just make it a class. What happens if you have to change the value again? That's another extra 3 lines of code.

I'm just concerned that
1. You'll make mistakes (because more loc = more potential for bugs)
2. You're making things harder for yourself than they really need to be
 
Whilst its true it adds lines of code which can in turn lead to errors, changing the Stucture to a Class could be catastropic on the application in the short term. It is quite likely that elsewhere in their code TheWizardofInt has statements that would function differently if the value type is changed to a reference type.
 
I am creating a Control which is a table full of buttons

Each of the buttons can be valid or invalid at any time

And each of them can look different for each type of user
 
Back
Top