[RESOLVED] Easy Conversions? (e.g. Millimeters to Inches)
Hi, I'm just wondering (this is SO noobish of me) if there is an easy way to convert units. Up until now, I have inserted a combobox, and, depending on what's in it, converted something in a textbox (numeric value). For example:
Code:
Sub ConvertButton_Click(blah blah blah blah) Handles ConvertButton_Click
Dim conversionanswer As Double
If combobox1.Text = "Feet to inches" Then
conversionanswer = textbox1.text * 12
ElseIf combobox1.Text = "Millimeters to inches" Then
conversionanswer = textbox1.text * 0.4
EndIf
label1.Text = conversionanswer
End Sub
Something akin to that (I know, sloppy code that probably doesn't work ;).) I'm looking for something like two comboxboxes each with a unit and a textbox for number of units with a "Convert!" button. Can anyone help? Thanks! :)
(EDIT: Is this the right section? My app is for Windows Mobile, but this is conceptual VB...)
Re: Easy Conversions? (e.g. Millimeters to Inches)
For each item in a combo, keep track of how many of the smallest unit (presumably millimetres) it is - so a centimetre is 10, an inch is something like 25.4, etc.
You can then divide your number by the scale in one combo, and multiply by the scale in the other.
For a value of 50, the conversion from cm to inches would be: 50 / 25.4 * 10, which is about 20
Quote:
(EDIT: Is this the right section? My app is for Windows Mobile, but this is conceptual VB...)
While it is general VB at the moment, that may change... so this forum is apt. :)
Re: Easy Conversions? (e.g. Millimeters to Inches)
Ok, this is going to sound really stupid, but you take the textbox data, divide it by the scale in the other combobox, and multiply it by the other? Can you please give me another example? Thanks again for your quick and great response. :)
EDIT: So how would you find the scale numbers? Thanx again.
Re: Easy Conversions? (e.g. Millimeters to Inches)
Another example would be 2 metres to centimetres
A metre is 1000mm and a centimetre is 10mm, so it would be:
2 [m] / 10 [mm per cm] * 1000 [mm per m] = 200 [cm]
There are many places to find out the scale, including google. The important thing is to have them all measured in the same units (such as mm).
Re: Easy Conversions? (e.g. Millimeters to Inches)
Ok, thanks! You were so helpful! :)