Change form height syntax

  • Thread starter Thread starter Woody Splawn
  • Start date Start date
W

Woody Splawn

I have a form who's height I would like to change in code. I would have
supposed something like the following would work but it does not:

Me.Size.Height = 292

I get "Expression is a value and therefore can not be the target of an
asignment"

What am I missing?
 
Woody Splawn said:
I have a form who's height I would like to change in code. I would have
supposed something like the following would work but it does not:

Me.Size.Height = 292

I get "Expression is a value and therefore can not be the target of an
asignment"

Use 'Me.Height = 292' instead.
 
Size is a class, not a simple structure. Try one of the following:

Me.Height = 292
or
Me.Size = new Size(Me.Size.Width, 292)
 
Hi Woody,

The documentation for Size says that you can get or set the Width and
Height, which is entirely reasonable. What it doesn't say is that you <can't>
when it's the Size of a Control!! The bit you're missing is informative
documentation!!

You can create a new Size and assign it in one go.
Me.Size = New Size (Me.Size.Width, 292)

But it's easier to say Huh! to the Size and just go for the Height

Me.Height = 292. ;-))

Regards,
Fergus.
 
Hi Rafael,

Size <is> a structure, but its fields are read-only in Controls, for some
reason.

Regards,
Fergus
 
Fergus Cooney said:
Size <is> a structure, but its fields are read-only in Controls,
for some reason.

Really? I think, the thing is that retrieving the Size returns a copy of the
Size (because it is a value type), and changing the property of the copy
doesn't make sense.
 
Fergus,

Fundamentally it is a class for sure. The question that, maybe, you are
trying to rise is that this class inherits System.ValueType, but that is a
long question.. They are not Pascal-like (VB6-like) structures.



And more. Size.Width and Size.Height are not read-only properties from Size.

The problem was that Woody was trying to access indirectly the Form.Size. It
can't.

Look at this code. It will work too:



Dim MySize as Size

MySize = Me.Size ' value assignment

MySize.Width = 294

Me.Size = MySize ' value assignment again





The indirect assignment uses a "temporary allocation" that will raise the
error:



Me.Size.Width = 294





Look at this topic from MSDN: "Expression is a value and therefore cannot be
the target of an assignment" from Visual Basic Reference Error Messages.
 
:-) nice and clean.... :-)

Armin Zingler said:
Really? I think, the thing is that retrieving the Size returns a copy of the
Size (because it is a value type), and changing the property of the copy
doesn't make sense.
 
Hi Rafael,

|| Fundamentally it [Size] is a class for sure.

For me a ValueType is not a class in the sense that it
is an embedded structure and a containing object has
(needs) no object reference to access it. No object.
No independant existance. To me it is not a class but
it is class-like in that it inherits from System.Object
and System.ValueType.

I imagine your definition of 'fundamentally' discounts the
above definition.

For me the lack of independent existence and object
reference are fundamental.


|| Size.Width and Size.Height are not read-only properties of Size.

True. Lol, it would be strange if they were.
I said that <in Controls> they are read-only.

|| Look at this topic from MSDN: "Expression is a
|| value and therefore cannot be the target of an
|| assignment" from Visual Basic Reference Error Messages.

The topic says
|| An expression occurs in a context that assigns a value to it.
|| Only writeable variables, properties, and array elements
|| can have values assigned to them during execution.

I'm not sure why you want me to read it. It says exactly what
I said but in more words - Size.Width and Size.Height are
read-only in [the context of] Controls.

|| The problem was that Woody was trying to access indirectly
|| the Form.Size. It can't.

I was aware of both those facts. Here's my challenge - and the
only bit of this that matters -

Can you say why? ;-)

Regards,
Fergus
 
Hi Rafael,

Challenge rescinded. I hadn't seen Armin's post at that point. Sorry - no
points to be scored - they've already been allocated. :-)

Regards,
Fergus.
 
Fergus,

First, review the OOP paradigm.

Other comments follow...



Fergus Cooney said:
Hi Rafael,

|| Fundamentally it [Size] is a class for sure.

For me a ValueType is not a class in the sense that it

See the framework reference...

is an embedded structure and a containing object has
(needs) no object reference to access it. No object.
No independant existance. To me it is not a class but
it is class-like in that it inherits from System.Object
and System.ValueType.

I imagine your definition of 'fundamentally' discounts the
above definition.

For me the lack of independent existence and object
reference are fundamental.

You are confused. To help you I just can say: the "structure" is an
abstraction.

The fact that you can't reference an object doesn't mean that it's not a
class instance (object again).

If you still concerned about it I suggest you to open another thread.

|| Size.Width and Size.Height are not read-only properties of Size.

True. Lol, it would be strange if they were.
I said that <in Controls> they are read-only.

hmmmm....

|| Look at this topic from MSDN: "Expression is a
|| value and therefore cannot be the target of an
|| assignment" from Visual Basic Reference Error Messages.

The topic says
|| An expression occurs in a context that assigns a value to it.
|| Only writeable variables, properties, and array elements
|| can have values assigned to them during execution.

Take a look again... indirect use, temporary allocation and, as you said,
value types... it's trivial...

I'm not sure why you want me to read it. It says exactly what
I said but in more words - Size.Width and Size.Height are
read-only in [the context of] Controls.

There is no read-only trouble. It's related to indirect access of value
type.


|| The problem was that Woody was trying to access indirectly
|| the Form.Size. It can't.

I was aware of both those facts. Here's my challenge - and the
only bit of this that matters -

Can you say why? ;-)

That's your challenge? Please....

Again. Temporary allocation; Value types and Indirect access.
 
:-) Gotcha! ;-)


Hey! I am working here!!! :-)


Fergus Cooney said:
Hi Rafael,

Challenge rescinded. I hadn't seen Armin's post at that point. Sorry - no
points to be scored - they've already been allocated. :-)

Regards,
Fergus.
 
Hi Rafael,

|| :-) Gotcha! ;-)

You have? How so?

|| Hey! I am working here!!! :-)

What do you mean?

Regards,
Fergus
 
Hi Rafael,

|| First, review the OOP paradigm.

How long is it going to take you to review the OOP paradigm?

|| Other comments follow...

Follow what?

Regards,
Fergus
 
Hi Rafael,

Lol. You'd know if I was angry - Brother, would you know!!

I'm mostly stirred up by unfairness and inconsiderate behaviour towards
others ('colleagues' or 'guests'). Only a very select few (three I think) have
discovered what it feels like to be in my sights when I'm really serious about
such an issue, though many, I guess, have watched.

I'm just getting tired - long day - I'm adding back the Hi and Regards so
you know that I'm not angry with you. ;-)

Regards,
Fergus
 
Back
Top