By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,684 Members | 1,338 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,684 IT Pros & Developers. It's quick & easy.

Change form height syntax

P: n/a
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?

Nov 20 '05 #1
Share this Question
Share on Google+
19 Replies


P: n/a
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)
-----
Rafael Pivato
"Woody Splawn" <wo***@splawns.com> escreveu na mensagem
news:e0*************@TK2MSFTNGP10.phx.gbl...
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?

Nov 20 '05 #2

P: n/a
"Woody Splawn" <wo***@splawns.com> scripsit:
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.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>
Nov 20 '05 #3

P: n/a
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.
Nov 20 '05 #4

P: n/a
Hi Rafael,

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

Regards,
Fergus
Nov 20 '05 #5

P: n/a
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.

-------------------------------

Rafael Pivato

"Fergus Cooney" <fi******@tesco.net> escreveu na mensagem
news:e5**************@tk2msftngp13.phx.gbl...
Hi Rafael,

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

Regards,
Fergus

Nov 20 '05 #6

P: n/a
"Fergus Cooney" <fi******@tesco.net> schrieb

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.
--
Armin

Nov 20 '05 #7

P: n/a
:-) nice and clean.... :-)

"Armin Zingler" <az*******@freenet.de> escreveu na mensagem
news:%2****************@TK2MSFTNGP12.phx.gbl...
"Fergus Cooney" <fi******@tesco.net> schrieb

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.
--
Armin

Nov 20 '05 #8

P: n/a
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
Nov 20 '05 #9

P: n/a
Hi Armin,

Doh! ;-)

Regards,
Fergus
Nov 20 '05 #10

P: n/a
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.
Nov 20 '05 #11

P: n/a
Fergus,

First, review the OOP paradigm.

Other comments follow...

"Fergus Cooney" <fi******@tesco.net> escreveu na mensagem
news:OW**************@tk2msftngp13.phx.gbl...
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.

Regards,
Fergus

---------
Rafael Pivato
Nov 20 '05 #12

P: n/a
:-) Gotcha! ;-)
Hey! I am working here!!! :-)
"Fergus Cooney" <fi******@tesco.net> escreveu na mensagem
news:%2****************@TK2MSFTNGP09.phx.gbl...
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.

-------
Rafael Pivato
Nov 20 '05 #13

P: n/a
Hi Rafael,

|| :-) Gotcha! ;-)

You have? How so?

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

What do you mean?

Regards,
Fergus
Nov 20 '05 #14

P: n/a
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
Nov 20 '05 #15

P: n/a
don't feel angry... some day you will learn...

"Fergus Cooney" <fi******@tesco.net> escreveu na mensagem
news:uB***************@tk2msftngp13.phx.gbl...
Hi Rafael,

|| :-) Gotcha! ;-)

You have? How so?

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

What do you mean?

Regards,
Fergus

Nov 20 '05 #16

P: n/a
Sorry Fergus, I didn't want to make you feel so angry.

"Fergus Cooney" <fi******@tesco.net> escreveu na mensagem
news:u3**************@TK2MSFTNGP09.phx.gbl...
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

Nov 20 '05 #17

P: n/a
I'm not angry.

You don't say anything.

So ..

I'm just bored.

:-(
Nov 20 '05 #18

P: n/a
I'm not so angry.

You don't say anything.

That makes sense to me.

:-(
Nov 20 '05 #19

P: n/a
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
Nov 20 '05 #20

This discussion thread is closed

Replies have been disabled for this discussion.