1.9 - Adding Code

1... Double click on the button at the center of your form.

2... Your screen will now change from the Designer View to the Code View

3... Since you double clicked on the button, you will now write the code for the double click event.

4... In the code view, add the following code:

5... The First two lines of code Dim kilogarms as Double and Dim pounds As Double are used to declare variables.
They have declared a variable called kilograms as type Double and a variable called pounds as type Double as well.

6... The line kilogarms = txtKg.Text means that whatever is entered into the txtKg textbox will be put into the variable called kilograms.

7... The line pounds = kilograms * 2.2 means that whatever is in the variable kilograms will be multiplied by 2.2 and then stored into pounds.

8... The line txtPound.Text = pounds means that whatever is stored in pounds will now be displayed in the txtPound textbox.

9... Now that you know a little about the code, let's build the program and run it.

10... Select Build... and then BuildWeightConverterTutorial1

11... To run the program, click on Debug... and then Start Debugging.

12... Your program should run as it is intended. Try entering some values in for the weight in kilograms, and then click the CONVERT button. If the program doesn't run as it should, check your code and make sure it resembles the code above. Call you teacher if necessary.

13... Close the running program and be sure to Save All.