Starting from the basic concepts and syntax, learning a language, especially now is a visual development, but I suggest not to drag several widgets first, instead, you must first understand the concepts, syntaxes, and specifications of the language.VB. NETAlthough it is very similar to the previous VB6 syntax, the current VB. NET is a brand new object-oriented language, so there are some differences between the two.
As we all know, now VB. net has fully supported various object-oriented features, and there are some other.. NET environment: inherit, overload, override attributes and methods, implement constructor and destructor, interface, Delegate, exception, namespace, assembly, feature programming, multithreading, sharing members. (We will gradually explore these features in subsequent notes .)
First, briefly describe the VB. NET syntax, although it is so similar to VB6. Therefore, VB. NET statements are a review of VB6 statements, but some statements are not found in VB6.
VB. NET statements include declaration statements, value assignment statements, condition statements, loop statements, array processing statements, exception statements, control flow statements, call statements, and lock statements.
Statement
Declaration in VB. NET and medium usually refers to the declaration of variables.
We use the dim modifier to declare local variables. You can still use const to modify the variable as a constant. Static is still valid as a description of static variables.
Declaration example (We will describe classes and arrays later)
The following is a reference clip:
Code:
- Const s as string = "hello" 'constant local variable
- Dim B as Boolean 'Rule local variable
- Static I as int32 'static local variable
Variable accessibility
The above three variables are all local variables. We know that local variables are visible only in the declared regions and cannot be accessed outside the scope, for those that require more access control, VB. NET provides richer modifier keywords.
Accessibility Modification
Description
Public
If the declared element is public, there is no restriction on the accessibility of the public element.
Private
Declared elements can only be accessed from the same module, class, or structure.
Protected
The declared element can only be accessed from the same class or the derived class of the class.
Friend
Declarative elements can be accessed from the same project, but cannot be accessed from outside the project.
Protected friend
The declared element can be accessed from a derived class, within the same project, or both.
Examples of accessibility (note the relationship between testb, testc and Testa)
The following is a reference clip:
Code:
- Public class Testa
- Public I as int32 = 100 'unlimited access
- Private s as string = "hello" 'accessible only by Testa
- Protected B as Boolean = true 'only Testa and Its Derived classes can access
- Friend d as double = 3.1415926 'can only be accessed by the same project class
- Protected friend l as long = 100000'
- End Class
- Public class testb
- Inherits Testa 'inherits Testa
- Public sub new ()
- Mybase. B = false
- Mybase. d = 3.14
- Mybase. I = 10
- Mybase. L = 10000
- End sub
- End Class
- Public class testc
- Public sub new ()
- Dim A as new Testa
- A. D = 3.14
- A. I = 10
- A. L = 1000
- End sub
- End Class
If you have the foundation of VB6, I believe it will soon be possible to transition to VB.net.