In visual studio I am trying to make a us distance converter
In visual studio I am trying to make a u.s. distance converter to metric converter. It involves three group boxes, one with two radio buttons and the other two with three radio buttons. It also includes a button, a text box and a label. In the first group box \"grpUnits\" the radio buttons are u.s. distance, and metric (optDistance, optMetric) the other two group boxes are labeled input and output and my text box is txtInput. Please help me get my converter and radio buttons working I will rate Highly. The goal is to select which unit from the first group box(distance u.s., or metric) and then in the second and third select the method i want it to go to such as convert inches to centimeters. For some reason though I can not get my code to work properly or select the radiobuttons. Here is my code:
Public Class Form1
Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click
\'if number is not entered
If (txtInput.Text <> \"\") Then
End If
MessageBox.Show(\"Input the digit to convert\")
Dim x As Double
Dim y As Double
y = 0
\'convert Feet to Millimeters
If (optFeet.Checked = True And optMillimeters.Checked = True) Then
y = x * 0.305
End If
\'convert Feet to Meters
If (optFeet.Checked = True And optMeters.Checked = True) Then
y = x * 0.3048
End If
\'convert Feet to Centimeters
If (optFeet.Checked = True And optCentimeters.Checked = True) Then
y = x * 30.48
End If
\'convert Inches to Millimeters
If (optInches.Checked = True And optMillimeters.Checked = True) Then
y = x * 25.4
End If
\'convert Inches to Meters
If (optInches.Checked = True And optMeters.Checked = True) Then
y = x * 0.025
End If
\'convert Inches to Centimeters
If (optInches.Checked = True And optCentimeters.Checked = True) Then
y = x * 2.54
End If
\'convert Yards to Millimeters
If (optYards.Checked = True And optMillimeters.Checked = True) Then
y = x * 914.4
End If
\'convert Yards to Meters
If (optYards.Checked = True And optMeters.Checked = True) Then
y = x * 0.914
End If
\'convert Yards to Centimeters
If (optYards.Checked = True And optCentimeters.Checked = True) Then
y = x * 91.44
End If
End Sub
End Class
Solution
\'Changes are made in bold letters and rest of code is already same and some minor changes
Public Class Form1
Private Sub btnConvert_Click(sender As Object, e As EventArgs) Handles btnConvert.Click
Dim x As Double
Dim y As Double
\'if text input is not empty
If (txtInput.Text <> \"\") Then
\'convert text to integer using Convert.ToInt32 method
\'now you have user given input value
x=Convert.ToInt32(txtInput.Text)
else
\'display a message box if text input is empty
MessageBox.Show(\"Input the digit to convert\")
End If
y = 0
\'convert Feet to Millimeters
If (optFeet.Checked = True And optMillimeters.Checked = True) Then
y = x * 0.305
End If
\'rest of the code is same no changes
\'convert Feet to Meters
If (optFeet.Checked = True And optMeters.Checked = True) Then
y = x * 0.3048
End If
\'convert Feet to Centimeters
If (optFeet.Checked = True And optCentimeters.Checked = True) Then
y = x * 30.48
End If
\'convert Inches to Millimeters
If (optInches.Checked = True And optMillimeters.Checked = True) Then
y = x * 25.4
End If
\'convert Inches to Meters
If (optInches.Checked = True And optMeters.Checked = True) Then
y = x * 0.025
End If
\'convert Inches to Centimeters
If (optInches.Checked = True And optCentimeters.Checked = True) Then
y = x * 2.54
End If
\'convert Yards to Millimeters
If (optYards.Checked = True And optMillimeters.Checked = True) Then
y = x * 914.4
End If
\'convert Yards to Meters
If (optYards.Checked = True And optMeters.Checked = True) Then
y = x * 0.914
End If
\'convert Yards to Centimeters
If (optYards.Checked = True And optCentimeters.Checked = True) Then
y = x * 91.44
End If
\'Now set value of y to corresponding text box
\'we assume that name of the text box is outputTextBox
outputTextBox.Text=Convert.ToString(y)
End Sub
End Class
----------------------------------------------------------------------------
Note : The form design and group boxes and radio button setting are same as with yours project in vb.net.


