Wednesday, January 16, 2013

Contoh Penggunaan IF Pada Visual Studio 2008


Setting Properties


source code :



Public Class Form1

    Private Sub angka_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles angka.KeyPress
        If Asc(e.KeyChar) = 13 Then
            If Val(angka.Text) >= 60 Then
                keterangan.Text = "Lulus"
            Else
                keterangan.Text = "Gagal"
            End If
            If angka.Text > 100 Then
                huruf.Text = "Nilai Salah"
                keterangan.Text = "Nilai Salah"
            ElseIf angka.Text >= 80 Then
                huruf.Text = "A"
            ElseIf angka.Text >= 75 Then
                huruf.Text = "B+"
            ElseIf angka.Text >= 70 Then
                huruf.Text = "B"
            ElseIf angka.Text >= 65 Then
                huruf.Text = "C+"
            ElseIf angka.Text >= 60 Then
                huruf.Text = "C"
            ElseIf angka.Text >= 50 Then
                huruf.Text = "D"
            Else
                huruf.Text = "E"
            End If
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Val(angka.Text) >= 60 Then
            keterangan.Text = "Lulus"
        Else
            keterangan.Text = "Gagal"
        End If

        If angka.Text > 100 Then
            huruf.Text = "Nilai Salah"
            keterangan.Text = "Nilai Salah"
        ElseIf angka.Text >= 80 Then
            huruf.Text = "A"
        ElseIf angka.Text >= 75 Then
            huruf.Text = "B+"
        ElseIf angka.Text >= 70 Then
            huruf.Text = "B"
        ElseIf angka.Text >= 65 Then
            huruf.Text = "C+"
        ElseIf angka.Text >= 60 Then
            huruf.Text = "C"
        ElseIf angka.Text >= 50 Then
            huruf.Text = "D"
        Else
            huruf.Text = "E"
        End If

    End Sub
End Class


No comments:

Post a Comment