# Speed Conversions

• ### Question

• I'm trying to make a VB program that will use a loop to create a list for the KPH to MPH conversions the

formula is MPH = KPH * 0.6214. The list needs to be from 60kph to 130kph with increments of 5 (65, 70, 75, 80.etc)

any ideas on how I can do this? thanks

Sunday, April 1, 2018 6:58 AM

### All replies

• I'm trying to make a VB program that will use a loop to create a list for the KPH to MPH conversions the formula is MPH = KPH * 0.6214. The list needs to be from 60kph to 130kph with increments of 5 (65, 70, 75, 80.etc)

You haven't indicated what the problem is.   Is it in constructing the loop?  See:
https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/for-next-statement

Or is it in doing the calculation, displaying the result, or something else?

• Proposed as answer by Sunday, April 1, 2018 10:29 AM
Sunday, April 1, 2018 7:40 AM
• I guess homework, because this is so easy.

Success
Cor

Sunday, April 1, 2018 10:29 AM
• Here are some ideas to get you started.

```Public Class Form3
Private WithEvents Nud1 As New NumericUpDown With {.Parent = Me, .Text = "Go",
.Minimum = 0, .Maximum = 150, .Increment = 5, .Value = 100,
.Location = New Point(100, 80), .Size = New Size(60, 30)}
Private WithEvents Label1 As New Label With {.Parent = Me, .Text = "Kilometer / Hour", .ForeColor = Color.AntiqueWhite,
.Location = New Point(Nud1.Right + 10, Nud1.Top)}
Private WithEvents Picturebox1 As New PictureBox With {.Parent = Me,
.Dock = DockStyle.Top, .Size = New Size(250, 70)}
Private ConversionFactor As Double = 0.6214    'kph to mph

Private Sub Nud1_ValueChanged(sender As Object, e As EventArgs) Handles Nud1.ValueChanged
Picturebox1.Invalidate()
End Sub

Private Sub Picturebox1_Paint(sender As Object, e As PaintEventArgs) Handles Picturebox1.Paint

Dim dx As Single = CSng(Picturebox1.ClientSize.Width / 150)

With e.Graphics
.Clear(Color.Black)
.ScaleTransform(dx, 1)
.FillRectangle(Brushes.Silver, 0, 30, Picturebox1.ClientSize.Width, 3)

Using p1 As New Pen(Color.Yellow, 2),
f As New Font("arial", 15 / dx),
brScale As New SolidBrush(Color.AntiqueWhite),
brNeedle As New SolidBrush(Color.Lime)

'draw mph scale
For x As Single = 0 To 150 Step 20
.DrawLine(Pens.GreenYellow, x, 20, x, 40)
.DrawString(x.ToString, f, brScale, x - 10, 4)
Next

'draw kph conversion to mph
Dim mph As Double = Nud1.Value * ConversionFactor
.FillRectangle(brNeedle, 0, 30, CInt(mph), 10)
.DrawString(mph.ToString("f1") & " Mph", f, brNeedle, CInt(mph - 10), 50)

End Using
End With

End Sub

Private Sub picturebox1_SizeChanged(sender As Object, e As EventArgs) Handles picturebox1.SizeChanged
picturebox1.Invalidate()
End Sub

Text = "Kph to Mph"
BackColor = Color.DimGray
End Sub
End Class```

Sunday, April 1, 2018 10:39 AM
• I guess you are a student and it is a school assignment and suppose it is OK you ask questions about it. But, I'm afraid you need to provide your code. If you don't have any code, I hesitate to provode answer.

Ashidacchi -- http://hokusosha.com/

Sunday, April 1, 2018 12:03 PM
• Use a loop with a step of 5 and add the answers to your MPH list(Of T).

La vida loca

Sunday, April 1, 2018 4:18 PM
• This is my code right now but I'm not sure how to add an increment of 5.

Private Sub btnShow_Click(sender As Object, e As EventArgs) Handles btnShow.Click
Dim intMPH As Integer
Dim intKPH As Integer
Dim strSpeed As String

For intMPH = 60 To 130
' Calculate the speed conversion.
intKPH = CInt(intMPH * 0.6214)
' Display string.
strSpeed = intMPH.ToString() & " KPH " &
" is " & intKPH.ToString() & " MPH"
'show output.
Next
End Sub
Monday, April 2, 2018 6:06 PM
• Never Mind I figured it out thanks
Monday, April 2, 2018 6:21 PM
• Hi,

Thank you for showing code.

For intMPH = 60 To 130 Step 5

This is inceremental by 5: 60, 65, 70, ... 120, 125, 130

Good luck!

Ashidacchi -- http://hokusosha.com/

Monday, April 2, 2018 8:18 PM