Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Distance Converter In the English measurement system, 1 yard equals 3 feet and 1

ID: 3767710 • Letter: D

Question

Distance Converter
In the English measurement system, 1 yard equals 3 feet and 1 foot equals 12 inches.
Use this information to create an application that lets the user convert distances to
and from inches, feet, and yards.

Figure 4-35 shows an example of how the application’s form might appear. In the
example, the user enters the distance to be converted into a TextBox. A ListBox
allows the user to select the units being converted from, and another ListBox allows
the user to select the units being converted to.


Figure 4-35 The Distance Converter form
Note: Be sure to handle the situation where the user picks the same units from both
list boxes. The converted value will be the same as the value entered.

Explanation / Answer

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If ListBox1.SelectedItem = "Inches" And ListBox2.SelectedItem = "Feet" Then
TextBox2.Text = Val(TextBox1.Text) / 12
End If
If ListBox1.SelectedItem = "Inches" And ListBox2.SelectedItem = "Yards" Then
TextBox2.Text = Val(TextBox1.Text) / 36
End If
If ListBox1.SelectedItem = "Yards" And ListBox2.SelectedItem = "Inches" Then
TextBox2.Text = Val(TextBox1.Text) * 36
End If

If ListBox1.SelectedItem = "Yards" And ListBox2.SelectedItem = "Feet" Then
TextBox2.Text = Val(TextBox1.Text) * 3
End If

If ListBox1.SelectedItem = "Feet" And ListBox1.SelectedItem = "Inches" Then
TextBox2.Text = Val(TextBox1.Text) * 12
End If

If ListBox1.SelectedItem = "Feet" And ListBox2.SelectedItem = "Yard" Then
TextBox2.Text = Val(TextBox1.Text) / 3
End If

If ListBox1.SelectedItem = ListBox2.SelectedItem Then
TextBox2.Text = Val(TextBox1.Text)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
End Class