Results 1 to 8 of 8

Thread: Unit Converter Application [Help]

  1. #1
    New Member
    Join Date
    Sep 12
    Posts
    6

    Unit Converter Application [Help]

    Hello forum,

    I am posting here in regard to a problem I am having with a converter application that I am developing.

    My issue is that I can't find a way to code my input and output textboxes of the program, so that regardless of which textbox the user enters a value into, the program will still apply preset arithmetic, and display an equivalent measurement of unit in the alternate textbox.

    Feel free to ask for any clarification :)

  2. #2
    Hyperactive Member marniel647's Avatar
    Join Date
    Aug 10
    Location
    MSDN Library
    Posts
    256

    Re: Unit Converter Application [Help]

    what problem do you have in your program.? You cannot Display in Textbox? Your Calculations is wrong? Can you elaborate more also can you include your code. So we can check for the errors. Thanks

  3. #3
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: Unit Converter Application [Help]

    I'm trying to make the program more user friendly; giving them the option of typing in the output text box, and still being able to convert properly to the input text box.
    Keep in mind, the program is still in development
    My current code is as follows:
    See Screenshot for code disambiguation...
    Code:
            Private Sub txtAreaInput_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAreaInput.TextChanged
            If cboAreaInputUnit.Text.Contains("Millimetre") = True Then
                If cboAreaOutputUnit.Text.Contains("Millimetre") = True Then
                    txtAreaOutput.Text = txtAreaInput.Text
                End If
                If cboAreaOutputUnit.Text.Contains("Centimetre") = True Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) * 0.1
                End If
                If cboAreaOutputUnit.Text.Contains("Metre") = True Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) * 0.001
                End If
                If cboAreaOutputUnit.Text.Contains("Kilometre") = True Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) * 0.000001
                End If
                If cboAreaOutputUnit.Text = "Hectare" Then
                    txtAreaOutput.Text = txtAreaInput.Text * 0.001
                End If
                If cboAreaOutputUnit.Text = "Perch" Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) / 25290
                End If
                If cboAreaOutputUnit.Text = "Rood" Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) / 1011600
                End If
                If cboAreaOutputUnit.Text = "Acre" Then
                    txtAreaOutput.Text = Val(txtAreaInput.Text) / 4046400
                End If
            End If
        End Sub

  4. #4
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: Unit Converter Application [Help]

    Since my posts don't seem to be appearing, I'm not sure how to reply... I'll check back tomorrow. Thanks for your help thus far.

  5. #5
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Unit Converter Application [Help]

    How does the user indicate that they have completed the input? What happens if they have left previous input so that there is text in both boxes? Is there only one conversion option (cubits to yards or whatever) or many different possibilities?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  6. #6
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: Unit Converter Application [Help]

    The use does not need to indicate that they have completed the input. I have coded the text box event: text input/change so that when a numeric value is entered, my preset arithmetic is applied.

  7. #7
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 12
    Posts
    5,501

    Re: Unit Converter Application [Help]

    Quote Originally Posted by SpaceLlama View Post
    The use does not need to indicate that they have completed the input. I have coded the text box event: text input/change so that when a numeric value is entered, my preset arithmetic is applied.
    Then you've made it tricky. In theory you could use the text changed event of both boxes with the inverse arithmetic then you can use either box to input. eg.

    vb.net Code:
    1. Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
    2.         TextBox2.Text = Val(TextBox1.Text) * 2
    3.     End Sub
    4.  
    5.     Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
    6.         TextBox1.Text = Val(TextBox2.Text) / 2
    7.     End Sub

    The problem with that is that there will be calculations where the inverse will not result in exactly equal values. 1/3 for example will loop around to give the entirely accurate 0.3333333 in one box and 0.9999999 in the other but will abort making it impossible to add a second digit.

    For all kinds of reasons you are better to have one input and one output but if you want to use a two-way system you do need to have a submit method which positively indicates that a calculation is requested (or a very complex sieve which makes imbalances in the inverse calculations impossible).
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  8. #8
    New Member
    Join Date
    Sep 12
    Posts
    6

    Re: Unit Converter Application [Help]

    I'm trying this out with a timer, might post back later if I'm successful

Posting Permissions

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