Scotland, UK // ENG · GARAGE · PLC

A straightforward Visual Basic Windows Forms program that asks the user for a temperature in Celsius, converts it to Fahrenheit using F = C * 1.8 + 32, logs both values into list boxes, and displays the converted result in a message box.

Full Visual Basic Code

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim celsius As Single     ' creates the celsius variable
        Dim fahrenheit As Single  ' creates the fahrenheit variable

        celsius = InputBox("What's the temperature in Celsius?") ' asks for the degrees in celsius
        fahrenheit = celsius * 1.8 + 32 ' mathematical equation for celsius to fahrenheit

        ListBox1.Items.Add(celsius)     ' adds the degrees in celsius to your first listbox
        ListBox2.Items.Add(fahrenheit)  ' adds the degrees in fahrenheit to your second listbox
        MsgBox("The temperature converted to fahrenheit is " & fahrenheit) ' displays the result
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        End ' emergency end program button
    End Sub
End Class

Step-by-Step Guide

  1. Open Visual Studio and create a new Visual Basic Windows Forms Application.
  2. Drag and drop two Label controls onto the form and name them Celsius and Fahrenheit.
  3. Drag and drop two ListBox (or display) controls onto the form to display both temperature columns.
  4. Drag and drop two Button controls onto the form and label them Start and End.
  5. Double-click both the Start button and the End button to open their click event handlers in the Code Editor.
  6. Add the code below into each handler (the lines to add are marked in red in the screenshots).

"End" Button Code

Visual Studio code editor highlighting the End statement inside Button2_Click
"End" button handler — add a single End statement inside Button2_Click.

Below the Start button's handler, you'll see the Button2_Click block shown above. Add End inside it (without parentheses) — that's all you need for the End button to close the program.

"Start" Button Code

Visual Studio code editor highlighting Celsius to Fahrenheit conversion code inside Button1_Click
"Start" button handler — variable declarations, InputBox prompt, conversion formula, and output.

Inside Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click, declare the celsius and fahrenheit variables, read the Celsius input, calculate celsius * 1.8 + 32, and output the values to both list boxes and the MsgBox.