Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 795969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T22:33:57+00:00 2026-05-14T22:33:57+00:00

I have this as my conversion program for the Length, how can I do

  • 0

I have this as my conversion program for the “Length”, how can I do it the simpliest way instead of keeping the if, elseif, else too much, i do not have much experience and trying to improve my programming skills on visual studio 2008.

Basically, I get annoyed with the formulas because I don’t know if it is right, I use google but doesn’t help because i don’t know how to get it right when the program converts from type to type.

Public Class Form2
    Dim Metres As Integer
    Dim Centimetres As Integer
    Dim Inches As Integer
    Dim Feet As Integer
    Dim Total As Integer

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ErrorMsg.Hide()
    End Sub

    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click

        Metres = 1
        Centimetres = 0.01
        Inches = 0.0254
        Feet = 0.3048

        txtTo.Text = 0

        If txtFrom.Text <> "" Then
            If IsNumeric(txtFrom.Text) And IsNumeric(txtTo.Text) Then

                If cbFrom.Text = "Metres" And cbTo.Text = "Centimetres" Then
                    Total = txtFrom.Text * Metres
                    txtTo.Text = Total
                ElseIf cbFrom.Text = "Metres" And cbTo.Text = "Inches" Then
                    Total = txtFrom.Text * 100
                    txtTo.Text = Total
                ElseIf cbFrom.Text = "Metres" And cbTo.Text = "Feet" Then

                ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Metres" Then

                ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Inches" Then

                ElseIf cbFrom.Text = "Centimetres" And cbTo.Text = "Feet" Then

                ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Metres" Then

                ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Centimetres" Then

                ElseIf cbFrom.Text = "Inches" And cbTo.Text = "Feet" Then

                ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Metres" Then

                ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Centimetres" Then

                ElseIf cbFrom.Text = "Feet" And cbTo.Text = "Inches" Then

                End If

            End If
        End If
    End Sub
End Class

This is the source for what I have done at the moment.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T22:33:58+00:00Added an answer on May 14, 2026 at 10:33 pm

    One basic approach would be to split the handling of the “from”- and the “to”-conversion by using an intermediate format.

    So the program code would be similar to something like this:

    Dim intermediate as Double //Intermediate format in centimeters
    Dim result as Double
    Dim inputValue as Double = cDbl(txtFrom.Text)
    
    If cbFrom.Text = "Metres" Then
       intermediate = inputValue  * 100
    else if cbFrom.Text = "Centimetres" Then
       intermediate = inputValue  
    else if 
       ...
    End If
    
    If cbTo.Text = "Metres" Then
      result = intermediate / 100
    else if cbTo.Text = "Centimetres" Then
      result = intermediate
    End If 
    
    txtTo.Text = Math.Round(result, 2) //Round optional :)
    

    Using this approach you only have to worry about conversion to and from your intermediate format and you only have to handle each input and output format once (instead of writing custom conversions for each input/output pair).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 463k
  • Answers 463k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Scrapy is much more complicated. It runs several processes and… May 16, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer You should have a corresponding @interface NSMutableArray (StackUtil) in a… May 16, 2026 at 12:45 am
  • Editorial Team
    Editorial Team added an answer I can't reproduce exactly what you describe, but I have… May 16, 2026 at 12:45 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.