InternetUnicodeHTMLCSSScalable Vector Graphics (SVG)Extensible Markup Language (xml) ASP.Net TOCASP.NetMiscellaneous Feature ASP.NET Scripting Visual Basic .NET TOCVB .NET Language ReferencenaVB.Net ElementsVB.NET Operators StatementComment Statements Draft for Information Only
Content
VB.NET Assignment Statements
VB.NET Assignment StatementsThe supporting VB.NET Assignment Statements are AddHandler, Declare, Enum, Erase, RemoveHandler, Set, = AddHandler StatementAssociates an event with an event handler at run time. SyntaxAddHandler event, AddressOf eventhandler Partsevent: The name of the event to handle. eventhandler: The name of a procedure that handles the event. RemarksThe AddHandler and RemoveHandler statements allow you to start and stop event handling at any time during program execution. The signature of the eventhandler procedure must match the signature of the event event. The Handles keyword and the AddHandler statement both allow you to specify that particular procedures handle particular events, but there are differences. The AddHandler statement connects procedures to events at run time. Use the Handles keyword when defining a procedure to specify that it handles a particular event. For more information, see Handles. Note For custom events, the AddHandler statement invokes the event's AddHandler accessor. For more information on custom events, see Event Statement. See alsoDeclare StatementDeclares a reference to a procedure implemented in an external file. Syntax[ <attributelist> ] [ accessmodifier ] [ Shadows ] [ Overloads ] _ Declare [ charsetmodifier ] [ Sub ] name Lib "libname" _ [ Alias "aliasname" ] [ ([ parameterlist ]) ] ' -or- [ <attributelist> ] [ accessmodifier ] [ Shadows ] [ Overloads ] _ Declare [ charsetmodifier ] [ Function ] name Lib "libname" _ [ Alias "aliasname" ] [ ([ parameterlist ]) ] [ As returntype ] Parts
RemarksSometimes you need to call a procedure defined in a file (such as a DLL or code resource) outside your project. When you do this, the Visual Basic compiler does not have access to the information it needs to call the procedure correctly, such as where the procedure is located, how it is identified, its calling sequence and return type, and the string character set it uses. The Declare statement creates a reference to an external procedure and supplies this necessary information. You can use Declare only at module level. This means the declaration context for an external reference must be a class, structure, or module, and cannot be a source file, namespace, interface, procedure, or block. For more information, see Declaration Contexts and Default Access Levels. External references default to Public access. You can adjust their access levels with the access modifiers. Rules
Data Type Rules
Behavior
Important If the external procedure runs outside the common language runtime (CLR), it is unmanaged code. When you call such a procedure, for example a Windows API function or a COM method, you might expose your application to security risks. For more information, see Secure Coding Guidelines for Unmanaged Code. See also
Enum StatementDeclares an enumeration and defines the values of its members. Syntax[ <attributelist> ] [ accessmodifier ] [ Shadows ] Enum enumerationname [ As datatype ] memberlist End Enum Parts
RemarksIf you have a set of unchanging values that are logically related to each other, you can define them together in an enumeration. This provides meaningful names for the enumeration and its members, which are easier to remember than their values. You can then use the enumeration members in many places in your code. The benefits of using enumerations include the following:
An enumeration has a name, an underlying data type, and a set of members. Each member represents a constant. An enumeration declared at class, structure, module, or interface level, outside any procedure, is a member enumeration. It is a member of the class, structure, module, or interface that declares it. Member enumerations can be accessed from anywhere within their class, structure, module, or interface. Code outside a class, structure, or module must qualify a member enumeration's name with the name of that class, structure, or module. You can avoid the need to use fully qualified names by adding an Imports statement to the source file. An enumeration declared at namespace level, outside any class, structure, module, or interface, is a member of the namespace in which it appears. The declaration context for an enumeration must be a source file, namespace, class, structure, module, or interface, and cannot be a procedure. For more information, see Declaration Contexts and Default Access Levels. You can apply attributes to an enumeration as a whole, but not to its members individually. An attribute contributes information to the assembly's metadata. Data TypeThe Enum statement can declare the data type of an enumeration. Each member takes the enumeration's data type. You can specify Byte, Integer, Long, SByte, Short, UInteger, ULong, or UShort. If you do not specify datatype for the enumeration, each member takes the data type of its initializer. If you specify both datatype and initializer, the data type of initializer must be convertible to datatype. If neither datatype nor initializer is present, the data type defaults to Integer. Initializing MembersThe Enum statement can initialize the contents of selected members in memberlist. You use initializer to supply an expression to be assigned to the member. If you do not specify initializer for a member, Visual Basic initializes it either to zero (if it is the first member in memberlist), or to a value greater by one than that of the immediately preceding member. The expression supplied in each initializer can be any combination of literals, other constants that are already defined, and enumeration members that are already defined, including a previous member of this enumeration. You can use arithmetic and logical operators to combine such elements. You cannot use variables or functions in initializer. However, you can use conversion keywords such as CByte and CShort. You can also use AscW if you call it with a constant String or Char argument, since that can be evaluated at compile time. Enumerations cannot have floating-point values. If a member is assigned a floating-point value and Option Strict is set to on, a compiler error occurs. If Option Strict is off, the value is automatically converted to the Enum type. If the value of a member exceeds the allowable range for the underlying data type, or if you initialize any member to the maximum value allowed by the underlying data type, the compiler reports an error. ModifiersClass, structure, module, and interface member enumerations default to public access. You can adjust their access levels with the access modifiers. Namespace member enumerations default to friend access. You can adjust their access levels to public, but not to private or protected. For more information, see Access levels in Visual Basic. All enumeration members have public access, and you cannot use any access modifiers on them. However, if the enumeration itself has a more restricted access level, the specified enumeration access level takes precedence. By default, all enumerations are types and their fields are constants. Therefore the Shared, Static, and ReadOnly keywords cannot be used when declaring an enumeration or its members. Assigning Multiple ValuesEnumerations typically represent mutually exclusive values. By including the FlagsAttribute attribute in the Enum declaration, you can instead assign multiple values to an instance of the enumeration. The FlagsAttribute attribute specifies that the enumeration be treated as a bit field, that is, a set of flags. These are called bitwise enumerations. When you declare an enumeration by using the FlagsAttribute attribute, we recommend that you use powers of 2, that is, 1, 2, 4, 8, 16, and so on, for the values. We also recommend that "None" be the name of a member whose value is 0. For additional guidelines, see FlagsAttribute and Enum. See also
Erase StatementUsed to release array variables and deallocate the memory used for their elements. SyntaxErase arraylist Parts
arraylist RemarksThe Erase statement can appear only at procedure level. This means you can release arrays inside a procedure but not at class or module level. The Erase statement is equivalent to assigning Nothing to each array variable. See alsoRemoveHandler StatementRemoves the association between an event and an event handler. SyntaxRemoveHandler event, AddressOf eventhandler Parts
RemarksThe AddHandler and RemoveHandler statements allow you to start and stop event handling for a specific event at any time during program execution. Note For custom events, the RemoveHandler statement invokes the event's RemoveHandler accessor. For more information on custom events, see Event Statement. See alsoSet StatementDeclares a Set property procedure used to assign a value to a property. Syntax[ <attributelist> ] [ accessmodifier ] Set (ByVal value [ As datatype ]) [ statements ] End Set Parts
attributelist
accessmodifier See Access levels in Visual Basic.
value
datatype
statements
End Set RemarksEvery property must have a Set property procedure unless the property is marked ReadOnly. The Set procedure is used to set the value of the property. Visual Basic automatically calls a property's Set procedure when an assignment statement provides a value to be stored in the property. Visual Basic passes a parameter to the Set procedure during property assignments. If you do not supply a parameter for Set, the integrated development environment (IDE) uses an implicit parameter named value. The parameter holds the value to be assigned to the property. You typically store this value in a private local variable and return it whenever the Get procedure is called. The body of the property declaration can contain only the property's Get and Set procedures between the Property Statement and the End Property statement. It cannot store anything other than those procedures. In particular, it cannot store the property's current value. You must store this value outside the property, because if you store it inside either of the property procedures, the other property procedure cannot access it. The usual approach is to store the value in a Private variable declared at the same level as the property. You must define a Set procedure inside the property to which it applies. The Set procedure defaults to the access level of its containing property unless you use accessmodifier in the Set statement. Rules
Behavior
See also
Source/Reference
©sideway ID: 200800009 Last Updated: 8/9/2020 Revision: 0 Ref: ![]() References
![]() Latest Updated Links
![]() ![]() ![]() ![]() ![]() |
![]() Home 5 Business Management HBR 3 Information Recreation Hobbies 8 Culture Chinese 1097 English 339 Travel 18 Reference 79 Computer Hardware 254 Software Application 213 Digitization 37 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-2025 Sideway . All rights reserved Disclaimers last modified on 06 September 2019