Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Creating a Temperature converter using VB.net.

Author: DevASP
Download Source Code : 587_TemperatureConvertor.zip

This article is about how you can create a temperature converter which can convert the temperature into any given unit.

 

 

Steps you will do.

 

Start visual studio and create a new window application.

 

 

Set the following properties of the form

 

Name = Form1

Font = Microsoft Sans Serif, 8.25pt

FontBorderStyle = FixedToolWindow

Text = Temperature Convertor

 

Now drop a label control on the form and set its text property as below.

 

Text = What Unit Do You Want To Convert ?

 

Now place a group box control on the form and place three radio buttons in this group box control and set their properties as below.

 

First radio button control

 

Name = c

Font = Microsoft Sans Serif, 8.25pt

Text = Celsius

 

 

Second radio button control

 

Name = f

Font = Microsoft Sans Serif, 8.25pt

Text = Ferinhieght

 

  

Third radio button control

 

Name = t

Font = Microsoft Sans Serif, 8.25pt

Text = Kelvin (T)

 

 

Place another label control on the form and set its following properties as below.

 

Text = Please Enter The Temperature :

Font = Arial, 9pt, style=Bold

 

Now place a text box control to enter the temperature and set its following properties.

 

Name = txt

Text = “”

 

Place a button control on the form and set its following properties.

 

Name = cmd

Font  = Arial, 8.25pt, style=Bold

Text = &Convert

 

Now place another group box control on the form and set its text property as below.

 

Text = Result

 

 

With in this group box control place a label control and set its following properties.

 

Text = Celsius :               Ferinhieght :           Kelvin :

TextAlign = BottomLeft

Font = Microsoft Sans Serif, 8.25pt

 

Now place three more label controls within this group box control and set their following properties.

 

First label control

 

Name = lblc

Font = Arial, 9.75pt, style=Bold

ForeColor = Arial, 9.75pt, style=Bold

Text = C

TextAlign = MiddleCenter

 

 

 

Second label control

 

Name = lblf

Font = Arial, 9.75pt, style=Bold

ForeColor = Arial, 9.75pt, style=Bold

Text = F

TextAlign = MiddleCenter

 

 

Third label control

 

Name = lblt

Font = Arial, 9.75pt, style=Bold

ForeColor = Arial, 9.75pt, style=Bold

Text = K or T

TextAlign = MiddleCenter

 

 

 

Open the code window of your form and write the following code in the closing event of the form.

 

If MsgBox("Are You Sure?", MsgBoxStyle.Information Or

MsgBoxStyle.OKCancel) = MsgBoxResult.OK Then

     

      e.Cancel = False

Else

     e.Cancel = True

End If

 

 

 

Now write the following code in the CheckChange event of c, f, t and r.

 

cmd.Enabled = True

 

 

Write the following code in the click event of cmd.

 

Dim box As Double

        Dim sum As Double

        Dim sum2 As Double

        Dim sum3 As Double

        box = Convert.ToDouble(txt.Text)

 

        If c.Checked = True Then

            lblc.Text = box

            sum = (box * 9) / 5 + 32

            lblf.Text = sum

            sum2 = box + 273.15

            lblt.Text = sum2

        End If

        If f.Checked = True Then

            lblf.Text = box

            sum = (box - 32) * 5 / 9

            lblc.Text = sum

            sum2 = sum + 273.15

            lblt.Text = sum2

        End If

        If t.Checked = True Then

            lblt.Text = box

            sum = box - 273.15

            lblc.Text = sum

            sum2 = (sum * 9) / 5 + 32

            lblf.Text = sum2

        End If

         

Run your application, enter the temperature and finally click the button and see the results.

 

 

Article Comments
Hey there!

Dude, "e.Cancel = ** " doesn't work.
(where ** =true or false)
And what is "r"?

Posted on 2/23/2007 4:54:22 PM by Rochus

Dude!

I forgot to tell you, " dim Box as Double"? Whick box? Results or enter temperature box?

Posted on 2/23/2007 4:56:12 PM by Rochus

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to convert image to other extension and reduce its size in .NET 2.0.

Disclaimer - Privacy
© 2002-2017 DevASP.net