(1) The variable name must start with a letter or an underscore, and the middle of the name can only consist of letters, numbers and the underscore "_"; The last character can be a type descriptor;
(2) The length of variable name shall not exceed 255 characters;
(3) Variable names must be unique within the valid range. Effective range is the range where a program can recognize and use reference variables-such as a procedure, a form, and so on. The range of reference variables will be introduced later.
(4) Variable names cannot be reserved words (keywords) in VB, nor can they be reserved words with type descriptors at the end, but they can be embedded in variable names. Keywords refer to the system internal identifiers such as attributes, events, methods, procedures and functions in VB6. Such as defining words (if, endif, while, loop, etc. ) and function names (len, format, msgbox, etc. Like Print, Print$ is illegal, but Myprint is legal. For example: strName 1, intMax_Length, interless, strNo3, etc. Is a legal variable name, and a &;; B, ok, 3M, _Number, etc. Is an illegal variable name.
note:
(1) Variable names in VB are case-insensitive (such as abc, aBc, ABC, etc.). Case sensitivity in. c language. Different languages have different rules.
(2) When defining and using variables, it is usually necessary to define the variable name as a name that is easy to use and read, and can describe the usefulness of the data contained, instead of using some difficult abbreviations such as A or B2. For example, suppose you are laying out a software that sells apples for fruits. We need two variables to store Apple's price and sales. At this point, you can define two variables named Apple_Price and Apple_Sold. Every time you run the program, the user will provide specific values for these two variables, which looks very intuitive. The specific method is to form a meaningful variable name with one or more words to make the meaning of the variable clear. For example, the meaning of the variable name SalesTaxRate is much clearer than that of Tax or Rate.
(3) Mix uppercase and lowercase letters and numbers as needed. A reasonable protocol is to capitalize the first letter of each word in a variable, such as DateOfBirth.
(4) Another reasonable protocol is that each variable name starts with two or three character abbreviations, corresponding to the data type of the data to be stored in the variable. For example, use strName to explain that the Name variable holds string data. This naming method is called Hungarian nomenclature.
Format Variable Type+Variable Name
For example, strName str is the abbreviation of string, and Name is the name of the variable.
Note that the variable types are all lowercase, and the beginning of the variable name is uppercase.
C# naming method stringstrNameVB naming method DimstrNameasString doesn't need to care too much about the details of character abbreviations, but we should look at this convention in the future. Detailed information about this convention can be found in Visual Basic online help and many books on advanced programming of Visual Basic.