TheWizardofInt Posted August 17, 2006 Posted August 17, 2006 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? Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
mskeel Posted August 17, 2006 Posted August 17, 2006 http://msdn2.microsoft.com/en-us/library/5y6d545d.aspx Boolean.Equals is a check, not a set. Try Class.sVariable.bVisible = True to set the value of bVisible for sVariable to be true. Quote
Cags Posted August 17, 2006 Posted August 17, 2006 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 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
mskeel Posted August 17, 2006 Posted August 17, 2006 Right...becuase the value returned by sVariable would be a copy that was pushed onto the stack for this expression, not a pointer to mVariable. Becuase it's a value type, not a reference type. This is related to that other post you made a few weeks ago. Quote
TheWizardofInt Posted August 17, 2006 Author Posted August 17, 2006 Actually, I did this: Dim str As Class.struConditions str.bVariable = True str.sURL = "" Class.sVariable = str And that reset the variable Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
mskeel Posted August 17, 2006 Posted August 17, 2006 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 Quote
Cags Posted August 17, 2006 Posted August 17, 2006 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. Quote Anybody looking for a graduate programmer (Midlands, England)?
TheWizardofInt Posted August 17, 2006 Author Posted August 17, 2006 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 Quote Read the Fovean Chronicles Because you just can't spend your whole day programming!
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.