You are on page 1of 10

LAB TASK 2

DFP40233 VISUAL BASIC


PROGRAMMING

NAME CHONG XING JOE

REGISTRATION NO 21DDT20F1078

CLASS DDT5B S2

PROGRAMME DIPLOMA OF DIGITAL TECHNOLOGY


DR LETCHUMANAN A/L SHANMUGAM
LECTURER
CLO 1: Construct the visual basic program by using .NET frameworks in developing windows
Application. (P4, PLO3)

Question 1: Array : One-Dimensional [ 25 marks]

You are required to build a one-dimensional array using visual basic .net. Please submit

31, 32, 20, 30, 25, 27, 25, 20, 20, 31, 32, 35, 36, 24, 25, 22, 20

your answer with completeform interface and program code.

Table 1: Ages

Table 1 shows the age of people who are shopping at the Little Baby Shop. But the ages
are not well organized.Therefore, the management team asks you to help them arranges
the information according to these criteria:

1. Ascending Order
2. Show older age
3. Show younger age
4. Average of age

Form1(Q1)

Here is the screen shot for Form 1.


If Click the button “Ascending Order”. The list box will show the customer’s ages in
ascending order.

Now click the button “Show older age”, the list box will clear the data about ascending order
and show out the older customer’s age.
Click the button “Show younger age”, the list box will clear the data about older customer’s
age and show out the younger customer’s age.

Click the button “Average of age”, the list box will clear the data about younger customer’s
age and show out customer’s average age.
Coding(Form1(Q1))
Public Class Form1

Dim ages As Integer() = {31, 32, 20, 30, 25, 27, 25, 20, 20, 31, 32,
35, 36, 24, 25, 22, 20}

Private Sub Ascending_Click(sender As Object, e As EventArgs) Handles


Ascending.Click

Array.Sort(ages)

For i As Integer = 0 To ages.Length - 1

Show.Items.Add(ages(i))

Next

End Sub

Private Sub Older_Click(sender As Object, e As EventArgs) Handles


Older.Click

Show.Items.Clear()

Dim old As Integer = 0

For i As Integer = 0 To ages.Length - 1

If (old < ages(i)) Then

old = ages(i)

End If

Next

Show.Items.Add(old)

End Sub

Private Sub Younger_Click(sender As Object, e As EventArgs) Handles


Younger.Click

Show.Items.Clear()

Dim young As Integer = 100

For i As Integer = 0 To ages.Length - 1

If (young > ages(i)) Then

young = ages(i)

End If

Next

Show.Items.Add(young)
End Sub

Private Sub Average_Click(sender As Object, e As EventArgs) Handles


Average.Click

Show.Items.Clear()

Dim sum As Integer

For i As Integer = 0 To ages.Length - 1

sum += ages(i)

Next

sum = sum / (ages.Length)

Show.Items.Add(sum)

End Sub

End Class
Question 2: Array : Two-Dimensional [ 25 marks]
A treasurer wants to list out the person that paid or unpaid for the fees for year 2021
and 2022 as in Table 2 by usingtwo dimensional arrays. Construct Windows Application
program with array – two-dimensional coding that show thestatus of paid and unpaid
person using message box. Please submit you answer with complete form interface and
program code.

Name 2021 2022

Lax Paid Paid

Rizal Paid Unpaid

Maheran Paid Paid

Tan Sze In Unpaid Unpaid

Table 2: List Name of Students in


Semester 4 for Class VB.NET

Write suitable naming prefixes for the object controls.


Form1(Q2)

Here is the screen shot for Form 1.


After click the button “Check Fees”. There will come out a message box to show the student
payment detail.

Coding(Form1(Q2))
Public Class Form1

Private Sub Check_Click(sender As Object, e As EventArgs) Handles


Check.Click

Dim array(2, 4) As String

array(0, 0) = "Name "

array(0, 1) = "Lax "

array(0, 2) = "Rizal "

array(0, 3) = "Maheran "

array(0, 4) = "Tan Sze In "

array(1, 0) = "2021 "

array(1, 1) = "Paid "

array(1, 2) = "Paid "

array(1, 3) = "Paid "

array(1, 4) = "Unpaid "

array(2, 0) = "2022 "

array(2, 1) = "Paid "

array(2, 2) = "Unpaid "

array(2, 3) = "Paid "

array(2, 4) = "Unpaid "


Dim str As String

For x = 0 To 4

For y = 0 To 2

str = str & array(y, x) & ""

Next

str = str & vbNewLine

Next

MsgBox(str, MsgBoxStyle.MsgBoxSetForeground, "List Paid")

End Sub

Private Sub Tabel_namelist_Paint(sender As Object, e As PaintEventArgs)


Handles Tabel_namelist.Paint

End Sub

Private Sub Title_Click(sender As Object, e As EventArgs) Handles


Title.Click

End Sub

Private Sub Table_name_Click(sender As Object, e As EventArgs) Handles


Table_name.Click

End Sub

Private Sub Student1_Click(sender As Object, e As EventArgs) Handles


Student1.Click

End Sub

Private Sub Student2_Click(sender As Object, e As EventArgs) Handles


Student2.Click

End Sub

Private Sub Student3_Click(sender As Object, e As EventArgs) Handles


Student3.Click
End Sub

Private Sub Student4_Click(sender As Object, e As EventArgs) Handles


Student4.Click

End Sub

End Class

You might also like