Real Software Forums
http://forums.realsoftware.com/

"With" or "Using" Statement?
http://forums.realsoftware.com/viewtopic.php?f=13&t=44747
Page 1 of 1

Author:  mamerica [ Tue Jul 17, 2012 9:50 am ]
Post subject:  "With" or "Using" Statement?

In VB, instead of typing:
MyControl.Left = 0
MyControl.Top = 100
MyControl. Etc

You can type:
With MyControl
.Left = 0
.Top = 100
.Etc
End With

Other languages have the "Using" key word for the same purpose.
Does Real Studio have anything like this?
Thanks

Author:  kermit [ Tue Jul 17, 2012 10:52 am ]
Post subject:  Re: "With" or "Using" Statement?

Not unless it made it into a very recent update and I missed it.

Personally, Im not a fan.
Although this saves a little typing, in the middle of a dense code block it is less than clear which object .left refers to.

If typing is an issue I prefer to create a local alias to the object.

So:

Dim c as control

c = MyControlWithAVeryLongName //almost the same as 'using MyControlWithAVeryLongName'
c.left = 100
c.top = 200
c.etc


The assignment of c to the control name takes one more character.
Each reference using c.left instead of .left uses one extra character
And there is no end with, saving 8 characters.


And the other beaty of this approach is that you can have 2 controls on the go at the same time without confusion


c = MyControlWithAVeryLongName
d = MyOtherControlWithAVeryLongName

c.left = 100
c.top = 200
d.left = c.left



.. you cant have two controls being 'used' in the same block of code as .left would be ambiguous.

Author:  Bob Keeney [ Tue Jul 17, 2012 11:00 am ]
Post subject:  Re: "With" or "Using" Statement?

No, Real Studio does not have With or Using. I missed it for about 3 months when I switched from VB6 but not much since then.

I too use a local alias if I am using an long name object a lot. Autocomplete is also generally good enough for me needs.

Author:  DaveS [ Tue Jul 17, 2012 4:33 pm ]
Post subject:  Re: "With" or "Using" Statement?

"USING" I can do without.... but for me... the addition of "WITH" would be the iceing on the cake...... would make the code SO MUCH cleaner.... but that my opinion.

Author:  pate [ Thu Aug 16, 2012 3:22 pm ]
Post subject:  Re: "With" or "Using" Statement?

I used to be in the "where's With statement" camp, but while the code may be cleaner looking, it is harder to read in bigger VB procedures that have the With and End With separateed by a lot of lines. Just my 2 cents as a long time VB6 programmer.

Author:  jlawrence [ Thu Aug 16, 2012 4:58 pm ]
Post subject:  Re: "With" or "Using" Statement?

Quote:
The assignment of c to the control name takes one more character.
Each reference using c.left instead of .left uses one extra character
And there is no end with, saving 8 characters.


LOL We had this exact same discussion almost a year ago to the day!!
http://forums.realsoftware.com/viewtopic.php?f=13&t=39881&p=222218&hilit=overhead#p222218

July 16, 2011 -> July 17, 2012!!!

and at the time I made the same point that you actually SAVE keystrokes in RS (you said 8, I said 10, I'll have to go back and count).

History really DOES repeat itself!! :lol: :lol:

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/