Hello Everyone,
I am doing a project "Unit Length Converter" using VB.NET.
I have two dropdownlist, 10 lines of textboxes (20 textboxes each side) and one Calculate button.
Please see the graphical sample of my project I am doing right now:
http://sdrv.ms/XMElf7
I selected the units of length on the both side of the dropdownlists, for example at left side dropdownlist1 I selected the unit (From "Inches" and on the right side of the dropdownlist2, I selected the unit (To centimeter. Later, I typed the numbers in each textbox(es) on the left side, and the textbox(es) on the right side are the results for the unit centimeter conversion.
How to add values entered into each textbox1, textbox3, textbox5... to be display the results in the textbox2, textbox4, textbox6, so on... based on the calculation converter, using VB.NET code?
See my code below, I understand is not the right code:
Dim calculation As Double
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
FillDropDownList1()
FillDropDownList2()
End If
End Sub
Private Sub FillDropDownList1()
DropDownList1.Items.Add("Choose one...")
DropDownList1.Items.Add("Inches")
DropDownList1.Items.Add("Feet")
DropDownList1.Items.Add("Meters")
End Sub
Private Sub FillDropDownList2()
DropDownList2.Items.Add("Choose one...")
DropDownList2.Items.Add("Inches")
DropDownList2.Items.Add("Feet")
DropDownList2.Items.Add("Meters")
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim Num As Double
Dim val1 As Double = TextBox1.Text
Dim val2 As Double = TextBox2.Text
If Double.TryParse(TextBox1.Text, Num) = False Then
Label3.Text = "Please enter a numeric value"
Exit Sub
End If
If DropDownList1.SelectedItem.Text <> "" Then
Select Case DropDownList1.SelectedItem.Text
Case "inches"
Num = CDbl(TextBox1.Text)
End Select
If DropDownList2.SelectedItem.Text <> "" Then
Select Case DropDownList2.SelectedItem.Text
Case "centimeter"
val1 = TextBox2.Text * 0.254
End Select
End If
End If
Protected Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Protected Sub TextBox2_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End class
I have been doing doing this for a few days unsuccefully. You help is very much appreciative. Don't forget to view my graphical project.
Thanks
I am doing a project "Unit Length Converter" using VB.NET.
I have two dropdownlist, 10 lines of textboxes (20 textboxes each side) and one Calculate button.
Please see the graphical sample of my project I am doing right now:
http://sdrv.ms/XMElf7
I selected the units of length on the both side of the dropdownlists, for example at left side dropdownlist1 I selected the unit (From "Inches" and on the right side of the dropdownlist2, I selected the unit (To centimeter. Later, I typed the numbers in each textbox(es) on the left side, and the textbox(es) on the right side are the results for the unit centimeter conversion.
How to add values entered into each textbox1, textbox3, textbox5... to be display the results in the textbox2, textbox4, textbox6, so on... based on the calculation converter, using VB.NET code?
See my code below, I understand is not the right code:
Dim calculation As Double
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
FillDropDownList1()
FillDropDownList2()
End If
End Sub
Private Sub FillDropDownList1()
DropDownList1.Items.Add("Choose one...")
DropDownList1.Items.Add("Inches")
DropDownList1.Items.Add("Feet")
DropDownList1.Items.Add("Meters")
End Sub
Private Sub FillDropDownList2()
DropDownList2.Items.Add("Choose one...")
DropDownList2.Items.Add("Inches")
DropDownList2.Items.Add("Feet")
DropDownList2.Items.Add("Meters")
End Sub
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
Dim Num As Double
Dim val1 As Double = TextBox1.Text
Dim val2 As Double = TextBox2.Text
If Double.TryParse(TextBox1.Text, Num) = False Then
Label3.Text = "Please enter a numeric value"
Exit Sub
End If
If DropDownList1.SelectedItem.Text <> "" Then
Select Case DropDownList1.SelectedItem.Text
Case "inches"
Num = CDbl(TextBox1.Text)
End Select
If DropDownList2.SelectedItem.Text <> "" Then
Select Case DropDownList2.SelectedItem.Text
Case "centimeter"
val1 = TextBox2.Text * 0.254
End Select
End If
End If
Protected Sub TextBox1_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Protected Sub TextBox2_TextChanged(sender As Object, e As System.EventArgs) Handles TextBox2.TextChanged
End Sub
End class
I have been doing doing this for a few days unsuccefully. You help is very much appreciative. Don't forget to view my graphical project.
Thanks