InternetUnicodeHTMLCSSScalable Vector Graphics (SVG)Extensible Markup Language (xml) ASP.Net TOCASP.NetMiscellaneous Feature ASP.NET Scripting Visual Basic .NET TOCVB .NET Language Referencena VB.Net KeywordsVB.Net DataVB.Net Declared ElementVB.Net DelegatesVB.Net Object CharacteristicsVB.Net EventsVB.Net InterfacesVB.Net LINQVB.Net Object and ClassVB.Net Operators and ExpressionsVB.Net ProceduresVB.Net StatementsVB.Net StringsVB.Net XMLConstants and LiteralsVB .NET EnumerationsVB .NET Data Types Visual Basic VariableVB .NET Variable Declaration Draft for Information Only
Content
VB.NET Object Variables
VB.NET Object VariablesIn addition to storing values directly, a variable can refer to an object. You assign an object to a variable for the same reasons you assign any value to a variable:
Making Code ShorterYou can use object variables to shorten the code you have to type. The following example uses the full path of methods and properties to access a Control object. VB' Assume Me is a valid Form, or replace Me with a valid Form. Me.ActiveForm.ActiveControl.Text = "Test" Me.ActiveForm.ActiveControl.Location = New Point(100, 100) Me.ActiveForm.ActiveControl.Show() You can shorten this code, and speed up execution, if you use an object variable for the control. You should declare the object variable with the specific class that you intend to assign to it (Control in this case). Once you assign an object to the variable, you can treat it exactly the same as you treat the object to which it refers. You can set or retrieve the properties of the object or use any of its methods. The following example uses an object variable to simplify the code in the preceding example. VBDim ctrlActv As System.Windows.Forms.Control = Me.ActiveForm.ActiveControl ctrlActv.Text = "Test" ctrlActv.Location = New Point(100, 100) ctrlActv.Show() See also
How to: Speed Up Access to an Object with a Long Qualification PathIf 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. To speed up access to a heavily qualified object by assigning it to a variable
To speed up access to a heavily qualified object by using a With...End With block
See alsoSource/Reference©sideway ID: 200900007 Last Updated: 9/7/2020 Revision: 0 Ref: References
Latest Updated Links
|
Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Travel 7 Reference 79 Computer Hardware 251 Software Application 213 Digitization 32 Latex 52 Manim 205 KB 1 Numeric 19 Programming Web 289 Unicode 504 HTML 66 CSS 65 SVG 46 ASP.NET 270 OS 431 DeskTop 7 Python 72 Knowledge Mathematics Formulas 8 Set 1 Logic 1 Algebra 84 Number Theory 206 Trigonometry 31 Geometry 34 Calculus 67 Engineering Tables 8 Mechanical Rigid Bodies Statics 92 Dynamics 37 Fluid 5 Control Acoustics 19 Natural Sciences Matter 1 Electric 27 Biology 1 |
Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019