Visual Basic.NET
VB.NET Quick Reference
Variable Declaration
|
Const trialDays As Integer = 30 'Constant Dim today As DateTime = DateTime.Now 'Current Date Dim saleDate As DateTime = New _ DateTime(2004, 1, 23, 13, 48, 39) '(year, month, day, hours, minutes, seconds) Dim items(100) As Integer 'Array (See ArrayList) Enum OrderStatus As Integer NewOrder = 1 Picked Shipped End Enum |
Procedures/Properties
|
//Access Modifiers: public, friend, Private Function Markup(ByVal total _ As Double) As Double Return total * _markupPercent End Function Friend Property InvoiceId() As Integer Return _invoiceId End Get Set(ByVal Value As Integer) _invoiceId = Value End Set End Property |
Loops
|
'While While i < 10 i += 1 End While 'For For i As Integer = 0 To 9 If (isFound) Then _ Exit For 'Exit loop Next 'For each loop Dim dt As DataTable For Each _ dr As DataRow In dt.Rows Console.WriteLine( _ dr(0).ToString()) Next 'Do Loop Do i += 1 Loop Until i > 9 |
Branching
|
'If/Else statement If (i > 0 AndAlso j <> 5) OrElse k = 1 Then Else If (i < 0) Then End If Select Case i 'Case statement Case Is < 2 Return "Less than two" Case 3, 5 Return "Three or five" Case Else 'Default Return "Other" End Select j= CInt(IIf(i > 0, 1, 0)) 'Immediate If |
Operators
|
Computational - Negate/Subtract * Multiplication / Division Float \ Division Integer mod Modulus + Addition Logical not Logical NOT < Less than > Greater than <= Less than or equal >= Greater than or equal = Equality <> Inequality And Logical AND Or Logical OR AndAlso Short Circuit Assignment = Assignment Compound assignment operators += Addition -= Subtraction *= Multiplication /= Division |
Error Handling
|
Try i = 10 / 0 ' "Catch" the error Catch ex As Exception Dim s As String = "Error:" + vbCrLf _ + ex.Message.ToString + vbCrLf _ + "Trace: " + ex.StackTrace.ToStringMsgBox(s, MsgBoxStyle.Critical, _ "Error") Finally 'Always do this inputFile.Close() End Try |
Parameter Definitions
|
'Value,Reference,Dynamic Private Sub Calc( _ ByVal i As Integer, _ ByRef j As Integer, _ ByVal ar() As Integer) End Sub |
Previous page: Afx functions
Next page: Multi-threading in VB.NET
Print this page