Lab 4 Report
Lab 4 Report
Design Form:
Output:
Coding Form:
Public Class azform
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim button(26) As Button
Dim i As Integer
Dim n As Integer
Dim myfont As New Font("New Times Roman", 12, FontStyle.Italic)
Dim buttonA As Button
Dim buttonB As Button
For i = 0 To 6
button(i) = New Button()
button(i).Width = 30
button(i).Height = 30
button(i).Top = 50
button(i).BackColor = Color.DarkOliveGreen
button(i).ForeColor = Color.White
button(i).Font = myfont
button(i).Left = (i * 30) + 15
Me.Controls.Add(button(i))
button(i).Text = Chr(n + 65)
n += 1
AddHandler button(i).Click, AddressOf button_click
button(i).BringToFront()
Next
For i = 7 To 13
button(i) = New Button()
button(i).Width = 30
button(i).Height = 30
button(i).Top = 90
button(i).BackColor = Color.SkyBlue
button(i).Font = myfont
button(i).Left = ((i - 7) * 30) + 15
Me.Controls.Add(button(i))
button(i).Text = Chr(n + 65)
n += 1
AddHandler button(i).Click, AddressOf button_click
button(i).BringToFront()
Next
For i = 14 To 20
button(i) = New Button()
button(i).Width = 30
button(i).Height = 30
button(i).Top = 130
button(i).BackColor = Color.PaleVioletRed
button(i).Font = myfont
button(i).Left = ((i - 14) * 30) + 15
Me.Controls.Add(button(i))
button(i).Text = Chr(n + 65)
n += 1
AddHandler button(i).Click, AddressOf button_click
button(i).BringToFront()
Next
For i = 21 To 25
button(i) = New Button()
button(i).Width = 30
button(i).Height = 30
button(i).Top = 170
button(i).BackColor = Color.BlueViolet
button(i).Font = myfont
button(i).Left = ((i - 21) * 30) + 15
Me.Controls.Add(button(i))
button(i).Text = Chr(n + 65)
n += 1
AddHandler button(i).Click, AddressOf button_click
button(i).BringToFront()
Next
buttonA = New Button()
buttonA.Width = 30
buttonA.Height = 30
buttonA.Top = 170
buttonA.BackColor = Color.BlueViolet
buttonA.Font = myfont
buttonA.Left = ((26 - 21) * 30) + 15
Me.Controls.Add(buttonA)
buttonA.Text = ("@")
AddHandler buttonA.Click, AddressOf button_click
buttonA.BringToFront()
buttonB = New Button()
buttonB.Width = 30
buttonB.Height = 30
buttonB.Top = 170
buttonB.BackColor = Color.BlueViolet
buttonB.Font = myfont
buttonB.Left = ((27 - 21) * 30) + 15
Me.Controls.Add(buttonB)
buttonB.Text = ("#")
AddHandler buttonB.Click, AddressOf button_click
buttonB.BringToFront()
Me.BackColor = Color.Aquamarine
End Sub
Private Sub button_click(ByVal sender As Object, ByVal e As EventArgs)
txtoutput.Text = sender.text
End Sub
End Class
Output:
Output:
Coding Form:
Public Class NumberForm
Private Sub BtnMax_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnMax.Click
Dim input() As TextBox = {txtinput1, txtinput2, txtinput3}
Dim counter As Integer
'declaration
Dim maxi As Integer
For counter = 0 To 2
If input(counter).Text > maxi Then
'comparing the largest number
maxi = input(counter).Text
End If
Next
txtmax.Text = maxi
End Sub
Output:
'declaration
For counter = 0 To 9
If mark(counter) > high Then
' comparing the highest mark
high = mark(counter)
End If
Next
Console.WriteLine("The Highest mark of student is " & high & "mark(s).") 'display the output
For counter = 0 To 9
If mark(counter) < low Then
'comparing the lowest mark
low = mark(counter)
End If
Next
Console.WriteLine("The Lowest mark of student is " & low & " mark(s).")
'display the output
Console.WriteLine("The Average mark for the class is " & Format(sum / 10, "0.00") & " mark(s).")
Console.ReadLine()
End Sub
End Module
Output:
sum(1) = 0
For counterClass = 0 To 1
'1st looping for the class
Console.WriteLine("{0:s}", stdntclass(counterClass))
For counterStdnt = 0 To 9
'2nd looping for the student
Console.Write("Insert " & student(counterClass, counterStdnt) & "'s mark:")
mark(counterClass, counterStdnt) = Console.ReadLine
sum(counterClass) += mark(counterClass, counterStdnt) 'formula of sum
Next
Console.WriteLine()
Next
'display the output of average and comparing for the highest average between class.
Console.WriteLine("The Average mark of DTK5C is " & Format((sum(0) / 10), "0.00") & " mark(s).")
Console.WriteLine("The Average mark of DTK5E is " & Format((sum(1) / 10), "0.00") & " mark(s).")
If (sum(0) / 10) > (sum(1) / 10) Then
Console.WriteLine("DTK5C obtained highest average mark in final examinataion with " & Format((sum(0) /
10), "0.00") & " mark(s).")
ElseIf (sum(0) / 10) < (sum(1) / 10) Then
Console.WriteLine("DTK5E obtained highest average mark in final examinataion with " & Format((sum(1) /
10), "0.00") & " mark(s).")
End If
For counterClass = 0 To 1
For counterStdnt = 0 To 9
'comparing the highest mark in 2 class
If mark(counterClass, counterStdnt) > high Then
high = mark(counterClass, counterStdnt)
max = student(counterClass, counterStdnt)
End If
Next
Next
Console.WriteLine("The student get highest marks is " & max & " with " & high & " marks(s).")
For counterClass = 0 To 1
For counterStdnt = 0 To 9 'comparing the lowest mark in 2 class
If mark(counterClass, counterStdnt) < low Then
low = mark(counterClass, counterStdnt)
min = student(counterClass, counterStdnt)
End If
Next
Next
Console.WriteLine("The student get lowest marks is " & min & " with " & low & " marks(s).")
Console.ReadLine()
End Sub
End Module
Output:
Discussions:
Design Form:
Coding Form:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim button1(13) As Button
Dim buttonB As Button
Me.BackColor = Color.LightSeaGreen
For i = 0 To 2
button1(i) = New Button()
button1(i).Width = 50
button1(i).Height = 50
button1(i).Top = 100
button1(i).BackColor = Color.Red
button1(i).ForeColor = Color.White
button1(i).Left = (i * 50) + 30
button1(i).Text = i + 1
Me.Controls.Add(button1(i))
AddHandler button1(i).Click, AddressOf button_click
button1(i).BringToFront()
Next
For i = 3 To 5
button1(i) = New Button()
button1(i).Width = 50
button1(i).Height = 50
button1(i).Top = 160
button1(i).BackColor = Color.Gold
button1(i).ForeColor = Color.Black
button1(i).Left = ((i - 3) * 50) + 30
button1(i).Text = i + 1
Me.Controls.Add(button1(i))
AddHandler button1(i).Click, AddressOf button_click
button1(i).BringToFront()
Next
For i = 6 To 8
button1(i) = New Button()
button1(i).Width = 50
button1(i).Height = 50
button1(i).Top = 220
button1(i).BackColor = Color.SkyBlue
button1(i).ForeColor = Color.Black
button1(i).Left = ((i - 6) * 50) + 30
button1(i).Text = i + 1
Me.Controls.Add(button1(i))
AddHandler button1(i).Click, AddressOf button_click
button1(i).BringToFront()
Next
For i = 9 To 12
button1(i) = New Button()
button1(i).Width = 50
button1(i).Height = 50
button1(i).Top = ((i - 9) * 60) + 100
button1(i).BackColor = Color.Violet
button1(i).ForeColor = Color.White
button1(i).Left = (3 * 50) + 50
Me.Controls.Add(button1(i))
button1(i).BringToFront()
Next
button1(9).Text = ("+")
button1(10).Text = ("-")
button1(11).Text = ("*")
button1(12).Text = ("/")
AddHandler button1(9).Click, AddressOf button1_click
AddHandler button1(10).Click, AddressOf button2_click
AddHandler button1(11).Click, AddressOf button3_click
AddHandler button1(12).Click, AddressOf button4_click
buttonB = New Button()
buttonB.Width = 100
buttonB.Height = 50
buttonB.Top = 280
buttonB.BackColor = Color.BlueViolet
buttonB.Left = 50 + 30
Me.Controls.Add(buttonB)
buttonB.Text = (0)
AddHandler buttonB.Click, AddressOf button_click
buttonB.BringToFront()
Me.BackColor = Color.Aquamarine
BtnResult.BackColor = Color.BlueViolet
End Sub
Private Sub button_click(ByVal sender As Object, ByVal e As EventArgs)
txtvalue2.Text = sender.text
End Sub
Private Sub BtnResult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
BtnResult.Click
Dim i As Integer = 0
Dim a As Integer
Dim b As Integer
a = txtvalue1.Text
b = txtvalue2.Text
i=a-b
Select Case txtope.Text
Case "+"
i = Val(txtvalue1.Text)
Case "-"
i = Val(txtvalue1.Text)
Case "*"
i = Val(txtvalue1.Text)
Case "/"
i = Val(txtvalue1.Text)
+ Val(txtvalue2.Text)
- Val(txtvalue2.Text)
* Val(txtvalue2.Text)
/ Val(txtvalue2.Text)
Case Else
txtresult.Text = ("Try Again")
End Select
txtresult.Text = i
End Sub
Private Sub button1_click(ByVal sender As Object, ByVal e As EventArgs)
txtvalue1.Text = txtvalue2.Text
txtope.Text = "+"
txtvalue2.Clear()
End Sub
Private Sub button2_click(ByVal sender As Object, ByVal e As EventArgs)
txtvalue1.Text = txtvalue2.Text
txtope.Text = "-"
txtvalue2.Clear()
End Sub
Private Sub button3_click(ByVal sender As Object, ByVal e As EventArgs)
txtvalue1.Text = txtvalue2.Text
txtope.Text = "*"
txtvalue2.Clear()
End Sub
Private Sub button4_click(ByVal sender As Object, ByVal e As EventArgs)
txtvalue1.Text = txtvalue2.Text
txtope.Text = "/"
txtvalue2.Clear()
End Sub
End Class
Output:
Conclusion
From this practical work, I learned that the way of declare the array such as Dim
intStdnt() As Integer it will consist () after the variable to declare it. We also can
declare the textbox using array such as Dim Mark(3) As TextBox =
{Textbox1,TextBox2,TextBox3}. The number in the bracket is show the array we
required. We also can create array using button. First we need to declare 1 st, Dim
Button() As Button then use decorate the button it properties such as font,
backcolor,forecolor and etc. and then using the For..Next loop structure to create as
much as u like. And then Array divided to 2 dimension which is single dimension and
multi dimension for example to keep in the mark of 2 different classes contain of 10
students. Dim mark(2,10) As Integer it mean 2x10 matrix 2 for row and 10 for
column.