Respuesta :
Answer:
See text attachment for complete source code (for the answer) where I used comments to explain each line of the program
Explanation:
First, design the form using the following tools (and the accompanying properties) :
1 Label: Property: Text: Score
2 Buttons
Button1: Property: Name: btnAdd; Text: Add
Button2: Property: Name: btnDisplay; Text: Display
1 ListBox: Property: Visible: Hidden
1 TextBox: Property: Name: txtNum1
First, create the following function.
The function (named typecheck) validates input from the user (i.e. integer input only)
Function typecheck(ByVal input As String) As Boolean
Try
Convert.ToInt32(input)
[tex]Return\ True[/tex]
[tex]Catch\ ex\ As\ Exception[/tex]
[tex]Return\ False[/tex]
End Try
End Function
It returns true if the input is integer and false, if otherwise.
Next, double-click on the "Add" button and write the following lines of code:
Dim num1 As String
num1 = txtNum1.Text
If num1 IsNot String.Empty Then
If typecheck(num1) Then
[tex]ListBox1.Items.Add(num1)[/tex]
[tex]txtNum1.Text = String.Empty[/tex]
Else
[tex]MsgBox("Only[/tex] [tex]Integer[/tex] [tex]Inpu t")[/tex]
[tex]txtNum1.Text = String.Empty[/tex]
[tex]End\ If[/tex]
Else
[tex]MsgBox("Box[/tex] [tex]can\ not\ be\ empty")[/tex]
[tex]txtNum1.Text = String.Empty[/tex]
[tex]End\ If[/tex]
Next, double-click on the "Display" button and write the following lines of code:
If ListBox1.Items.Count > 0 Then
[tex]Dim\ max1, max2\ As\ Integer[/tex]
max1 = Convert.ToInt32(ListBox1.Items(0))
max2 = Convert.ToInt32(ListBox1.Items(0))
[tex]For\ count\ = 0\ To\ ListBox1.Items.Count - 1[/tex]
If Convert.ToInt32(ListBox1.Items([tex]count[/tex])) >= max1 Then
max1 = Convert.ToInt32(ListBox1.Items([tex]count[/tex]))
[tex]End\ If[/tex]
Next
[tex]For\ count\ = 0\ To\ ListBox1.Items.Count - 1[/tex]
If Convert.ToInt32(ListBox1.Items([tex]count[/tex])) >= max2 And Convert.ToInt32(ListBox1.Items([tex]count[/tex])) < max1 Then
max2 = Convert.ToInt32(ListBox1.Items([tex]count[/tex]))
[tex]End\ If[/tex]
Next
MsgBox("Highest Scores: " + max1.ToString() + " " + max2.ToString())
MsgBox("[tex]Total[/tex]: " + ListBox1.Items.Count.ToString())
[tex]End\ If[/tex]
ListBox1.Items.Clear()

