Results 1 to 8 of 8

Thread: With....End With

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2000
    Posts
    33

    Unhappy

    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?

  2. #2
    Guest
    I usually use With...End With if there are more than 2 items.

  3. #3
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    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

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Not everything is laid it stone..it's a preference thing.
    Less typing..easy to follow.
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  5. #5
    Guest
    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

  6. #6
    Guest
    In my opinion, it's more of a neatness and organization preference than a typing preference.

  7. #7
    Serge's Avatar
    Join Date
    Feb 1999
    Location
    Scottsdale, Arizona, USA
    Posts
    2,744
    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.

  8. #8
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    Good to know Serge..

    That info is good to know. Microsoft say it ought to be faster which is always a bonus.

    Cheers
    Paul


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width