It's Me again. I am having trouble trying to format the output using the String.Format Method. I have provided the code as well as my output and the output my professor said it should look like. Thanks
Thanks!
Code:
Option Strict On
Public Class FrmDistanceCalculator
' Public Shared Function Format( _
' ByVal Expression As Object, _
' ByVal Style As String _
' ) As String
' End Function
'Todd J. Rohrer .Net Programing 101
Private Sub BtnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnCalculate.Click
Dim DblSpeed As Double
Dim IntTime As Integer
Dim SB As New System.Text.StringBuilder
Dim IntTimeCounter As Integer = 1
'Dim Style1 As String = "(####.##)"
LbxDisplay.Font = New Font("Courier New", 8, FontStyle.Regular)
LbxDisplay.Items.Clear()
Do Until DblSpeed > 0
If Double.TryParse(InputBox("Please enter the speed of the vehicle in Miles Per Hour"), DblSpeed) = False Or DblSpeed < 1 Then
MessageBox.Show("Incorrect Entry Entered, Please Try Again")
Exit Sub
End If
Loop
Do Until IntTime > 0
If Integer.TryParse(InputBox("Please enter the amount of time, in hours, the vehicle has traveled"), IntTime) = False Or IntTime < 1 Then
MessageBox.Show("Incorrect Entry Entered, Please Try Again")
Exit Sub
End If
Loop
Dim DecMilesTraveled As Double = DblSpeed * IntTime
Dim DblSpeedInd As Double = DblSpeed
LbxDisplay.Items.Add("Vehicle Speed: " & DblSpeed.ToString & " MPH" & ControlChars.CrLf)
LbxDisplay.Items.Add("Time Traveled: " & IntTime.ToString & ControlChars.CrLf & ControlChars.CrLf & " Hours")
LbxDisplay.Items.Add("Hours: " & " Distance Traveled" & ControlChars.CrLf)
LbxDisplay.Items.Add("_________________________________" & ControlChars.CrLf)
Do Until IntTimeCounter > IntTime
DblSpeedInd.ToString("n2")
LbxDisplay.Items.Add(" " & IntTimeCounter.ToString & " " & DblSpeedInd.ToString("n1"))
' LbxDisplay.Items.Add(" " & IntTimeCounter.ToString & " " & (String.Format("{0,4} {1,17}", DblSpeedInd)))
IntTimeCounter = IntTimeCounter + 1
DblSpeedInd = DblSpeedInd + DblSpeed
Loop
DblSpeedInd = DblSpeedInd - DblSpeed
LbxDisplay.Items.Add("Total Distance: " & DblSpeedInd)
End Sub
Private Sub BtnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnExit.Click
Me.Close()
End Sub
Private Sub BtnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnClear.Click
LbxDisplay.Items.Clear()
End Sub
End Class