Summary of VB. NET syntax and syntax

Source: Internet
Author: User

Summary of VB. NET syntax and syntax

I am proficient in C # programming. I have no development experience in VB and need to perform project maintenance. I specially sorted out the VB syntax to make a negative supplement. All programming ideas are interconnected and are developed by Microsoft. The language is similar.

Imports System 1. (1) define a variable and initialize it. Dim strText As String = ""
Or Dim strText As String strText = ""
(2) instantiate a class or object Dim openFileDialog1 As New OpenFileDialog () Dim clsClass As New ClsClass () (3) declare an array Dim fileNames As String () = New String (3) {} fileNames (0) = "Zhang San" fileNames (1) = "Li Si" fileNames (2) = "Wang Wu"
(4) declare a generic type Dim list As New List (Of T) () II. Exception Handling.
Try Catch ex As Exception 
    Throw New Exception(ex.Message, ex)
 End Try 
Iii. Condition judgment statement
Else ... End if 
Iv. Loop array and set
For i As Integer = 0 To openFileDialog1.FileNames.Length - 1 
//exit for 
For Each item In List           //exit for
V. Process and Function
Public Sub function name (ByVal/ByRef parameter name As Integer) as type
End Sub 
Public Function Name (ByVal/ByRef parameter name As Integer) as type
'Vb6. 0: function writing with return values
 Dim str1 As String = "111" 
'Result = str1  
'You can also use the key value Return in to Return.
 Dim str2 As String = "222"
 Return str2 
End Function 
6. modules in are generally used only to define global variables and public methods.
Class ClassName 
Public shared Function fnXXX () as string' shared refers to the Static keyword equivalent to the Static keyword in C.
End Function 
The End Class is called directly using ClassName. fnXXX. You can also call fnXXX () directly.
Module ModuleName 
public Function fnXXX() as string 
End Function 
End Module
Call: ModuleName. fnXXX (). You can also call fnXXX () directly. There can be direct methods in the modules. These methods are automatically static (or shared-by-VB.. NET), these methods can be called directly, so the Module cannot be instantiated, there is no need to instantiate the Module can not inherit, and there can be classes in the interface Module, however, this class does not need to be referenced by the module as the prefix. Therefore, the concept module is a bit virtual and can be organized into the namespace. Because the module is actually virtual, its method can also be called directly in the outer namespace. 7. Use the same event for multiple identical events. VB. NET
Private Sub rdbFeedChannelAny_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rdbFeedChannel1.Click, rdbFeedChannel2.Click, rdbFeedChannel3.Click
 Exit Sub 
C#Designerthis.radioButton1.CheckedChanged += new System.EventHandler(radioButton_CheckedChanged);this.radioButton2.CheckedChanged += new System.EventHandler(radioButton_CheckedChanged);Code; 
Private void radioButton_CheckedChanged (object sender, EventArgs e) {if (this. radioButton1.Checked) {}} 8. Overloads keywords to implement overload functions. Class1 Overloads Public Sub New () // constructor. ...... ...... End sub
Overloads Public Sub New(s as string)   。。。。。。   。。。。。。   end sub 
end Class 
9. withevents is used to declare an object. The object declared with withevents has its own event. When RaiseEvent exists in this object, it is received externally. Handles is used to receive the withevents object event. For example, if your object has an event A, and the RaiseEvent A object is executed, the SUB of the caller's handles object. A will be executed.

Related Article

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: 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.