1 / 18

Visual Basic .NET

Visual Basic .NET. Huimin Zhao. VB .NET and C# .NET. Sister languages Both are pure OO languages Virtually equivalent in capabilities Share the same .NET Framework Class Library Mainly differ in syntax. Payroll Example (VB). VB Syntax. Case insensitive ' for starting a comment

millerv
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 Huimin Zhao

  2. VB .NET and C# .NET • Sister languages • Both are pure OO languages • Virtually equivalent in capabilities • Share the same .NET Framework Class Library • Mainly differ in syntax

  3. Payroll Example (VB)

  4. VB Syntax • Case insensitive • ' for starting a comment • No ; at end of statement • No { }. Use End for ending a block End Class, End Sub, End Function, End Property, End Get, End Set, End Try, End If, End Select, End Using, etc.

  5. Imports (for using) a namespace Imports System • Boolean for bool Private isMaleValue As Boolean • Integer for int Dim i As Integer • Single character value "0"c If (c >= "0"c And c <= "9"c) Then

  6. vbCrLf for newline character If (MessageBox.Show("Are you sure you want to update " + vbCrLf + CType(lstEmployees.SelectedItem, Employee).ToString(), • vbTab for tab character Return TitleName + vbTab _ + MaritalStatus + vbTab _ + Category + vbTab _ + HomeAddress.ToString()

  7. Defining a local variable Dim employeeObject As Employee • Defining a class instance variable Private firstNameValue As String • Catch exception object Catch ex As Exception • Using a resource Using exampleObj As New ExampleObj exampleObj.SomeMethodEnd Using

  8. CType for type casting CType(employeeObject, HourlyEmployee).Hours = Decimal.Parse(txtHoursWorked.Text) • = for equality, <> for inequality If (value = "") Then If (phoneNumberValue.Length <> 10) Then • And, Or, Not for &&, ||, ! If (c >= "0"c And c <= "9"c) Then If c < "A"c Or c > "Z"c Then IsMale = Not value

  9. Is for comparing reference types • Nothing for null If (Not Input Is Nothing) Then • Typeof to check the type of an object If (TypeOf EmployeeObject Is SalariedEmployee) Then • () for array subscript Private Shared stateNamesValue As String() = {...} stateNamesValue(stateValue)

  10. If – ElseIf – Else – End If If (value = "MALE" Or value = "M") Then IsMale = True ElseIf(value = "FEMALE" Or value = "F") Then IsMale = False Else Throw New Exception("...") End If

  11. For loop Dim i As Integer For i = 0 To stateNamesValue.Length - 1 If (inputValue = stateAbbreviationsValue(i)) Then stateValue = i Return End If Next i

  12. For Each loop Dim item As Employee For Each item In lstEmployees.Items Formatter.Serialize(output, item) Next item

  13. Do While loopDim Employee As Employee Employee = CType(reader.Deserialize(Input), Employee) Do While (Not Employee Is Nothing) lstEmployees.Items.Add(Employee) Employee = CType(reader.Deserialize(Input), Employee) Loop

  14. Function for method that returns value Private Function getInputs(employeeObject As Employee) As Boolean • Sub for a void method Private Sub displayEmployee( EmployeeObject As Employee)

  15. Property for class property Public Property FirstName() As String • ReadOnly for read-only property Public ReadOnly Property Age() As Byte • Shared for static Public Shared ReadOnly Property States() As String()

  16. Sub New for class constructor • Me for this Public Sub New(first As String,...) Me.FirstName = first

  17. Inherits for inheritance Public Class HourlyEmployee Inherits Employee • myBasefor base Public Sub New() MyBase.New() End Sub

  18. MustInherit for abstract class Public MustInherit Class Employee • Overridable for virtual method or property Public Overridable ReadOnly Property Category As String • MustOverride for abstract method or property Public MustOverride ReadOnly Property Earnings() As Decimal • Overrides for override Public Overrides ReadOnly Property Earnings() As Decimal

More Related