Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27412

VS 2010 How to check if Integer AND how to align the output in a ListBox.

$
0
0
I am a first year .Net Student and am working on a program for class called Distance Calculator in which you enter Vehicle speed as well as hours driven and it will output each hour's distance. I have been trying for about 1 hour to get two things working. This first is the Hours need to be an integer and I have tried using in the second Do statement 'Do Until > 0 & IntTime IS Integer' And other versions and cannot figure out how. The Second problem is when I output my text I need the listed 1-5 portion, shown in the provided picture, to line up to the left. If you have any questions feel free to ask. I have provided my Code and a picture of my output. Thanks again.

Code:

Option Strict On
Public Class FrmDistanceCalculator
    '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
        LbxDisplay.Font = New Font("Courier New", 8, FontStyle.Regular)
        Do Until DblSpeed > 0
            DblSpeed = CDec(InputBox("Please enter the speed of the vehicle in Miles Per Hour"))
        Loop


        Do Until IntTime > 0
            IntTime = CInt(InputBox("Please enter the amount of time, in hours, the vehicle has traveled"))
        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
            LbxDisplay.Items.Add("  " & IntTimeCounter.ToString & "              " & DblSpeedInd.ToString).ToString()
            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

Attached Images
 

Viewing all articles
Browse latest Browse all 27412

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>