Results 1 to 5 of 5

Thread: What's With good for?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2000
    Location
    London, UK
    Posts
    145
    Hello!
    I've seen some ppl here using With, for instance
    With CommonDialog1
    .Flags = ...

    and so on.
    What's the point with this?
    Is there a special benefit with using With, and when should you use it?

    Thanks in advance,

    Pentax
    Wilhelm Tunemyr,
    Swede in London

    [email protected]

    "Dort, wo man Bücher verbrennt, verbrennt man am Ende auch Menschen"
    Heinrich Heine (1797-1856)

    Pravda vítezi!
    (Truth prevails!)

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You use with so that you don't have to type
    text1.bla1=..
    text1.bla2=..
    text1.bla3=..
    all the time, instead you type
    with text1
    .bla1=...
    .bla2=...
    .bla3=...
    end with

    You can do this for objects with properties, and UDT's
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

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

    <?>

    Saves repeditive typing:
    ie
    Data1.Recordset.movelast
    data1.recordset.addnew
    data1.recordset!myRec = text1
    data1.recordset.update

    or
    With data1.recordset
    .movelast
    .addnew
    etc.


    Late for dinner..I have to improve my typing speed.



    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    And using With ... is a bit quicker then accessing the same object over and over again.

  5. #5
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736

    Lightbulb

    You can also nest WITH statements when you are changing properties on a single object.

    "WITH" can help make your code look a little cleaner if you are making a lot of changes on one object.

    Instead of :

    Code:
    Private Sub Command1_Click()
        Text1.Height = 100
        Text1.Text = "Sample"
        Text1.Font.Bold = True
    End Sub
    Code:
    Private Sub Command1_Click()
        With Text1
            .Height = 100
            .Text = "Sample"
            With .Font
                .Bold = True
            End With
        End With
    End Sub
    And, as mentioned earlier, there is a slight performance gain in using WITH since the name of the object does not need to be requalified for each statement.

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