Results 1 to 5 of 5

Thread: [RESOLVED] Easy Conversions? (e.g. Millimeters to Inches)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    13

    Resolved [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...)
    Last edited by winallsys; May 17th, 2009 at 05:03 PM. Reason: another question

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

    (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.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    13

    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.
    Last edited by winallsys; May 17th, 2009 at 05:47 PM. Reason: another question

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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).

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2009
    Posts
    13

    Re: Easy Conversions? (e.g. Millimeters to Inches)

    Ok, thanks! You were so helpful!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width