1 / 12

Visual Basic.NET

Visual Basic.NET. Declaring Variables Dim x As Integer Dim y As Integer = 10 Comments ' comment Assignment Statement var= newvalue Constant Const Pi As Double = 3.14159. Visual Basic.NET Data Types. Visual Basic .NET Runtime Storage Range of Values Data Type Data Type Size

Download Presentation

Visual Basic.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic.NET • Declaring Variables • Dim x As Integer • Dim y As Integer = 10 • Comments • ' comment • Assignment Statement • var= newvalue • Constant • Const Pi As Double = 3.14159

  2. Visual Basic.NET Data Types Visual Basic .NET Runtime Storage Range of Values Data Type Data Type Size ============================================================ Boolean System.Boolean 4 bytes True or False Byte System.Byte 1 byte 0 to 255 (unsigned) Char System.Char 2 bytes 1 Unicode “” character Date System.DateTime 8 bytes January 1, 0001to December 31,9999 Decimal System.Decimal 12 bytes +/-0.0 79,228,162,514,264,337, 593,543,950,335 Double System.Double 8 bytes -1.797693134862310.0E308 to - 4.94065645841247E-324 Integer System.Int32 4 bytes -2,147,483,648 to 2,147,483,647 Long System.Int64 8 bytes -9,223,372,036,854,775,80 to 9,223,372,036,854,775,807 Object System.Object 4 bytes Any data type Depends on usage. Short System.Int16 2 bytes -32,768 to 32,7670 Single System.Single 4 bytes -3.402823E38 to 0.0 String System.String 10 bytes 0 to approximately billion Unicode char

  3. Data Types • Option Explicit: forces variable declaration • Option Strict: forces variable declaration + will not allow conversions where data loss would occur. • Data Type Conversion • CType (variable_name, New type) • ToString method is available in all data types • Members available for data types • String (Trim, Length, Substring, Replace,..) • Array (Length, GetUpperBound, Clear, Sort,..) • DateTime (Now,Today,Year,Day,Hour, Add, Subtract, IsLeapYear, DaysInMonth, …)

  4. VB.NET Operators Type Operator Purpose Example Math + Add 5 + 2 = 7 – Subtract 5 – 2 = 3 * Multiply 5 * 2 = 10 / Divide 5 / 3 = 2.5 \ Integer Divide 5 \ 2 = 2 ^ Exponentiation 5^2 = 25 Mod Remainder 5 mod 2 =1 String + Concatenate “one” + “two” = “onetwo” & Concatenate “one” & “two” = “onetwo” Assignment = Assigns the value of expression to variable x = 5 + 3 Math += Adds the value x += y

  5. Type Operator Purpose Example -= Subtracts the x -= y *= Multiplies the x *= y /= Divides the x /= y \= Integer divides x \= y &= Concatenates the x &= y ^= Exponentiates x ^= y Comparison = Is equal to If (x = y) < Is less than If (x < y) <= Is less than or If (x <=equal to y) > Is greater than If (x > y) >= Is greater than If (x >=or equal to y) <> Is not equal to If (x <> y) Like Matches a pattern If (x Like “p??r”) Is Do object variables refer to same object If (x Is y) Logical And True if both expressions are true If (x = 3 AND y=4) Or True if one or If (x = 3 OR y=4) both expressions are true Not True if expression is false If Not (x =5) Xor True if one expression is If (x = 3 Xor y=4) true, but not both

  6. Arrays • Specify upper bound of array, starting at index 0 Dim Names(9) As String `10 elements 0 to 9 Dim Num () As Integer = { {1,6} , {7,5} , {5,9} } Names(0) = “Ahmed” Num (2,1)=4 ReDim Preserve Names(2) For Each e in Num print e `Read only elements Next

  7. Enumeration Enum UserType Admin =3 Guest = 2 User= 9 End Enum Dim user As UserType = UserType.Guest Dim user2 As UserType = 9

  8. Branching Structures If (condition) Then code Elseif (condition) then another code Else final code End if

  9. Branching Structures Select Case expresssion Case 1 code 1 Case 2 code2 Case 3 code3 Case Else Default code End Select

  10. Looping Do While (condition) code to repeat Loop ___________________ Do code to repeat Loop until (condition) • Exit Do `to get out of a loop

  11. Looping For i = init_value To final_value Code to repeat Next • Exit for ` to get out of loop

  12. Subroutines and Functions • Subroutines Sub HelloWorld() Response.Write(“Hello World”) End Sub You call a sub using either of the following statements: HelloWorld() Call HelloWorld() • Functions: can return a value to calling program Function SayHello() As String Return “Hello World” End Function • NOTE • VB.NET requires parentheses around argument lists • The default is to pass parameters by value otherwise use “byref” keyward • Overload functions of procedures using the “overloads” keywaord

More Related