Public Class Form1
    ' Exam Number 3534535345
    Dim celcius As Boolean
    Private Sub btnCtoF_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCtoF.Click
        ' Users choice of which conversion to be done
        GroupBox1.Enabled = True
        celcius = True
    End Sub

    Private Sub btnFtoC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFtoC.Click
        ' Users choice of which conversion to be done
        GroupBox2.Enabled = True
        celcius = False
    End Sub

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim answer As String

        'Check the input for < 200 or > 200
        If Val(txtCelcius.Text) < -200 Or Val(txtCelcius.Text) > 200 Then
            txtCelcius.Clear()
            txtCelcius.Focus()
            Exit Sub
        End If
        If Val(txtFahrenheit.Text) < -200 Or Val(txtFahrenheit.Text) > 200 Then
            txtFahrenheit.Clear()
            txtFahrenheit.Focus()
            Exit Sub
        End If

        'Check which conversion is asked for
        If celcius Then
            answer = CelTOFaHr(CInt(txtCelcius.Text))
            lblAnswer.Text = txtCelcius.Text & " deg C = " & answer & " deg Far"
        Else
            answer = FahrToCel(CInt(txtFahrenheit.Text))
            lblAnswer.Text = txtFahrenheit.Text & " deg Far = " & answer & " deg C"
        End If

    End Sub

    Function CelTOFaHr(ByVal Celcius As Integer) As Single
        'Function for Celcius to Fahrenheit
        Dim Fahrenheit As Single
        Fahrenheit = (9 / 5) * Celcius + 32
        Return Fahrenheit
    End Function

    Function FahrToCel(ByVal Fahr As Integer) As Single
        'Function for Fahrenheit to Celcius
        Dim Celcius As Single
        Celcius = (Fahr - 32) * (5 / 9)
        Return Celcius
    End Function

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ' Clear all textbox and label, disable groupbox
        lblAnswer.Text = ""
        txtCelcius.Clear()
        txtFahrenheit.Clear()
        GroupBox1.Enabled = False
        GroupBox2.Enabled = False
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        ' Close the program
        Me.Close()
    End Sub
End Class
