Back to Off Topic

Program Challange Visual Basic

over 8 years

Make this:

  1. Design the GUI and code for a program that will allow a user to enter three test scores. The program should then calculate the test average and display it.

  2. Include clearing the values when the user starts entering a new test score in the first text box, designating a default button, and using string concatenation and formatting to display the result.

  3. Include highlighting the text in the text boxes when the focus is received, testing the input for each test score to ensure that it is between 0 and 100, and disallowing any characters to be input except numbers and the period.

  4. Add a combo box to the user interface that will allow the user to select a preset curve value of 1 to 5 points. Use the FormClosing event and a message box to determine if the user truly wants to close the form.

  5. Use a one-dimensional array to store the entered test scores, and then compute the average from the array.

  6. Add a button that will write the test scores and the average to a sequential file.

  7. Implement a class that calculates the average score of three test scores.

over 8 years
There that's the solution
over 8 years
Private Sub scoreTextBox3_GotFocus(sender As Object, e As EventArgs) Handles scoreTextBox3.GotFocus
scoreTextBox3.SelectAll()
End Sub

Private Sub scoreTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles scoreTextBox.KeyPress, scoreTextBox2.KeyPress, scoreTextBox3.KeyPress
'allow only letters and the Backspace key
If e.KeyChar Like "[!0-9.]" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub

Private Sub scoreTextBox_TextChanged(sender As Object, e As EventArgs) Handles scoreTextBox.TextChanged, scoreTextBox2.TextChanged, scoreTextBox3.TextChanged
If String.IsNullOrWhiteSpace(DirectCast(sender, TextBox).Text) Then
addButton.Enabled = False
Else
addButton.Enabled = True
End If
End Sub

Private Sub saveButton_Click(sender As Object, e As EventArgs) Handles saveButton.Click
Dim outfile As IO.StreamWriter
Dim i As Integer
outfile = IO.File.CreateText("grades.txt, true")
For i = 0 To listBox.Items.Count - 1
outfile.WriteLine(listBox.Items.Item(i))
Next
outfile.WriteLine(averageLabel.Text)
outfile.Close()
End Sub
End Class
over 8 years
Private Sub MainForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Dim button As DialogResult
button = MessageBox.Show("Do you want to exit? Make sure you exported the file!",
"Exit Verification", MessageBoxButtons.YesNo,
MessageBoxIcon.Exclamation,
MessageBoxDefaultButton.Button2)
If button = DialogResult.No Then
e.Cancel = True
End If
End Sub



Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
addButton.Enabled = False
saveButton.Enabled = False
'Filling the curve box
curveTextBox.Items.Add("1")
curveTextBox.Items.Add("2")
curveTextBox.Items.Add("3")
curveTextBox.Items.Add("4")
curveTextBox.Items.Add("5")
curveTextBox.SelectedIndex = 0
End Sub

Private Sub scoreTextBox_GotFocus(sender As Object, e As EventArgs) Handles scoreTextBox.GotFocus
scoreTextBox.SelectAll()
End Sub

Private Sub scoreTextBox2_GotFocus(sender As Object, e As EventArgs) Handles scoreTextBox2.GotFocus
scoreTextBox2.SelectAll()
End Sub
over 8 years
If score3 > 100 Then
MessageBox.Show("Test score above 100, please enter your scores again", "Kent State University",
MessageBoxButtons.OK, MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1)
scoreTextBox.Clear()
scoreTextBox2.Clear()
scoreTextBox3.Clear()
Exit Sub
End If
If scoreTextBox.Text = "" OrElse scoreTextBox2.Text = "" OrElse scoreTextBox3.Text = "" Then
MessageBox.Show("Please re-enter your numbers between 0 and 100 in the textboxs below", "Kent State University",
MessageBoxButtons.OK, MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1)
scoreTextBox.Clear()
scoreTextBox2.Clear()
scoreTextBox3.Clear()
Exit Sub
End If
For i As Integer = 0 To total.Length - 1
If i = 0 Then
total(i) = score + curve
listBox.Items.Add(total(i))
End If
If i = 1 Then
total(i) = score2 + curve
listBox.Items.Add(total(i))
End If
If i = 2 Then
total(i) = score3 + curve
listBox.Items.Add(total(i))
End If
Next i
listNumber = listBox.Items.Count
If listNumber = 3 Then
addButton.Enabled = False
For Each j As Integer In total
totalAllInteger += j
Next
saveButton.Enabled = True
finalAverage = totalAllInteger / 3
finalAverage = Math.Round(finalAverage, 2)
averageLabel.Text = Convert.ToString(finalAverage)
End If
End Sub
over 8 years
' Project name: Tax Project
' Project purpose: Displays a sales tax amount
' Created/revised by: on

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm
Private Sub addButton_Click(sender As Object, e As EventArgs) Handles addButton.Click
Dim score As Double
Dim score2 As Double
Dim score3 As Double
Dim curve As Integer
Dim total(2) As Double
Dim totalAllInteger As Double = 0
Dim finalAverage As Double
Dim listNumber As Double

Double.TryParse(scoreTextBox.Text, score)
Double.TryParse(scoreTextBox2.Text, score2)
Double.TryParse(scoreTextBox3.Text, score3)
curve = Convert.ToInt32(curveTextBox.SelectedItem)

listBox.Items.Clear()
saveButton.Enabled = False
If score > 100 Then
MessageBox.Show("Test score above 100, please enter your scores again", "Kent State University",
MessageBoxButtons.OK, MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1)
scoreTextBox.Clear()
scoreTextBox2.Clear()
scoreTextBox3.Clear()
Exit Sub
End If
If score2 > 100 Then
MessageBox.Show("Test score above 100, please enter your scores again", "Kent State University",
MessageBoxButtons.OK, MessageBoxIcon.Stop,
MessageBoxDefaultButton.Button1)
scoreTextBox.Clear()
scoreTextBox2.Clear()
scoreTextBox3.Clear()
Exit Sub
End If
over 8 years
Na. I am doing it right now. Just wanted someone to do it with me.

Option Explicit On
Option Strict On
Option Infer Off

Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
addButton.Enabled = False
saveButton.Enabled = False
'Filling the curve box
curveTextBox.Items.Add("1")
curveTextBox.Items.Add("2")
curveTextBox.Items.Add("3")
curveTextBox.Items.Add("4")
curveTextBox.Items.Add("5")
curveTextBox.SelectedIndex = 0
End Sub

Private Sub scoreTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles scoreTextBox.KeyPress
'allow only letters and the Backspace key
If e.KeyChar Like "[!0-9]" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
End Class
over 8 years
This sounds like an attempt to make someone do your homework
over 8 years
I don't know Visual Basic.
over 8 years
here is hint:

Private Sub letterTextBox_KeyPress(sender As Object, e As KeyPressEventArgs) Handles letterTextBox.KeyPress
'allow only letters and the Backspace key
If e.KeyChar Like "[!0-9]" AndAlso
e.KeyChar <> ControlChars.Back Then
e.Handled = True
End If
End Sub
deletedover 8 years
english challenge: spell challenge correctly
over 8 years
I will display mine when I finish it
over 8 years
Nvm I can read