use the following code. before use it take three textboxes(text1,trxt2,text3); one listbox(list1) ; one label(label1); and a commandbutton(command1)
Option Explicit
Private Sub Command1_Click()
Dim num As Integer
num = 0
begin:
num = InputBox("Enter exam marks. -1 to end", "Marks")
If num > -1 Then
List1.AddItem num
GoTo begin
End If
Text1.Text = "Max :" & GetMaxMark
Text2.Text = "Min :" & GetMinMark
Text3.Text = "Avg :" & GetAvg
Call Result
End Sub
Public Function GetMaxMark() As Integer 'to find out the maximum mark
Dim i As Integer, max As Integer
max = 0
For i = 0 To List1.ListCount - 1 Step 1
If Val(List1.List(i)) > max Then
max = Val(List1.List(i))
End If
Next i
GetMaxMark = max
End Function
Public Function GetMinMark() As Integer 'to find out the minimum mark
Dim i As Integer, min As Integer
min = List1.List(0)
For i = 0 To List1.ListCount - 1 Step 1
If Val(List1.List(i)) < min Then
min = Val(List1.List(i))
End If
Next i
GetMinMark = min
End Function
Public Function GetAvg() As Double 'to find out the average
Dim i As Integer, sum As Integer
sum = 0
For i = 0 To List1.ListCount - 1 Step 1
sum = sum + Val(List1.List(i))
Next i
GetAvg = sum / List1.ListCount
GetAvg = Format(GetAvg, "0.00")
End Function
Public Sub Result() 'to print the overall result status
Dim i As Integer, above40 As Integer, per As Double
above40 = 0
For i = 0 To List1.ListCount - 1 Step 1
If Val(List1.List(i)) >= 40 Then
above40 = above40 + 1
End If
Next i
per = (above40 * 100) / List1.ListCount
If per >= 30 Then
Label1.Caption = "GREAT WORK" & vbCrLf & "Passing Rate :" & per & "%"
Else
Label1.Caption = "HIGH FAILURE RATE" & vbCrLf & "Passing Rate :" & per & "%"
End If
End Sub
see the screenshot also
hope this will help you
regards
Shouvik