-
When is it really not necessecary to use With....End With...e.g. i use with functions such as
With Printer
.Orientation = printmode.dmOrientation
.PrintQuality = printmode.dmPrintQuality
.ColorMode = printmode.dmColor
.Copies = printmode.dmCopies
.PaperSize = printmode.dmPaperSize
.ScaleLeft = -0.5 * 1440
.ScaleTop = -0.5 * 1440
.CurrentX = 0
.CurrentY = 0
End With
but i wouldnt use it if tehre was only 3 or 4 items. Should i? What is the "standard" number of items that one should begin to use with and end with for?....does using it do anything more than save my hands some extra typing?
-
I usually use With...End With if there are more than 2 items.
-
Use it whenever you want
Once compiled it makes no difference whatsoever whether you use the block or not. (OK you caught me thats an ASSUMPTION however if it did make a difference, then how stupid would that be!)
I have even used it when there is only one line in the block, but it added readability to the code by allowing an otherwise long line of code to be shorter.
Mind you I do have a tendancy to name my classes somewhat descriptively... plus I don't like using the _ character to split lines for some reason. I think I am too used to C++, Java, Lisp in that respect :)
Cheers
Paul Lewis
-
<?>
Not everything is laid it stone..it's a preference thing.
Less typing..easy to follow.
-
Actually, With...End With is useful. So you don't have to type the whole thing out.
Code:
'Example:
RichTextBox1.Text = ""
RichTextBox1.SelText = "Hello World"
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
Can be easily typed short like this:
Code:
'Example:
With RichTextBox1
.Text = ""
.SelText = "Hello World"
.SelStart = 0
.SelLength = Len(.Text)
End With
-
In my opinion, it's more of a neatness and organization preference than a typing preference.
-
It's actually should speed up the code processing (atleast according to Micro$oft). When you use With statement, it referencing the object only once and then accessing it's properties and methods, where if you use object name explicitely, it referencing each time you call the object name.
-
Good to know Serge..
That info is good to know. Microsoft say it ought to be faster which is always a bonus.
Cheers
Paul