I have been working on a challenge for my beginner coding class and I hit a snag on one of the challenges. The program I am coding is supposed to bring up two prompt windows when the button is pressed, asking the user to enter how many hours they would like to travel in a day (the maximum being 20) and the speed limit. After the user enters the information the two values should be multiplied and displayed in a list box, thus giving the distance they can travel. I have scrapped my code twice already and started fresh; while I feel I'm getting closer to the solution, my code still isn't working. The two windows pop up alright and I can input values, but it keeps entering a 0 in the list box after the second value is entered. Any quick help would be appreciated, I am under a bit of a time crunch and this program has me about ripping my hair out.
This is my code for when the button is clicked.
Dim strSpeedLimit As String Dim strHours As String Dim decSpeedLimit As Decimal Dim decHours As Decimal Dim decDistance As Decimal = decSpeedLimit * decHours Dim strNormalMessage1 As String = "Enter the Speed Limit" Dim strNormalMessage2 As String = "Enter how many hours you would like to travel" Dim strInputMessage1 As String = "Enter the Speed Limit" Dim strInputHeading1 As String = "Enter Speed" Dim strInputMessage2 As String = "Enter how many hours you would like to travel in one day" Dim strInputHeading2 As String = "Enter Hours" Dim strNegativeError As String = "Enter a positive number" Dim strOver20Error As String = "Error - Enter a number less than or equal to twenty" Dim strNonNumericError As String = "Error - Enter a numeric value" Dim strErrorHeader As String = "Error" Dim intNumberOfEntries As Integer = 1 Dim intMaxNumberOfEntries As Integer = 7 strSpeedLimit = InputBox(strInputMessage1, strInputHeading1) strHours = InputBox(strInputMessage2, strInputHeading2) If IsNumeric(strSpeedLimit) Then decSpeedLimit = Convert.ToDecimal(strSpeedLimit) If decSpeedLimit > 0 And decHours > 0 And decHours < 20 Then strInputMessage1 = strNormalMessage1 Else strInputMessage1 = strNegativeError End If Else strInputMessage1 = strNonNumericError End If If IsNumeric(strHours) Then decHours = Convert.ToDecimal(strHours) If decHours > 0 And decHours < 20 Then strInputMessage2 = strNormalMessage2 Else strInputMessage2 = strOver20Error End If Else strInputMessage2 = strNonNumericError End If lstDistance.Items.Add(decDistance.ToString) intNumberOfEntries += 1 End Sub
Sorry for how messy the code is. Any help would be appreciated greatly.