Vb. NET Basic statement (recommended)

Source: Internet
Author: User
Tags try catch
Statement one: Try ..... Catch.........finally.........end Try Catch Error
Put a possible error statement behind a try, and, if an error occurs, execute a Catch statement, the catch can have multiple, and the first catch cannot catch an error that will be captured by the next catch statement. After all the processing is complete, the finally statement is executed.
You can use catch with one of the finally two in a try.........end try process, or two one at a
  
Two: Protected, private, public package control
These three keywords are generally placed at the front of the statement, and are placed behind overloads and overrides.
Public is an engineering-level external access
Protected is the following internal access to the family level
Private is not providing non-local access
  
Three: ByVal sender as Object, ByVal e as System.EventArgs
This is the most rewarding event for passing arguments. is encapsulated in two objects, and if you want to pass the corresponding arguments, look for them inside the two objects, such as the current mouse position is E. X e.y. In VB. NET some of the events are to write themselves, such as the form mouse process, the general plus this parameter in the parentheses in the back of the solution.
  
Four: Overloaded grammar overloads
such as: class Class1
Public Strtem As String
Overloads Public Sub Subx () Overload SUBX (a State)
Strtem= "3"
End Sub
Overloads Public Sub Subx (x As String) overload SUBX (b State)
Strtem=x
End Sub
End Class
  
If you call SUBX () with no parameters in the middle, VB automatically invokes the overload SUBX (a state),
Overloads Public Sub Subx () Overload SUBX (a State)
Strtem= "3"
End Sub
The result is strtem= "3."
If you call this, SUBX ("This is a different result"), then VB automatically invokes the overload SUBX (b State)
Overloads Public Sub Subx (x As String) overload SUBX (b State)
Strtem=x
End Sub
The result is strtem= "It's a different result."
You can call in a function, including in the API (of course vb.net no longer use WINAPI).
Even some of the most crucial processes are no exception: the new process (described in this Wangguorong article)
Such as:
class Class1
Overloads public Sub New ()
。。。。。。
。。。。。。
End Sub
Overloads public Sub New (s As String)
。。。。。。
。。。。。。
End Sub
End Class
  
There are also two methods of calling, such as dim as as Class1=new class, which calls a previous parameterless new procedure, while dim asb as Class1=new Class ("string") calls the second new Process. Remember, if a process or a function has only one state, it cannot be applied in this way. If you try to use the Overloads keyword, vb.net will be prompted with an error asking you to remove the overloads
  
Five: Overrides rewrite
such as the common Dispose process:
Overrides public Sub Dispose ()
Mybase.dispose
Components. Dispose
End Sub
Overrides represents a complete rewrite of the procedures and functions provided by the parent class
Remember, however, that using overtype is a prerequisite for using the Overrides keyword in front of the same procedure or function of the parent class
  
VI: MyBase.New and Mybase.dispose
Ublic Sub New ()
MyBase.New
Form1 = Me
InitializeComponent
End Sub
Overrides public Sub Dispose ()
Mybase.dispose
Components. Dispose
End Sub
  
These two processes are available to any new project, MyBase.New is the new process of invoking the parent class of the current class, and you can also add parameters to the overloaded new process of the parent class. Such as:
Overloads public Sub New ()
MyBase.New ()
End Sub
Overloads Public Sub New (string)
MyBase.New (String)
End Sub
  
Seven: Structure construction
Custom types, such as:
Structure Type1
Dim x as Y
Dim A as B
。。。。。。。
End Structure
This replaces the method used in VB6 to customize the type in Type.........end type.
  
Eight: return value
function functionname ()
Return X ...
End Funtion
His role is the same as the following:
function functionname ()
functionname = X ...
End Funtion


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.