description | title | ms.date | helpviewer_keywords | ms.assetid | |||||
---|---|---|---|---|---|---|---|---|---|
Learn more about: How to: Speed Up Access to an Object with a Long Qualification Path (Visual Basic) |
How to: Speed Up Access to an Object with a Long Qualification Path |
07/20/2015 |
|
3eb7657f-c9fe-4e05-8bc3-4bb14d5ae585 |
If you frequently access an object that requires a qualification path of several methods and properties, you can speed up your code by not repeating the qualification path.
There are two ways you can avoid repeating the qualification path. You can assign the object to a variable, or you can use it in a With
...End With
block.
-
Declare a variable of the type of the object that you are accessing frequently. Specify the qualification path in the initialization part of the declaration.
Dim ctrlActv As Control = someForm.ActiveForm.ActiveControl
-
Use the variable to access the object's members.
ctrlActv.Text = "Test" ctrlActv.Location = New Point(100, 100) ctrlActv.Show()
-
Put the qualification path in a
With
statement.With someForm.ActiveForm.ActiveControl
-
Access the object's members inside the
With
block, before theEnd With
statement..Text = "Test" .Location = New Point(100, 100) .Show() End With