1、vb_net简明使用手册(Vb_net concise manual)VB.NET concise manual VB.NET concise manualLiuVisual Basic.NET (VB.NET) is the next generation of VisualBasic, VB.NET will provide a first-class, object-oriented programming language, but also brings many new functions, such as inheritance implementation, overloadi
2、ng and parameterized constructor.In addition, as the language structure is adjusted, such as structured exception handling, code is easier to maintain, which enables developers to write highly scalable code using simple, clear free threads. VB will provide all the language features that developers n
3、eed to enable them to build stable, scalable distributed Web applications. At the same time, as the worlds most popular development software, to maintain the easy to use features.Whether youre a novice or a veteran VB programmer, VB.NET will enable you to create cutting-edge software for tomorrows i
4、nternet.First, the new characteristics of VB.NET(1) new functions related to object oriented programming(1) inheritance: programmers reuse code and data through inheritance. Reusing code that has been tested will greatly reduce the possibility of generating program Bug.(2) overloading: by using diff
5、erent parameter types, you can let programmers use sub processes or functions with the same name and different functions.(3) parameterized constructor: when you create a new instance, pass the parameter to it, simplifying the client code. (two) other new functions(1): free thread free thread provide
6、s asynchronous processing mechanism, the programmer can without affecting other applications, a new thread for long time task, complex queries or multi block synchronization calculation.(2) structured exception handling: using “Try“. Catch. “Finally“ statement, the programmer can insert exception pr
7、ocessing directly into the program without using “On Error“Goto“ statement.(3) detection: VB.NET generates compile errors for any type conversion that may cause runtime errors, so as to improve the security of type conversions.(4) shared members: data and function members that can be shared by all i
8、nstances of a class.(5) initialization function: VB.NET supports direct initialization of variable definition rows.At the same time, VB.NET also has garbage collection function; create server-side code; Web service strategy; through ADO.NET completely support XML format data sets and other new funct
9、ions.Two, VB.NET integrated development environment (IDE)Visual Studio.NET uses the same IDE, and the new tools provided in IDE are very comprehensive and powerful. Heres one by one:(1) Visual Studio main windowThis is the first interface that displays when you start VB.NET. The latest modifications
10、 are shown in the main window, and options for opening existing projects and creating new ones are provided. All options are displayed in hyperlinks.(two) new project (New Project) dialog boxProvides options for creating projects in any language. Divided into two columns: the left tree list lists se
11、veral programming languages, the VB node in the list is open, and the right icon displays several options for creating a new project. Notice that there are some new options, such as WebService, Web, Control, Library and ClassLibrary. The last option shows that in VB.NET, multiple related classes can
12、 be merged into a single module file.(three) the contents displayed in IDE when building or opening the project1. hidden tool boxThe tool box is hidden by default and can be pulled out by clicking its title“. For VB programmers, the biggest change here is that the controls in the tool box are now ve
13、rtically aligned, and each icon is written with a caption,Not like VB6 theres only one icon that way.2. card window (Tabbed Child Window)Visual Studio.NET takes advantage of the card window layout above the screen to replace the original MDI sub window layout. The card window includes: HomePage, for
14、m layout window, code window and help screen.3. task list (Task List)The task list is an important improvement that helps developers track all tasks that need to be completed. The code generator and compiler automatically add some content to the task list. Lets add task items manually:Find the code
15、that needs to be modified, insert a line with the beginning of the “TODO:“ notes, the task will automatically appear in the task list. Click “Task“In a task in List, the code editor will have the location to complete the task. This mechanism of defining tasks quickly and returning tasks will greatly
16、 improve the efficiency of development.4. program resource manager (Solution Explore)It replaces the original engineering resource manager (Project)Explorer). Program Explorer displays all the resources that are needed for the project, including code blocks written in other languages and various non
17、 code resources. Among them, “References“ is a new form of resource in the program explorer. “References“ manages the namespace of VB.NET, similar to VBComponent references in 6.5. attribute window (Properties)The property window is similar to VB 6, but it supports more layout patterns (display mode
18、). The “Anchor“ property of the following sample control and the use of the “Dock“ property:Most VB.NET controls contain “Anchor“ and “Dock“ attributes. The “Anchor“ property can force one or more edges of the control to keep a fixed distance from the edge of the form. Next, create an application th
19、at adds a text box at the bottom of the form to stretch with the size of the form. Steps are as follows:(1) add a text box to the form.(2) click on the “TextBox1“ control to see its “Anchor“ attribute. By default, “Anchors“ is in the upper left corner, that is, it keeps a fixed distance from the top
20、 and left edges of the form.(3) modify the “Anchor“ attribute: do not select “Top“ (top), and select “Left“ (left), “Right“ (right) and “Bottom“ (bottom). The property text is changed to “BottomLeftRight“. That is to say, the control will keep a fixed distance from the form at the bottom, left and r
21、ight.(4) press F5 to run the program and adjust the size of the form to enjoy your results.The “Dock“ attribute is also very important, and it is similar to the “Align“ attribute of some controls in VB 6. It forces specific controls to be fixed on one side of the form, or with the “Fill“ option to c
22、over the entire form.6. forms layout toolbar (Form Layout)In VB 6, the task of arranging controls on a form is called “Form“ by a nameThe toolbar for Editor is complete. The new toolbar of VB.NET provides more functionality, and defaults to open in WinForms type projects.7. code editorIn this window
23、, click the “+“ or “-“ number on the left of the code line, which can extend or fold the code block to hide the code unrelated to the current task.8.VB.NETs form engineVB.NET uses all of the Windows Forms engines that are based on the CLR language. It has many outstanding advantages. Such as: Window
24、sForms supports the creation of a form that automatically changes the size of a component, allows the anchor to be anchored to a specific location of the form, and creates a transparent form. The following example creates a WindowsForms (form),Steps are as follows:(1) start VB.NET. Click “New Projec
25、t“ on the start page“.(2) under the “Visual Basic Projects“, select “Windows Application“.(3) modify the name and location of the name if necessary. Click the “OK“ button, and youll see a Windows form.All VB code, either form or class module, is stored as a.Vb file. The code in the file describes wh
26、at it is and what it does.Click Form1 to browse the property window: here and VB6 compared to some changes, title attributes are now called text (Text), font attributes are divided into name and font size, and there is a “IsMDIContainer“ attribute for building MDI applications. Note: the “.Caption“
27、attribute disappears in VB.NET, and they are normalized to “.Text“, and the “.Tag“ attribute disappears.9. commonly used controls in the toolboxVB.NET binds a common control: Button (button) (corresponding to the previous CommandButton),RadioButton (check button) (corresponding to the previous Optio
28、nButton), GroupBox (corresponding to the previous Frame). And of courseTextBox (Wen Benkuang), CheckBox (Dan Xuankuang), PictureBox (Graphic box), ListBox (listbox) and ComboBox (combo box).Note: in VB.NET, the Shape control is missing. Adding graphics to the form will use the “System.Drawing.Graphi
29、cs“ namespace, that is, “code drawing.“.10. new controlsVB.NET provides some controls that have never been seen before. Lets take a look at the most important ones.(1) MainMenu (main menu) control: This is the previous Menu Builder (menu generator). The following example shows how to create a new me
30、nu using “MainMenu“:Add MainMenu controls to the form.In the form, click to display the following content: Type Here (type here); type: click in the “Type Here“ box, expand it to the right of “File“, and add some menus.According to F5, run the application program and test the new menu. And then, lik
31、e VB 6, add code to these menu items.Note: when you add an interval to the menu, you can type a single dash.(2) LinkLabel control: implement hyperlink. Add a “LinkLabel“ control to the form, press F5 to run and test the new “LinkLabel“.The running result looks like a hyperlink to a Web page. By defa
32、ult, it is underlined blue, and when the mouse passes it, it changes into the shape of the hand, and it changes color when clicked. But by default, it is not linked to a site, and when clicked, the code for the Click event runs.Note: through the “LinkBehavior“ attribute settings option, you can get
33、more effects of “LinkLabel“.(3) ErrorProvider control: if there is a confirmation error, it will automatically highlight the control with an icon.(4) other new controls: VB.NET also adds ToolTip (tooltip) controls, WindowsThe open and saved dialog box will now be used as a built-in control. TrayIcon
34、 control makes it easier to add custom icons and menus to the system tray. The HelpProvider control makes it easy to access help files.Three, VB.NET basic grammar(1) variables and constantsVB.NET uses variables to store values, and variables have names and data types. The array is used to store the
35、set of related variables that have been indexed.OneThe data type of the variable (as shown in the following table)(map)In order to match the data type of VB with the data types of other.NET languages, Microsoft modifies the representation of integer class data types and adds a new data type. These c
36、hanges are especially important for external calls (such as API calls). For example, if the calling function requires a 32 bit integer parameter, it is in VBIn 6, it should be declared as Long, and should be declared as Integer in VB.NET. As shown in the following table.(map)The naming of 2. variabl
37、esNaming rules for variables:Must start with letters; cannot contain embedded statements or embedded type declaration characters; not more than 255 characters; must be unique within the same range.Declaration of 3. variablesVB.NET has changed compared to the VB 6 declaration format:Dim variablename
38、as typeSuch as: Dim strS1 as StringDim intX as IntegerThe new declaration method is shown in the table below.(map)The role of the 4. keyword in the definition of variables (as shown in the table below)(map)(two) constantConstant is a constant quantity in program operation. There are two kinds of con
39、stants: one is the constant declared by the user, and the other is the constant supplied by the system.1. user declare constantFormat: Const constant name As type = expression, such as:Const PI=301415926 declares constant PI, representing 3.14159, single precision type2. constants provided by the sy
40、stemThe constants provided by the system are located in the object library. Using constants makes the program easier to read and write, and makes the program compatible in different versions.(three) operatorThe operators in VB.NET can be divided into four categories: arithmetic operator, string oper
41、ator, relational operator and logical operator.1. arithmetic operatorVB.NET (power), including - (minus), * (x) / (in addition), (divisible), Mod (modulo), + (plus), - (minus) is the operator.The new operator: VB.NET brings some new mathematical operators, thus reducing the code. Such as VB.NET in t
42、he “X = 4 and X = X + VB 6“4 is the same effect. Other such as: “X-= 10, X = 2, X / = 13“, “X, =13“ and “X 3“, “X if the two operands are character type, then the ASCII code values of the characters are compared from left to right;The precedence of relational operators is the same.4. logical operato
43、rsThe logical operator, except Not, is a unary operator, and the rest is a binocular operator. The function is to operate operands logically, and the result is the logical value True or False. As shown in the following table:(map)The logical operators have the following functions when they are used
44、to do numerical operations:The And operation used to shield some; Or operation is used in certain positions on a number of 1; two consecutive Xor operation, can restore the original value.(four) expressionComposition of 1. expressionsIt consists of variables, constants, operators and parentheses acc
45、ording to certain rules. After an operation, the expression has a result. The type of the result is determined by the data and the operator.The writing rules of 2. expressionsMultiplication can not be omitted; brackets must be in pairs, using parentheses; expressions written from left to right in th
46、e same standard, no height, size;3. priorityArithmetic operators and logical operators have different priorities, and the relational operators have the same priority. Different types of operator precedence are as follows:Arithmetic operator relational operator logical operatorNote: for multiple oper
47、ators, parentheses can be added to change the priority or make the expression clearer.(five) VB.NET new grammarThere are many grammatical changes in the VB.NET language. In addition to the list listed above, here are some of these. The table does not list all the changes, but lists some of the most
48、important changes.1. grammatical contrastThe following table compares some familiar grammatical forms in VB 6 and the closest grammatical forms of similar functions in VB.NET.(map)2. replaced keywordsIn VB.NET, Microsoft is reduced by many, originally used in VB6 keywords, instead of “frame type“. T
49、he reason for this substitution is that the functionality in the framework class is valid for all.NET languages. The following table lists some of the keywords that are affected.(map)3. new declarative methodsIn VB.NET, statements and initialization methods for variables, arrays, and UDT (user defined types) have changed. The following table outlines the changes of VB.NET in this respect.(map)(1) the array in VB.NET is based on 0: that is, they always start from 0, similar to “Dim MyArray (10) As“The result of the code like Integer is a Integer array with 11 elements: f