VB Code (II)

Source: Internet
Author: User

Automatically complete the encoding
Visual Basic can automatically populate statements, properties, and parameters, making it easier to write code. When you enter code, the editor enumerates the appropriate selections, statements, or function prototypes or values. You can access the Options dialog box from the Options command on the Tools menu, which is available on the Editor tab of the Options dialog box, deciding whether to allow or disallow the set values for each code.
When you enter a control name in your code, the Auto list member attribute highlights the Drop-down property sheet for this control (Figure 5.5). By typing the first few letters of the property name, the name is selected from the table, and pressing the TAB key completes this entry. This option is helpful when you cannot confirm what properties a given control has. You can still use the CTRL +j key combination to get this performance, even if you chose to prevent automatic list membership attributes.

The Automatic Quick Info feature displays the syntax of statements and functions (Figure 5.6). When a valid VisualBasic statement or function name is entered, the syntax immediately appears below the current line and its first argument is displayed in bold text. After you enter the first parameter value, the second argument appears, as well as in bold text. "Automatic Quick Info" can also be obtained by using the Ctrl+i key combination.

Bookmark
Bookmarks in the Code Editor can be used to mark some lines of code so that you can easily return those rows later. The switch to the bookmark switch and the command to navigate to the existing bookmark are available in the Edit, bookmark menu item, or edit toolbar.
For more information about how to use the various features of the Code Editor window using a combination of keys, see "Shortcuts for code windows."

Coding Basics
This section describes the code-writing mechanism, including how to break and merge lines of code, how to add comments, how to use numbers, and Visual Basic naming conventions.

Dividing a single line statement into multiple lines
You can divide long statements into multiple lines in the code window by using a continuation character (followed by an underscore). Because you use a continuation line, the code that is printed on your computer becomes readable. The following lines are divided into rows using a continuation character (_):
Data1.recordsource = _
"SELECT * from Titles, publishers" _
& "WHERE Publishers.pubid = Titles.pubid" _
& "and publishers.state = ' CA '"
Within the same line, no comment is added after the line continuation. There are certain limitations as to where the continuation of the line can be used.

Merge multiple statements onto the same line
Typically, there is a Visual Basic statement in a row without a statement non-terminal, but you can also put two or more statements on the same line, just to use a colon (:) to separate them.
Text1.Text = "Hello": Red = 255:text1.backcolor =
Red
However, to make it easier to read the code, it's best to put a single statement on one line.
For more information, see Appendix A, "Guidelines, restrictions, and file formats for Visual Basic."

Add a comment to your code
The example of reading this manual often encounters an annotation character ('). This symbol tells Visual Basic to ignore what is behind the symbol. These are the comments in the code snippet, both for the convenience of the developer and for other programmers who might be able to check the source code later. For example:
' This is from the left of the screen
' Start the comment.
Text1.Text = "hi!" ' Place in the text box
' Welcome words.
A note can be on the same line as the statement, and it can be written behind the statement or occupy an entire line. These two scenarios are demonstrated in the above code. Remember that you cannot connect annotations on the same line after the continuation of a line character.
Note You can add or remove annotation symbols from two or more lines of code by selecting the comment block or delete comment block button on the edit toolbar.

Understanding the Digital system
Most of the values in this document are in decimal (the cardinality is 10). However, it is sometimes more convenient to use hexadecimal numbers (cardinality 16) or octal numbers (cardinality 8). Visual Basic uses prefix &h to represent hexadecimal numbers, while &o represents octal numbers. The following table shows the decimal, octal, and hexadecimal representations of the same number.

It is not usually necessary to master the hexadecimal or octal number, because the computer can work with any numbers. However, for some tasks, some numbers are more appropriate than others, such as using hexadecimal numbers to set the color of screens and controls.

Naming conventions for Visual Basic
When you write Visual Basic code, you declare and name many elements (Sub and Function procedures, variables, constants, and so on). The names of the procedures, variables, and constants declared in Visual Basic code must follow these rules:
1. They must begin with a letter.
2. They may not contain embedded periods or type declaration characters (special characters that specify the data type).
3. They cannot exceed 255 characters. The names of controls, forms, classes, and modules cannot be longer than 40 characters.
4. They cannot have the same name as a restricted keyword.
The restricted keywords are the words used by visual Basic and are part of the language. These include predefined statements (such as If and Loop), functions (such as Len and Abs), and operators (such as OR and Mod).
For more information about the keyword table, see the Visual Basic 6.0 Language Reference Guide.
Forms and controls can have the same name as restricted keywords. For example, you can name a control as loop. However, you cannot reference the control in your code in the usual way because Visual Basic thinks that the Loop means a keyword. For example, the following code will have an error.
loop.visible = True ' ERROR.
To refer to a form or control that has the same name as a restricted keyword, you must qualify them or enclose them in square brackets []. For example, the following code will not go wrong.
MyForm.Loop.Visible = True ' with form name
' Limit it.
[Loop]. Visible = True ' square brackets
' played a role.
You can use square brackets in this way when you refer to forms and controls, but this is not possible when you declare a variable or procedure name that is not the same as a restricted keyword. The brackets can also be used to force Visual Basic to accept names provided by other types of libraries that conflict with restricted keywords.
Note Because typing square brackets is also a boring thing, you want to use less restrictive keywords as form or control names. However, if a new version of Visual Basic defines a new keyword that conflicts with an existing form or control, you can use this technique when updating code to use the new version.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.