PDA

View Full Version : [Tutorial] Writing a Converter in Visual Basic


xilica
05-22-2002, 09:53 AM
Hey everyone,

In this tutorial I will guide you through the process of successfully writing a converter in Visual Basic. Here is an example of what would could convert in Visual Basic:


Temperature: Celsuis -->Fahrenheit
Weight: Pounds-->Kilogram



Just to name a few. In this exercise we are going to write a Celsuis-->Fahrenheit converter.

When you open Visual Basic on the New Project Form click Standard EXE.

When the Form loads, locate the Properties Window on the right side of Visual Basic.

Click in it and change these values to the Form:

1. Caption: Temperature Converter
2. Height: 5000
3. Width: 7000

Now that you are done changing the Form's properties locate the toolbar on the left side of Visual Basic.

Click on the Label Button. The label button has a big "A" on it. Once you click on it drag it anywhere you want on the form.

Making sure you have the Label Button selected, click in the properties window. Change these values to the Label:

1. Caption: Celsius
2. Height: 495
3. Width: 2775
4. Top: 290
5. Left: 720


We have just positioned and labeled the Label Button. Congrats.


Now drag another Label Button anywhere you want onto the Form and click in the properties window. Change these properties:

1. Caption: Fahrenheit
2. Height: 495
3. Width: 2775
4. Top: 2160
5. Left: 720


Now locate the toolbar. Click on the text box and drag a text box anywhere on the form. Change its properties to these:

1. Text: Celsuis
2. Height: 615
3. Width: 2535
4. Top: 960
5. Left: 4200

Now drag another text box onto the form anywhere. Change its properties to these:

1. Text: Fahrenheit
2. Height: 615
3. Width: 2535
4. Top: 2160
5. Left: 4200

Now that you are done adding the two Labels and Text Boxes you are ready to add the final tool, the Command Button.

Click and drag a Command Button anywhere on the form. Change the properties to these values:

1. Caption: Calculate
2. Font: Bold 18
3. Height: 1095
4. Width: 3975
5. Top: 3240
6. Left: 1560


Congratulations, we have just completed the interface.

Adding the Code:


Private Sub Command1_Click()

If (Text1.Text = True) Then
Text2.Text = (Text1.Text * 9 / 5) + 32
Else
Text1.Text = (Text2.Text - 32) * 5 / 9
End If

End Sub


Analying the Code:

We used an " If Else" statement right here to describe if Text1 is true. If Text1 is true, then it calculates that value into Text2 and vis-versa. It only calculates if you hit the Calculate Button.

Congratulations you just finished this tutorial.

Please feel free to posts any comments regarding this tutorial.

xilica
05-22-2002, 04:32 PM
Here is an image of the interface:

http://www.tmstadium.com/extrastuff/VisualBasicConverter.jpg

mrbojangle
05-23-2002, 01:07 AM
AWSOME dude, thats a good job :)

xilica
05-23-2002, 07:46 AM
Thank You, I am currently writing more tutorials. I'm glad someone appreciate my dedicated work here. :)