Library code snippets

With statement precedence

Given the choice of creating a With statement for use with an object or
an user-defined type (UDT), choose the object over the UDT. Because UDTs
are simple variables and not full-blown objects, they don't take the
same resource hit as objects do when you repeatedly access their
properties. For instance, consider the following code, which alters the
command button's settings when you click it:

Private Type TBtnSettings
    BgColor As Long
    FontSize As Integer
    Top As Integer
    Left As Integer
    Width As Integer
    Height As Integer
End Type
Private mOrigSettings As TBtnSettings

Private Sub Command1_Click()
With Command1
    .BackColor = vbGreen
    .Top = mOrigSettings.Top - 100
    .Left = mOrigSettings.Left - 100
    .Width = mOrigSettings.Width + 200
    .Height = mOrigSettings.Height + 200
    .FontSize = mOrigSettings.FontSize + 4
End With
End Sub


Here, we could have used the With statement to reduce the number of
times we needed to manually type 'mOrigSettings'. However, as we stated,
by using the With statement for Command1 instead, our code becomes much
more efficient.

Comments

  1. 01 Jan 1999 at 00:00

    This thread is for discussions of With statement precedence.

Leave a comment

Sign in or Join us (it's free).

ElementK Journals
AddThis

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

Want to stay in touch with what's going on? Follow us on twitter!