Temperature Convertor - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

This tutorial will show you how to make a temperature converter in visual basic .net.

The program will convert the temperature from Fahrenheit to Celsius and vise versa.

Start a new project.

Add a MaskedTextBox to the form

Change the MaskedTextBox mask proerty to Numeric (5-digits). To do that, click on the MaskedTextBox and then click on the little arrow that appears on the right top side of the MaskedTextBox. Then click on set mask

A window will appear:

5 digits should be enough when it comes to temperature conversing.

Add 2 RadioButtons:

Change the text property of the RadioButtons:

Right click on the RadioButton1 and click on properties. On the properties window, change the text to "F to C". That is abbreviation for Fahrenheit to Celsius.

Change RadioButton2's text to "C to F"

Add a button to the form:

Change the text of the button to Convert:

Add a label and place it below the button:

Erase the text of Label1. Click on Label1 and go to the properties window:

Double click on the button that says "Convert" and add the following highlighted code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If RadioButton1.Checked = True Then
            Label1.Text = MaskedTextBox1.Text & " Fahrenheit = " & (MaskedTextBox1.Text - 32) / 1.8 & " Celsius"
        ElseIf RadioButton2.Checked = True Then
            Label1.Text = MaskedTextBox1.Text & " Celsius = " & (MaskedTextBox1.Text * 1.8) + 32 & " Fahrenheit"
        End If
    End Sub

Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.