Introduction: Length Converter

Picture of Length Converter
Hi. This tutorial will teach you how to make a length converter in Visual Basic. A length converter is a tool that can be used to turn Miles into Kilometres or Metres into Kilometres. This application uses Arithmetic Operators which are equations such as division and multiplication. I recommend this tutorial to people who are familiar with Visual Basic. If you are new to Visual Basic you can still try this.

This you need:
  • Computer.
  • Microsoft Visual Basic.
  • Basic knowledge of Visual Basic.

Step 1: Creating the Project

Picture of Creating the Project
Step 1: Open Microsoft Visual Basic.

Step 2: Create New Project by clicking on New Project or press Ctrl+N.

Step 3: Pick Windows Form Application and name it "Length Converter".

Step 4: Rename Form1.vb to "Length.vb". This is for Easy use.

Step 5: Rename Form1 to "LengthForm" and make the Text "Length Converter". This is for Easy use.

Step 6: Resize it to your liking. I have made my one '500, 300'.

Step 7: Insert a Label at the top of the Form and make the name "Title" and make the text "LengthConverter"

Step 8: Insert two Buttons. One in the centre. Name it "ConvertButton" and make text "Convert". The second button is optional. Place it at the top right hand conner and name it "ExitButton" and make text "Exit"

Step 9: Insert two ComboBoxes, Place one on the left and the other on the right. Name the one on the left "LengthList1" and the one on the right "LengthList2". Make the text on both of them "SelectUnit"

Step 10: Insert two TextBoxes and place them underneath the ComboBoxes. Name them "UnitText1" and "UnitText2". Leave the Text blank.

Step 2: Getting the Basic Code

Picture of Getting the Basic Code
Step 11: Double click on the 'ExitButton'. This will make a new Private Sub which will activate when the button is clicked.

Step 12: Insert the following code:
'This will close the application'
Me.Close()
Step 13: Double click the 'ConvertButton'. This will make new Private Sub which will activate when the button is clicked.

Step 14: Insert the following code:
'These are the Boolean for the Length in the first box'
Dim Mile1 As Boolean
Dim KM1 As Boolean
Dim M1 As Boolean
Dim CM1 As Boolean

'These are the Boolean for the length in the second box'
Dim Mile2 As Boolean
Dim KM2 As Boolean
Dim M2 As Boolean
Dim CM2 As Boolean

'These are the inserted numbers that will be converted'
Dim Num1 As String
Num1 = UnitText1.Text
Dim Num1 As String
Num2 = UnitText2.Text

Step 3: Converting the Units

Picture of Converting the Units
Step 15: Insert the following underneath the previous code:
'What it is converting'
If LengthList1.Text = ("Mile") And LengthList2.Text = ("Kilometre") Then
	Mile1 = True
	KM2 = True
End If
'The equation for the conversion'
If Mile1 = True and KM2 = True Then
	UnitText2.Text = Num1 / 0.62137
End If

If LengthList1.Text = ("Mile") And LengthList2.Text = ("Metre") Then Mile1 = True M2 = True End If If Mile1 = True and M2 = True Then UnitText2.Text = Num1 / 0.0062137 End If If LengthList1.Text = ("Mile") And LengthList2.Text = ("Centimetre") Then
Mile1 = True CM2 = True End If If Mile1 = True and CM2 = True Then UnitText2.Text = Num1 / 0.0000062137 End If If LengthList1.Text = ("Kilometre") And LengthList2.Text = ("Mile") Then
KM1 = True Mile2 = True End If If KM1 = True and Mile2 = True Then UnitText2.Text = Num1 * 0.62137 End If If LengthList1.Text = ("Kilometre") And LengthList2.Text = ("Metre") Then
KM1 = True M2 = True End If If KM1 = True and M2 = True Then UnitText2.Text = Num1 / 0.001 End If If LengthList1.Text = ("Kilometre") And LengthList2.Text = ("Centimetre") Then
KM1 = True CM2 = True End If If KM1 = True and CM2 = True Then UnitText2.Text = Num1 / 0.000001 End If If LengthList1.Text = ("Metre") And LengthList2.Text = ("Mile") Then
M1 = True Mile2 = True End If If M1 = True and Mile2 = True Then UnitText2.Text = Num1 * 0.000621317 End If If LengthList1.Text = ("Metre") And LengthList2.Text = ("Kilometre") Then
M1 = True KM2 = True End If If M1 = True and KM2 = True Then UnitText2.Text = Num1 / 1000 End If If LengthList1.Text = ("Metre") And LengthList2.Text = ("Centimetre") Then
M1 = True CM2 = True End If If M1 = True and CM2 = True Then UnitText2.Text = Num1 / 0.01 End If If LengthList1.Text = ("Centimetre") And LengthList2.Text = ("Mile") Then
CM1 = True Mile2 = True End If If CM1 = True and Mile2 = True Then UnitText2.Text = Num1 * 0.000000621317 End If If LengthList1.Text = ("Centimetre") And LengthList2.Text = ("Kilometre") Then
CM1 = True KM2 = True End If If CM1 = True and KM2 = True Then UnitText2.Text = Num1 * 0.00001 End If If LengthList1.Text = ("Centimetre") And LengthList2.Text = ("Metre") Then
CM1 = True M2 = True End If If CM1 = True and M2 = True Then UnitText2.Text = Num1 * 0.01 End If 'If converting into same unit then the valve will be the same' If LengthList1.Text = LengthList2.Text Then UnitText2.Text = Num1 End If

Comments

tobster911 (author)2014-11-20

It does work fine, problem being that in the instructable, it neglects to mention that you need to enter values for the string in the drop down box. To do this, simply click onto your design, select the drop down box, and in the properties window, click 'Edit Items'. In the box that appears, enter this:
Kilometre

Metre

Mile

Centimetre

Do this for both (note that my spelling may be slightly different to yours, so double check.

Also check that all the names of items and variables are exactly as they appear. Check this is correct. If not, place a screenshot up here of the errors you are receiving, and where the errors take place in the code, and I'll check it out for you.

Hope I have helped

amirul5399 (author)tobster9112016-05-28

thanks its working fine.

btw, im using windows visual studio community edition 2015

VB learner (author)tobster9112015-03-14

It did not work, but there are no errors in the list.

am using vb 2013

waldas.waitiekus (author)2014-10-09

It doesn't work :( (Please fix it)

About This Instructable

12,876views

5favorites

License:

More by Ashcraft11:How to Make a Calendar in PhotoshopBasics of PhotoshopLength Converter
Add instructable to: