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 :)
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
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
http://i.imgur.com/UOaZV.png
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. :)
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?
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.
Re: Unit Converter Application [Help]
Quote:
Originally Posted by
SpaceLlama
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:
Private Sub TextBox1_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox1.TextChanged
TextBox2.Text = Val(TextBox1.Text) * 2
End Sub
Private Sub TextBox2_TextChanged(sender As System.Object, e As System.EventArgs) Handles TextBox2.TextChanged
TextBox1.Text = Val(TextBox2.Text) / 2
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).
Re: Unit Converter Application [Help]
I'm trying this out with a timer, might post back later if I'm successful :)