Option Strict On
Public Class Form1
Private Sub btnDistance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDistance.Click
'The btnEnterSpeed click event accepts and displays up to ten speeds from the user
'and then calculates and displays average speed
'Declare and initialize variable
Dim intSpeedLimit As Integer
Dim strHours As String
Dim decHours As Decimal = 0D
Dim decTotalHours As Decimal = 0D
Dim decTotalDistance As Decimal
Dim strInputMessage As String = "Enter the Hours for Day #"
Dim strInputHeading As String = "Hours Per Day"
Dim strNormalMessage As String = "Enter the Hours for Day #"
Dim strNonNumericError As String = "Error - Enter a number for Day #"
Dim strNegativeError As String = "Error - Enter positive number for Day #"
'Declare and initalize loop variable
Dim strCancelClicked As String = ""
intSpeedLimit = Convert.ToInt32(txtSpeedLimit.Text)
strHours = txtNumberofDays.Text
Dim intEndCount As Integer
Dim intEndHours As Integer
Dim intNumberofHours As Integer = 1
'This loop allows the user to enter the speed of up to 10 vehicles.
'The loop terminates when the user has entered 10 speeds or the user
'click the cCancel button or the Close button in the InputBox
strHours = InputBox(strInputMessage & intNumberofHours, strInputHeading, " ")
Do Until intEndCount > intEndHours Or strHours = strCancelClicked
If IsNumeric(strHours) Then
decHours = Convert.ToDecimal(strHours)
If decHours > 0 Then
lstHours.Items.Add(decHours)
decTotalHours += decHours
intNumberofHours += 1
strInputMessage = strNormalMessage
Else
strInputMessage = strNegativeError
End If
Else
strInputMessage = strNonNumericError
End If
If intNumberofHours <= intEndHours Then
strHours = InputBox(strInputMessage & intNumberofHours, strInputHeading, " ")
End If
Loop
' Makes label visible
lblTotalNumberofMiles.Visible = True
'Calculates and displays average speed
If intNumberofHours > 1 Then
decTotalDistance = intSpeedLimit * decTotalHours
lblTotalNumberofMiles.Text = "Total Miles you will drive " & decTotalDistance.ToString("F1") & " Miles"
Else
lblTotalNumberofMiles.Text = "Hours entered"
End If
'Disable the Enter Speed button
btnDistance.Enabled = False
End Sub
Private Sub mnuClear_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuClear.Click
'The mnuClear click event clears the listbox and hides the
'average speed label. It also enables the Enter Speed button
lstHours.Items.Clear()
lblNumberofDays.Visible = False
btnDistance.Enabled = True
End Sub
Private Sub mnuExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExit.Click
' The mnuExit click event closes the window and exits the application
Close()
End Sub
End Class
I cannot figure out how to incorporate the number of days into the input box then get it to loop and count the number of times the User inputs in the number of days. Then I have to incorporate it into the equation to get the total distance D = MPH * Hours. What I have right now wil not count up the number of days and locks up after I input one number and will not add anything to the listbox. Because I also have to make sure that they cant add nonnumaric values and the number of hours per day cannot exceed 20. I have put things in and taken them out but it has been 2 days and I am lost now

New Topic/Question
Reply



MultiQuote




|