Lab Exercise 8 Object-Oriented Programming in Visual Basic.Net

4
QUESTION 1 CODING FOR FORM: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomerDetail.Click Dim Pelanggan As New customer Dim DOB As Date Pelanggan.Name = txtCustomerName.Text Pelanggan.ID = txtCustomerId.Text Pelanggan.Status = txtStatus.Text DOB = DateTimePicker1.Value.Date MsgBox(Pelanggan.Name & " " & Pelanggan.ID & " is " & Pelanggan.Status & " " & Pelanggan.Age(DOB) & " Years Old.") End Sub Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click txtCustomerName.Text = "" txtCustomerId.Text = "" txtStatus.Text = "" End Sub Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click Me.Close() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub txtCustomerName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerName.TextChanged End Sub Private Sub txtCustomerId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerId.TextChanged End Sub Private Sub txtStatus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStatus.TextChanged End Sub

Transcript of Lab Exercise 8 Object-Oriented Programming in Visual Basic.Net

Page 1: Lab Exercise 8 Object-Oriented Programming in Visual Basic.Net

QUESTION 1

CODING FOR FORM:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomerDetail.Click Dim Pelanggan As New customer Dim DOB As Date

Pelanggan.Name = txtCustomerName.Text Pelanggan.ID = txtCustomerId.Text Pelanggan.Status = txtStatus.Text DOB = DateTimePicker1.Value.Date

MsgBox(Pelanggan.Name & " " & Pelanggan.ID & " is " & Pelanggan.Status & " " & Pelanggan.Age(DOB) & " Years Old.")

End Sub

Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click txtCustomerName.Text = "" txtCustomerId.Text = "" txtStatus.Text = "" End Sub

Private Sub BtnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClose.Click Me.Close() End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub txtCustomerName_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerName.TextChanged

End Sub

Private Sub txtCustomerId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCustomerId.TextChanged

End Sub

Private Sub txtStatus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStatus.TextChanged

End Sub

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DateTimePicker1.ValueChanged

End SubEnd Class

Page 2: Lab Exercise 8 Object-Oriented Programming in Visual Basic.Net

INTERFACE OUTPUT:

Page 3: Lab Exercise 8 Object-Oriented Programming in Visual Basic.Net

QUESTION 2

What is the difference between an object and class?

Each object in Visual Basic is defined by a class. A class describes the variables, properties, procedures, and events of an object.

Objects are instances of classes; you can create as many objects you need once you have defined a class.

To understand the relationship between an object and its class, think of cookie cutters and cookies. The cookie cutter is the class. It defines the characteristics of each cookie, for example size and shape. The class is used to create objects. The objects are the cookies.

QUESTION 3

Give the definition for properties and method.

• Properties are retrieved and set like fields but are implemented using Property Get and Property Set procedures which provide more control on how values are set or returned

• Methods represent the object’s built-in procedures. 

• For example, a Class named Country may have methods named Area and Population.

• You define methods by adding procedures, Sub routines or functions to your class.