Visual Basic Codes



-->

Microsoft develops samples and documentation that follow the guidelines in this topic. If you follow the same coding conventions, you may gain the following benefits:

Code Library C Implementation of Visual Basic 6 LTrim Function 1.8K views 2 comments 0 points Most recent by uDocProject March 2018 Beginner C/C Code Library C Implementation of Visual Basic 6 RTrim Function.

A Code Library for Programmers in Visual Basic: a collection of bitmap routines in visual basic: A College Library Management Software in Visual Basic: a colorpicker that uses websafe colors. In visual basic: A Complete Calculator in Visual Basic: a complete mmorpg engine - vbgore v1.0.0: A complete mmorpg engine - vbGORE v1.0.0 in Visual Basic. Typographic and Code Conventions Summarizes the way that keywords, placeholders, and other elements of the language are formatted in the Visual Basic documentation. Visual Basic Runtime Library Members Lists the classes and modules of the Microsoft.VisualBasic namespace, with links to their member functions, methods, properties, constants, and enumerations. Visual Basic Sample Codes Visual Basic 6 is a third-generation event-driven programming language first released by Microsoft in 1991. In VB 6, there is no limit of what applications you could create, the sky is the limit.

Visual basic code excel
  • Your code will have a consistent look, so that readers can better focus on content, not layout.

  • Readers understand your code more quickly because they can make assumptions based on previous experience.

  • You can copy, change, and maintain the code more easily.

  • You help ensure that your code demonstrates 'best practices' for Visual Basic.

Naming Conventions

  • For information about naming guidelines, see Naming Guidelines topic.

  • Do not use 'My' or 'my' as part of a variable name. This practice creates confusion with the My objects.

  • You do not have to change the names of objects in auto-generated code to make them fit the guidelines.

Layout Conventions

  • Insert tabs as spaces, and use smart indenting with four-space indents.

  • Use Pretty listing (reformatting) of code to reformat your code in the code editor. For more information, see Options, Text Editor, Basic (Visual Basic).

  • Use only one statement per line. Don't use the Visual Basic line separator character (:).

  • Avoid using the explicit line continuation character '_' in favor of implicit line continuation wherever the language allows it.

  • Use only one declaration per line.

  • If Pretty listing (reformatting) of code doesn't format continuation lines automatically, manually indent continuation lines one tab stop. However, always left-align items in a list.

  • Add at least one blank line between method and property definitions.

Commenting Conventions

  • Put comments on a separate line instead of at the end of a line of code.

  • Start comment text with an uppercase letter, and end comment text with a period.

  • Insert one space between the comment delimiter (') and the comment text.

  • Do not surround comments with formatted blocks of asterisks.

Program Structure

  • When you use the Main method, use the default construct for new console applications, and use My for command-line arguments.

Language Guidelines

String Data Type

  • Use string interpolation to concatenate short strings, as shown in the following code.

  • To append strings in loops, use the StringBuilder object.

Relaxed Delegates in Event Handlers

Do not explicitly qualify the arguments (Object and EventArgs) to event handlers. If you are not using the event arguments that are passed to an event (for example, sender as Object, e as EventArgs), use relaxed delegates, and leave out the event arguments in your code:

Unsigned Data Type

  • Use Integer rather than unsigned types, except where they are necessary.

Arrays

  • Use the short syntax when you initialize arrays on the declaration line. For example, use the following syntax.

    Do not use the following syntax.

  • Put the array designator on the type, not on the variable. For example, use the following syntax:

    Do not use the following syntax:

  • Use the { } syntax when you declare and initialize arrays of basic data types. For example, use the following syntax:

    Do not use the following syntax:

Use the With Keyword

When you make a series of calls to one object, consider using the With keyword:

Basic

Use the Try...Catch and Using Statements when you use Exception Handling

Do not use On Error Goto.

Visual Basic Codes

Use the IsNot Keyword

Use the IsNot keyword instead of Not...Is Nothing.

New Keyword

  • Use short instantiation. For example, use the following syntax:

    The preceding line is equivalent to this:

  • Use object initializers for new objects instead of the parameterless constructor:

Visual Basic Codes

Event Handling

  • Use Handles rather than AddHandler:

  • Use AddressOf, and do not instantiate the delegate explicitly:

  • When you define an event, use the short syntax, and let the compiler define the delegate:

  • Do not verify whether an event is Nothing (null) before you call the RaiseEvent method. RaiseEvent checks for Nothing before it raises the event.

Using Shared Members

Call Shared members by using the class name, not from an instance variable.

Use XML Literals

XML literals simplify the most common tasks that you encounter when you work with XML (for example, load, query, and transform). When you develop with XML, follow these guidelines:

Visual Basic Codes

  • Use XML literals to create XML documents and fragments instead of calling XML APIs directly.

  • Import XML namespaces at the file or project level to take advantage of the performance optimizations for XML literals.

  • Use the XML axis properties to access elements and attributes in an XML document.

  • Use embedded expressions to include values and to create XML from existing values instead of using API calls such as the Add method:

LINQ Queries

  • Use meaningful names for query variables:

  • Provide names for elements in a query to make sure that property names of anonymous types are correctly capitalized using Pascal casing:

  • Rename properties when the property names in the result would be ambiguous. For example, if your query returns a customer name and an order ID, rename them instead of leaving them as Name and ID in the result:

  • Use type inference in the declaration of query variables and range variables:

  • Align query clauses under the From statement:

  • Use Where clauses before other query clauses so that later query clauses operate on the filtered set of data:

  • Use the Join clause to explicitly define a join operation instead of using the Where clause to implicitly define a join operation:

Visual Basic Codes List

See also





Comments are closed.