| The status of this resource is Pending. The webmaster may be reviewing this resource or have put on hold. |
'---------------------Variable Declaration----------------------------- '--Constant variable Const no_of_days As Integer = 30
'--Boolean Dim isLoaded As Boolean = True
'--16 bit Unicode character Dim keystroke As Char
'--Signed 32-bit integer Dim count As Integer = 0
'--Signed 64-bit integer Dim customerId As Long = 0
'--Double precision float Dim totalAmount As Double = 0
'--Single precision float Dim taxAmount As Single = 0
'--String Dim custName As String = String.Empty
'--Current Date Dim created_date As DateTime = DateTime.Now
'---Date time variable (year, month, day, hours, minutes, seconds) Dim saleDate As DateTime = New DateTime(2008, 8, 27, 10, 58, 20)
'--Single dimensional Array declaration Dim bill_no(100) As Integer
'---------------------Looping statements in vb.Net------------------------- '----While Loop----
Syntax: ------- While 'statements here End While
Example: -------- dim itot as integer While i < 10 itot = itot + i i = i+1 End While
Short description: ------------------ The statements inside a while loop will be executed in a loop until the condition remains true. In the above example, the statement will be exectued 10 times and the variable itot will be computed as itot = 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
'----For Loop---- Example: ------ For iLoop As Integer = 0 To 9 itot = itot + iLoop Next
The statements inside a for loop will be executed within the range values. Unlike the while statement, the For loop statement increments the starting range automatically by 1 and when it reaches the ending range, exits the loop.
'----For each loop---- Dim dt As DataTable For Each dr As DataRow In dt.Rows Console.WriteLine(dr(0).ToString()) Next
The difference between a "For Loop" and a "For Each Loop" statement is, for the "For Each Loop" statement its not necessary to specify the range of values as it loops as many times as the number of conditional rows exist.
'-----------------------Branching statements------------------------------
'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
'----------------------Parameter Definitions----------------------- '----Value,Reference,Dynamic---- Private Sub Calc(ByVal i As Integer, ByRef j As Integer)
End Sub
'-----------------------Error Handling----------------------------- Try i = 10 / 0 ' "Catch" the error Catch ex As Exception Dim s As String = "Error:" + vbCrLf _ + "Target: " + ex.TargetSite.ToString _ + vbCrLf + "Error: " _ + ex.Message.ToString + vbCrLf _ + "Trace: " + ex.StackTrace.ToString MsgBox(s, MsgBoxStyle.Critical, _ "Error") Finally 'Always do this inputFile.Close() End Try
'-------------------------------Procedures------------------------------ Private Function Markup(ByVal total As Double) As Double Return total * _markupPercent End Function
'---------------------------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 OrElse 'Short Circuit
'----Assignment = 'Assignment
'----Compound assignment operators += 'Addition -= 'Subtraction *= 'Multiplication /= 'Division
|
No responses found. Be the first to respond and make money from revenue sharing program.
|