Your SlideShare is downloading. ×
0
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
VB.NET Language Fundamentals
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

VB.NET Language Fundamentals

7,234

Published on

Published in: Technology, Education
0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
7,234
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
6
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • Transcript

    • 1. Section 4: VB.NET Language Fundamentals
      • VB.NET Statements
      • Data Types
      • Operators in .NET
      • Declaring and Assigning Variables
      • Declaring Constants
      • Static Variable Types
      • Arrays in VB.NET
      • Conditional Statements
      • Looping Statements
    • 2. Section Objectives
      • After completing this section, you will be able to:
        • Explain VB.NET statements
        • List the fundamental language features of VB.NET
        • Identify supported .NET data types
        • Explain how to create variables, constants, and arrays
        • Explain conditional statements
        • Explain looping statements
    • 3. VB.NET Statements
      • VB.NET programs are written using statements such those shown here:
      • Dim custCount as Integer = 3
      • custCount += 1
      • Statements represent a single VB.NET operation and can be composed of several elements including types, VB.NET keywords, etc.
      • Statements that span more than one line require the _ continuation character:
      • Dim custCount as _
      • Integer = 3
      VB.NET statement VB.NET statement
    • 4. Commenting VB.NET Statements
      • Comments allow documentation to be added into code and/or statements to be commented out.
      • VB.NET statements can be commented by using the apostrophe (‘) character:
      • ‘ Dim custCount as Integer = 3
    • 5. Data Types
      • Data types in .NET are based upon the CTS, which is part of the CLR.
      • CTS types are either value or reference types.
      Intermediate language runtime compilers CTS Execution support, runtime functions Security functionality Boolean Byte Char Double Int16 Int32 Etc. Garbage collection, stack walker, Code manager Class loader, memory layout
    • 6. Value Types
      • They hold data within their own memory allocation. (They have their own copy of data.)
      • Any assignment of a value type creates a new copy of the data.
      • Examples of value types:
        • Integer, Boolean, Char, Date, Enum, Structure
      i = 4 Dim i as Integer = 4
    • 7. Reference Types
      • They point to another memory location where the data is held. (They do not have their own copy of data.)
      • Any assignment of a reference type creates a reference to the data. (A new copy is not made.)
      • Examples of value types:
        • String, Array, Class
      name “ Hello” Dim name as String = “Hello”
    • 8. Data Types in VB.NET Reference types Value types Object String Array Foo(4) Class Foo Short Char Float Long Integer Byte Boolean Double Enum Enum Foo Structure Foo
    • 9. Operators in .NET
      • Operators allow tasks such as arithmetic, comparisons, and concatenation to be performed in a statement.
      • VB.NET contains several new operators. For example: Dim name as String = “John” name += “ Doe”
      • Dim i as Integer = 40 i -= 3
    • 10. Arithmetic and Assignment Operators Exponentiation assignment ^= Equality = Modulo division Mod Exponentiation ^ Integer division Floating-point division / Multiplication * Subtraction - Addition + Operation Operator Concatenation and assignment &= Integer division assignment = Floating-point division assignment /= Subtraction assignment -= Multiplication assignment *= Addition assignment += Operation Operator
    • 11. Comparison Operators And And String concatenation + Concatenation & Tests to see if obj1 and obj2 refer to same object Is Compares string to pattern Like Greater than or equal to >= Less than or equal to <= Greater than > Operation Operator Or Or Inequality <> Negative for booleans Not Returns the type of an object GetType Returns address of a given procedure AddressOf Xor (bitwise operations) Xor Less Than < Operation Operator
    • 12. Demonstration
      • Value vs. reference types
      • Operators
    • 13. Declaring and Assigning Variables
      • VB.NET types can be declared and assigned with one statement:
      • Dim x as Integer = 45
      • Dim name as String = “John Doe”
      • Dim currentDateTime as DateTime = DateTime.Now
      • Multiple types can be declared on the same line in VB.NET. In the following code, all types are assigned an Integer type:
      • Dim x,y,z as Integer
    • 14. Variable Scope and Visibility
      • Scope refers to how long a variable is accessible.
      • Types of scope:
        • Class and structure level
        • Function and subroutine level
        • Block level
      • Variables can have different types of visibility, including public and private.
    • 15. Understanding Scope
      • Public Class Customer
      • Dim CustomerName as String
      • End Class
      • Public Class Customer
      • Public Function GetCustomer() as String
      • Dim CustomerName as String = “John”
      • Return CustomerName
      • End Function
      • End Class
      Scope global to class Scope local to function
    • 16. Function vs. Block Scope
      • Public Function GetCount() as Integer
      • Dim totalCount as Integer = 0
      • Dim i as Integer
      • For i = 1 to 50
      • Dim x as Integer = i + 5
      • totalCount += x
      • Next
      • Return totalCount
      • End Function
      Scope local to function Scope local to looping block
    • 17. Declaring Constants
      • Constants are used to hold data that does not change. They can help make code easier to read and maintain.
      • Constants can be assigned an initial value, but cannot be changed like a variable can.
      • VB.NET constants use the Const keyword:
      • Public Const DepartmentID as Integer = 158945699
      • The scoping rules that apply to variables also apply to constants.
    • 18. Static Variable Types
      • Variables declared using the Static keyword stay in memory until the program finishes executing:
      • Function Total() as Integer
        • Static CustomerTotal as Integer = 0
        • CustomerTotal += 1
        • Return CustomerTotal
      • End Function
      CustomerTotal stays in memory even after the Total() function is exited.
    • 19. Converting Between Types
      • VB.NET relies upon the CType function to convert between different types:
      • Dim age as Integer = 45
      • Dim stringAge as String = CType (age,String)
      • There are several other ways to convert between types:
        • System.Convert class
        • Dim stringAge as String = System.Convert.ToString(age)
        • Type methods
        • Dim stringAge as String = age.ToString()
    • 20. Preventing Implicit Conversions: Option Strict
      • VB.NET allows implicit conversions by default:
      • Dim x as Integer = 25
      • Dim y as Long = 52
      • x = y
      • When Option Strict is turned on, the compiler will not allow implicit type conversions. You must handle conversions in the code.
      • Option Strict On
      • Dim x as Integer = 25
      • Dim y as Long = 52
      • x = y
      With Option Strict on, the compiler will catch this potential problem. This may cause loss of data.
    • 21. Arrays in VB.NET
      • Arrays are reference types used to hold a collection of identically typed objects.
      • Arrays can be used to hold value and reference types (integers, strings, custom objects, etc.).
      Widget Widget Widget Array of widgets
    • 22. Declaring Arrays
      • Reference and value type objects can be stored in arrays.
      • Dim A() as Integer = {1,2,3}
      A(0) 1 A(1) 2 A(2) 3 A Dim S() as String = {“Hi”,”There”,”Class”} S(0) S(1) S(2) S “ Hi” “ There” “ Class”
    • 23. Redimensioning Arrays
      • Arrays can be redimensioned using the ReDim keyword in VB.NET:
      • Dim Years(2) as Integer
      • Years(0) = 1970
      • Years(1) = 1980
      • Years(2) = 1990
      • ReDim Preserve Years(6)
      • The Preserve keyword can be used when the original contents of the array need to be copied to the newly dimensioned array.
    • 24. Conditional Statements
      • Conditional statements play an important role in applications.
      • VB.NET supports the following types of conditional statements:
        • If…Then…Else
        • Select…Case
    • 25. If Statements
      • If statements provide a way to check if one or more conditions are met:
      • Dim total as Integer = GetTotalSale() ‘Call Function
      • Dim shipping as Integer
      • If total > 100 And total < 1000 Then
      • shipping = total * 0.02
      • ElseIf total > 1000 Then
      • shipping = 0 ‘shipping is free!
      • Else
      • shipping = total * 0.9
      • End If
    • 26. Select Case Statements
      • Select Case statements provide a clean way to evaluate multiple conditions:
      • Dim total As Double = GetTotalSale() 'Call Function
      • Dim phrase As String = &quot;Shipping is $&quot;
      • Select Case total
      • Case 100 To 1000
      • Console.WriteLine(phrase & (total * 0.02))
      • Case Is >= 1000
      • Console.WriteLine(phrase & &quot; free!&quot;)
      • Case Is < 100
      • Console.WriteLine(phrase & (total * 0.9))
      • Case Else
      • Console.WriteLine(&quot;We don't ship to your address.&quot;)
      • End Select
    • 27. Looping Statements
      • Looping statements can be used to iterate through collections of objects or perform a task a specific number of times.
      • VB.NET supports the following types of looping statements:
        • For…Next
        • For…Each
        • Do…While/Until
        • While
    • 28. For…Next Loops
      • The For…Next keywords provide a way to perform looping a specific number of times:
      • Dim names() as String = {“John”,”Jane”,”Thomas”,”Dan”}
      • Dim i as Integer
      • For i=0 To names.GetUpperBound(0) Step 1
      • Dim name as String = names(i)
      • Console.WriteLine(name)
      • Next
      Step 1 is the default.
    • 29. For…Each Loops
      • Object collections can be iterated through using the For…Each keywords:
      • Dim Exists As Boolean = False
      • Dim fname as String = “John”
      • Dim customers As Customers = GetCustomers()
      • Dim customer as Customer
      • For Each customer In customers
      • If customer.FirstName = fname Then
      • Exists = True
      • Exit For
      • End If
      • Next
    • 30. Do…While and Do…Until Loops
      • The Do…While and Do…Until keywords can be used to perform a looping routine until a specific condition is met:
      • Dim i as Integer = 0
      • Do Until i = 4
      • i += 1
      • Loop
      • Do While i > 0
      • i -= 1
      • Loop
      Loop while the condition is true. Loop until the condition is true.
    • 31. While Loops
      • The VB6 While…Wend has been replaced with While…End While in VB.NET:
      • Dim i as Integer = 0
      • While i < 6
      • i += 1
      • Console.WriteLine(“Value is: “ & i.ToString())
      • End While
    • 32. Demonstration
      • Looping and arrays
    • 33. Summary
      • VB.NET programs are composed of statements.
      • Types found in the .NET framework can be classified as value or reference types.
      • Type conversions can be accomplished using the CType() function.
      • Conditional and looping statements can be used to control an application’s flow.
    • 34.
      • The VB6 While…Wend statement has been replaced by which statement in VB.NET?
        • a. While…Loop
        • b. While…End While
        • c. Do…Loop
        • d. None of the above
      • Which of the following characters can be used to comment a line of code in VB.NET?
        • a. //
        • b. */
        • c. /*
        • d. ‘
      Section Review
    • 35.
      • The following types exist in the .NET platform:
        • a. Value types
        • b. Object types
        • c. Conversion types
        • d. Reference types
        • e. Both a and d
      Section Review
    • 36.
      • Which of the following lines of code represents a valid code statement?
        • a. Dim x as Integer = 45
        • b. Dim x as _ Integer = 45
        • c. Dim x as Integer = 45
        • d. a and b only
        • e. b and c only
      Section Review
    • 37.
      • Value types hold their own copy of data.
        • True
        • False
      • In the following line of VB.NET code, y and z are declared as variants: Dim x,y,z as Integer
        • True
        • False
      • Reference types hold their own copy of data.
        • True
        • False
      Section Review

    ×