Write a VB program to find out the highest and lowest mark and displayed every time the user add a mark into the list box.
The program should allow user to key in the mark on the text box and insert the mark into the list box suing the Insert button. After the mark is inserted, the highest mark and lowest mark within the list box will be displayed on the corresponding text box.
The interface should be as followed:
Example
Mark: 57(TextBox) ListBox
29
Insert(Button) 74
45
Highest:87(TextBox) 87
Lowest: 26(TextBox) 26
66
35
77
73
57
Public Class frmMain
Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
Dim mark As Integer
Integer.TryParse(txtMark.Text, mark)
lstMarks.Items.Add(mark.ToString())
Dim highestMark As Integer = Integer.Parse(lstMarks.Items(0))
Dim lowestMark As Integer = Integer.Parse(lstMarks.Items(0))
For i As Integer = 1 To lstMarks.Items.Count - 1
If Integer.Parse(lstMarks.Items(i)) > highestMark Then
highestMark = Integer.Parse(lstMarks.Items(i))
End If
If Integer.Parse(lstMarks.Items(i)) < lowestMark Then
lowestMark = Integer.Parse(lstMarks.Items(i))
End If
Next
txtHighestMark.Text = highestMark.ToString()
txtLowestMark.Text = lowestMark.ToString()
End Sub
End Class
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class frmMain
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.txtMark = New System.Windows.Forms.TextBox()
Me.Label1 = New System.Windows.Forms.Label()
Me.btnInsert = New System.Windows.Forms.Button()
Me.lstMarks = New System.Windows.Forms.ListBox()
Me.txtHighestMark = New System.Windows.Forms.TextBox()
Me.Label2 = New System.Windows.Forms.Label()
Me.txtLowestMark = New System.Windows.Forms.TextBox()
Me.Label3 = New System.Windows.Forms.Label()
Me.Label4 = New System.Windows.Forms.Label()
Me.SuspendLayout()
'
'txtMark
'
Me.txtMark.Location = New System.Drawing.Point(113, 18)
Me.txtMark.Name = "txtMark"
Me.txtMark.Size = New System.Drawing.Size(100, 20)
Me.txtMark.TabIndex = 0
'
'Label1
'
Me.Label1.AutoSize = True
Me.Label1.Location = New System.Drawing.Point(45, 21)
Me.Label1.Name = "Label1"
Me.Label1.Size = New System.Drawing.Size(62, 13)
Me.Label1.TabIndex = 1
Me.Label1.Text = "Enter Mark:"
'
'btnInsert
'
Me.btnInsert.Location = New System.Drawing.Point(113, 44)
Me.btnInsert.Name = "btnInsert"
Me.btnInsert.Size = New System.Drawing.Size(100, 23)
Me.btnInsert.TabIndex = 2
Me.btnInsert.Text = "Insert"
Me.btnInsert.UseVisualStyleBackColor = True
'
'lstMarks
'
Me.lstMarks.FormattingEnabled = True
Me.lstMarks.Location = New System.Drawing.Point(113, 98)
Me.lstMarks.Name = "lstMarks"
Me.lstMarks.Size = New System.Drawing.Size(100, 121)
Me.lstMarks.TabIndex = 3
'
'txtHighestMark
'
Me.txtHighestMark.Enabled = False
Me.txtHighestMark.Location = New System.Drawing.Point(113, 225)
Me.txtHighestMark.Name = "txtHighestMark"
Me.txtHighestMark.Size = New System.Drawing.Size(100, 20)
Me.txtHighestMark.TabIndex = 0
'
'Label2
'
Me.Label2.AutoSize = True
Me.Label2.Location = New System.Drawing.Point(34, 228)
Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(73, 13)
Me.Label2.TabIndex = 1
Me.Label2.Text = "Highest Mark:"
'
'txtLowestMark
'
Me.txtLowestMark.Enabled = False
Me.txtLowestMark.Location = New System.Drawing.Point(113, 251)
Me.txtLowestMark.Name = "txtLowestMark"
Me.txtLowestMark.Size = New System.Drawing.Size(100, 20)
Me.txtLowestMark.TabIndex = 0
'
'Label3
'
Me.Label3.AutoSize = True
Me.Label3.Location = New System.Drawing.Point(34, 254)
Me.Label3.Name = "Label3"
Me.Label3.Size = New System.Drawing.Size(71, 13)
Me.Label3.TabIndex = 1
Me.Label3.Text = "Lowest Mark:"
'
'Label4
'
Me.Label4.AutoSize = True
Me.Label4.Location = New System.Drawing.Point(110, 78)
Me.Label4.Name = "Label4"
Me.Label4.Size = New System.Drawing.Size(50, 13)
Me.Label4.TabIndex = 1
Me.Label4.Text = "All Marks"
'
'frmMain
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(240, 287)
Me.Controls.Add(Me.lstMarks)
Me.Controls.Add(Me.btnInsert)
Me.Controls.Add(Me.Label3)
Me.Controls.Add(Me.Label4)
Me.Controls.Add(Me.Label2)
Me.Controls.Add(Me.Label1)
Me.Controls.Add(Me.txtLowestMark)
Me.Controls.Add(Me.txtHighestMark)
Me.Controls.Add(Me.txtMark)
Me.Name = "frmMain"
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Highest and lowest mark"
Me.ResumeLayout(False)
Me.PerformLayout()
End Sub
Friend WithEvents txtMark As System.Windows.Forms.TextBox
Friend WithEvents Label1 As System.Windows.Forms.Label
Friend WithEvents btnInsert As System.Windows.Forms.Button
Friend WithEvents lstMarks As System.Windows.Forms.ListBox
Friend WithEvents txtHighestMark As System.Windows.Forms.TextBox
Friend WithEvents Label2 As System.Windows.Forms.Label
Friend WithEvents txtLowestMark As System.Windows.Forms.TextBox
Friend WithEvents Label3 As System.Windows.Forms.Label
Friend WithEvents Label4 As System.Windows.Forms.Label
End Class
Comments
Leave a comment