user function For Conversion table for Length

Last Reply 8 days ago By pandeyism

Posted 8 days ago

all conversion done in single function . user select meter to inch output get in inch 

 

Units	m	in.	ft.	yd.
Metre,m	1	39.37	3.28	1.09
Inch, in(")	0.0254	1	0.083	0.02
Foot, ft(')	0.3048	12	1	0.33
Yard, yd.	0.914	35	3	1
Mile	1609		5280	1760
Nautical Mile	1852		6076	
Fathom	1.829	72	6	2

 

vishalkal has viewed this question 3 days ago.
Posted 8 days ago

Hi vishalkal,

Will you please explain your requirement with more details.


Posted 8 days ago

there are 2 combo box list of Length Unit meter,inch,foot

user enter input value and then select combobox value from to like that meter to inch then output display in third control like that textbox 

my requirement is user enter value and select value from to in runtime then value convert to that selected type at runtime

so i want user function means user pass value and from to type that means 3 parameter in function he gets output

 


Posted 8 days ago

Hi vishalkal,

Please refer below sample.

Namespaces

C#

using System.Windows.Forms;

Code

C#

private void btnSubmit_Click(object sender, EventArgs e)
{
    int number = Convert.ToInt32(textBox1.Text);
    if (comboBox1.Text.ToLower() == "meter" && comboBox2.Text.ToLower() == "inch")
    {
        double inches;

        inches = number * 39.3701;
        textBox2.Text = inches.ToString();
    }
    else if (comboBox1.Text.ToLower() == "feet" && comboBox2.Text.ToLower() == "meter")
    {
        double feet;
        feet = number * 0.3048;
    }

    else if (comboBox1.Text.ToLower() == "meter" && comboBox2.Text.ToLower() == "feet")
    {
        double feet;
        feet = number * 3.28084;
        textBox2.Text = feet.ToString();
    }

    else if (comboBox1.Text.ToLower() == "inch" && comboBox2.Text.ToLower() == "meter")
    {
        double inchToMeter;
        inchToMeter = number * 0.0254;
        textBox2.Text = inchToMeter.ToString();
    }

    else if (comboBox1.Text.ToLower() == "inch" && comboBox2.Text.ToLower() == "feet")
    {
        double inchToFeet;
        inchToFeet = number * 0.0833333;
        textBox2.Text = inchToFeet.ToString();
    }

    else if (comboBox1.Text.ToLower() == "feet" && comboBox2.Text.ToLower() == "inch")
    {
        double feetToinch;
        feetToinch = number * 12;
        textBox2.Text = feetToinch.ToString();
    }
}

VB.Net

Private Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim number As Integer = Convert.ToInt32(textBox1.Text)
    If comboBox1.Text.ToLower() = "meter" AndAlso comboBox2.Text.ToLower() = "inch" Then
        Dim inches As Double
        inches = number * 39.3701
        textBox2.Text = inches.ToString()
    ElseIf comboBox1.Text.ToLower() = "feet" AndAlso comboBox2.Text.ToLower() = "meter" Then
        Dim feet As Double
        feet = number * 0.3048
    ElseIf comboBox1.Text.ToLower() = "meter" AndAlso comboBox2.Text.ToLower() = "feet" Then
        Dim feet As Double
        feet = number * 3.28084
        textBox2.Text = feet.ToString()
    ElseIf comboBox1.Text.ToLower() = "inch" AndAlso comboBox2.Text.ToLower() = "meter" Then
        Dim inchToMeter As Double
        inchToMeter = number * 0.0254
        textBox2.Text = inchToMeter.ToString()
    ElseIf comboBox1.Text.ToLower() = "inch" AndAlso comboBox2.Text.ToLower() = "feet" Then
        Dim inchToFeet As Double
        inchToFeet = number * 0.0833333
        textBox2.Text = inchToFeet.ToString()
    ElseIf comboBox1.Text.ToLower() = "feet" AndAlso comboBox2.Text.ToLower() = "inch" Then
        Dim feetToinch As Double
        feetToinch = number * 12
        textBox2.Text = feetToinch.ToString()
    End If
End Sub

Screenshot