Visual Basic Tutorial: Currency Converter

Full Code Currency Converter Example 1

Public Class Form1

    Dim currency As Double

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Label1.Text = currency * Convert.ToDouble(TextBox1.Text)

    End Sub

    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        currency = 1.29
    End Sub

    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
        currency = 95.75
    End Sub

    Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        currency = 1.42
    End Sub

    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        currency = 160.11
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        currency = 1.9
    End Sub

    Private Sub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged
        currency = 9.24
    End Sub
End Class

Full Code using IF in Currency Converter statement example 2

Public Class Form1

    Dim currency As Double

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


        If (RadioButton1.Checked = True) Then
            currency = 1.29
        End If
        If (RadioButton2.Checked = True) Then
            currency = 160.11
        End If
        If (RadioButton3.Checked = True) Then
            currency = 95.75
        End If
        If (RadioButton4.Checked = True) Then
            currency = 1.42
        End If
        If (RadioButton5.Checked = True) Then
            currency = 1.9
        End If
        If (RadioButton6.Checked = True) Then
            currency = 9.24
        End If


        Label1.Text = currency * Convert.ToDouble(TextBox1.Text)

    End Sub

End Class



Comments are closed.