GuidesFitness Gear & Equipment

Visual Basic Sample Programs : Celsius to Fahrenheit, Area of a Circle

Knoji reviews products and up-and-coming brands we think you'll love. In certain cases, we may receive a commission from brands mentioned in our guides. Learn more.
Visual Basic sample programs that converts Celsius to Fahrenheit and Area of a circle.

Alan Cooper, the Father of Visual Basic said:

“When people ask me what is the best way to learn programming or how to use a specific language, I tell them to experiment – write as many small programs as you can, as each one will teach you more – and each one will add another trick to your tool bag.”

So take your time following the examples below, and soon you’ll develop skills by heart as you travel more into the world of programming.

Celsius to Fahrenheit

Follow the steps below in designing and developing the system of converting the input value of Celsius into its equivalent Fahrenheit degree using the formula: F = (9/5) * C + 32.

Solution:

1. At the Start of the Taskbar and Programs submenu select Visual Basic under the Microsoft visual Studio

2. Start a new project and select the Standard EXE on the given displayed items, then click the Open command button. Set the caption of the form to Degree1.

3. Double-click the two text boxes in the Toolbox to add them into the Form. Position them properly and adjust their width appropriately. Now double-click two Labels in the Toolbox and write the caption “Enter the Celsius:” and “The Fahrenheit is:” in front of its respective text boxes. Click a command button in the toolbox to add it into the Form, then set its caption to Compute.

4. Double-click now the form to display the Code editor. Embed the following code to its respective procedures:

Private txtCelsius As Integer

Private txtFahrenheit As Double

Private Sub Command_Click ( )

txtFahrenheit = (9 / 5) * (txtCelsius + 32)

Text2.Text = Str (txtFahrenheit)

End Sub

Private Sub Form_Load ( )

txtCelsius = 0

txtFahrenheit = 0

Text1.Text = nNum1

Text2.Text = nNum2

End Sub

Private Sub Text1_Change ( )

txtCelsius = Val (Text1.Text)

End Sub

5. Run the application system selecting the Run menu at the menu bar and click the Start item (or click its equivalent icon at the tool bar.)

Now try to enter any value at the text box of the Celsius. Then click the Compute button to see the result.

Area of a Circle

Design and develop a simple application system that computes the area of a circle. Use the formula: =πr^2 , where Pi (π) is approximately equivalent to 3.1416. Follow the given figure below in designing and developing the application system.

Note:

When the user enters the value of the radius in text box, the user should click the Command button (with a Compute caption) before the resulting computed value will be displayed at text box 2.

Solution:

1. Select the Visual Basic under the Microsoft Visual Studio at the Start of the Taskbar and programs submenu of the operating system.
2. Start a new project and select the Standard EXE on the given displayed items, then click the Open command button. Set the caption of the form to Area1.
3. Double-click the two text boxes in the Toolbox to add them into the form. Position them properly and adjust their width appropriately. Now double-click two Labels in the Toolbox and write the caption “enter the radius:” and “Area of a circle is:” in-front of its respective text boxes. Finally , click a command button in the Toolbox to add it into the Form, then set its caption to Compute.
4. Double-click now the form to display the code editor. Embed the following code to its respective procedures:

Private txtRadius As Integer

Private txtArea As double

Const conPi = 3.1416

Private Sub Command1_Click ( )

txtArea = conPi * txtRadius * txtRadius

Text2.Text = Str (txtArea)

End sub

Private sub Form_Load ( )

txtRadius = 0

txtArea = 0

Text1.Text = nNum1

Text2.Text = nNum2

End sub

Private Sub Text1_Change ( )

txtRadius = Val (Text1.Text)

End sub

5.  Run the application system by selecting the Run menu at the menu bar and click the Start item or itsequivalent  icon at the tool bar).

Now try to enter any value at the text box of the radius. Then click the Compute button to see the result.

Reference: Introduction to Visual Basic 6 Programming by Copernicus P. Pepito, Philippine Copyright 2005, National Bookstore

2 comments

Bruce Bostwick
0
Posted on Feb 21, 2012
Abdel-moniem El-Shorbagy
0
Posted on Apr 30, 2011

About This Article

Nida Cabauatan Abarca

Explore Top Fitness Gear & Equipment Brands

Expand more
Top-ranked fitness gear & equipment brands