Selasa, 05 April 2016

Peretemuan 4

Latihan 1

1. Buat Projek dan form baru
2. buat Interface seperti ini


3. Masukan koding dibawah ini

Public Class Form1
    Private Sub btn_tampil_Click(sender As Object, e As EventArgs) Handles btn_tampil.Click
        Dim decsalary As Decimal
        Try
            decsalary = CDec(txt_isi.Text)
            lbl_hasil.Text = "your salary is " & decsalary.ToString("c")
        Catch
            lbl_hasil.Text = "please try agan. enter number invalid"
        End Try
    End Sub
End Class


Latihan 2

1. Buat Form Baru
2. buat interface seperti dibawah ini

3. Masukan Koding dibawah ini

Public Class Form2
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim salary As Decimal
        Dim pay As Integer
        Dim decsalary As Decimal
        Try
            'deklarasi untuk salary dan pay terhadap text box
            salary = CDec(txt_salary.Text)
            pay = CInt(txt_pay.Text)

            'hitungan
            decsalary = salary / pay

            lbl_hasil.Text = decsalary.ToString("c")
        Catch
            lbl_status.Text = "Eroor = Be sure enter is no zero " & "numeric values"
        End Try
    End Sub
End Class

Latihan 3

1. Buat form baru
2. Buat Interface dibawah ini
3. Masukan Koding dibawah ini
Public Class Form3
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim salary As Decimal
        Dim pay As Integer
        Dim decsalary As Decimal

        Try
            salary = CDec(txt_salary.Text) 'txt_salary dijadikan desimal dan di deklarasi dari deklarasi salary yang diatas agar nanti bisa dibagi
            Try
                pay = CInt(txt_pay.Text) ' txt_pay dijadikan interger dan dideklarasikan dari pay yang diatas agar nanti bisa dibagi
                Try
                    decsalary = salary / pay ' hitungan

                    lbl_hasil.Text = decsalary.ToString("c") 'hasil decsalary dijadikan string

                Catch
                    lbl_status.Text = "pay periods cannot be zero " ' eroro untuk pay periods
                End Try
            Catch
                    lbl_status.Text = " pay perids must be integer" ' eror message untuk tex box pay periods
                End Try

            Catch
                lbl_status.Text = "enter a numeric value for salary" ' eror untuk text box salary
            End Try

        End Sub
End Class

Latihan 4
Public Class Form3
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim salary As Decimal
        Dim pay As Integer
        Dim decsalary As Decimal

        Try
            salary = CDec(txt_salary.Text) 'txt_salary dijadikan desimal dan di deklarasi dari deklarasi salary yang diatas agar nanti bisa dibagi
            Try
                pay = CInt(txt_pay.Text) ' txt_pay dijadikan interger dan dideklarasikan dari pay yang diatas agar nanti bisa dibagi
                Try
                    decsalary = salary / pay ' hitungan

                    lbl_hasil.Text = decsalary.ToString("c") 'hasil decsalary dijadikan string

                Catch
                    lbl_status.Text = "pay periods cannot be zero " ' eroro untuk pay periods
                End Try
            Catch
                    lbl_status.Text = " pay perids must be integer" ' eror message untuk tex box pay periods
                End Try

            Catch
                lbl_status.Text = "enter a numeric value for salary" ' eror untuk text box salary
            End Try

        End Sub
End Class

Latihan 4

1. Buat Form baru
2. Buat interface seperti dibawah ini
3. Masukan Koding dibawah ini

Public Class Form4
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim salary As Decimal
        Dim pay As Integer
        Dim decsalary As Decimal

        Try
            salary = CDec(txt_salary.Text)
            pay = CInt(txt_pay.Text)

            decsalary = salary / pay ' hitungan

            lbl_hasil.Text = decsalary.ToString("c") ' tampil hasil dan di konversi ke string

        Catch ex As InvalidCastException ' Perintah ini akan dijalankan apabila yang kita masukan bukan angka
            lbl_status.Text = " Eroor : Input must be Numeric"

        Catch ex As DivideByZeroException ' Perintah akan dijalankan apabila yang dimasukan adalah nol pada txt_pay
            lbl_status.Text = "Erorr : Enter Non zero values"
        End Try
    End Sub
End Class


Latihan 5


Pertemuan 5

1. Buat Projek baru
2. buat tampilan seperti dibawah ini

3. masukan koding dibawah ini

Public Class Form1
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim skor1 As Double
        Dim skor2 As Double
        Dim skor3 As Double
        Dim rata2 As Double

        Const num_scores As Integer = 3 ' jumlah skor yang ada, dihitung menurut jumlah tex box
        Const high_scores As Integer = 95.0

        Try
            skor1 = CDbl(txt_skor1.Text)
            skor2 = CDbl(txt_skor2.Text)
            skor3 = CDbl(txt_skor3.Text)

            rata2 = (skor1 + skor2 + skor3) / num_scores

            lbl_rata.Text = rata2.ToString("n2")

            If rata2 > high_scores Then lbl_ucapan.Text = "Selamat !! Nilai anda bagus"

        Catch
            lbl_ucapan.Text = "Scores harus angka"

        Catch ex As Exception

        End Try

    End Sub

    Private Sub btn_clear_Click(sender As Object, e As EventArgs) Handles btn_clear.Click
        txt_skor1.Clear()
        txt_skor2.Clear()
        txt_skor3.Clear()
        lbl_rata.Text = ""
        lbl_ucapan.Text = ""
    End Sub

    Private Sub btn_exit_Click(sender As Object, e As EventArgs) Handles btn_exit.Click
        Me.Close()

    End Sub
End Class

latihan 2

1. Buat form baru
2. buat interface seperti dibawah ini

3. Masukan koding dibawah ini
Public Class Form2
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click

        Dim skor1 As Double
        Dim skor2 As Double
        Dim skor3 As Double
        Dim rata2 As Double

        Const num_scores As Integer = 3 ' jumlah skor yang ada, dihitung menurut jumlah tex box
        Const high_scores As Integer = 95.0


        skor1 = CDbl(txt_skor1.Text)
            skor2 = CDbl(txt_skor2.Text)
            skor3 = CDbl(txt_skor3.Text)

            rata2 = (skor1 + skor2 + skor3) / num_scores

            lbl_rata.Text = rata2.ToString("n2")

        If rata2 > high_scores Then
            lbl_ucapan.Text = "Selamat !! Nilai anda bagus"
        Else
            lbl_ucapan.Text = "Coba Lagi"
        End If



    End Sub

    Private Sub btn_clear_Click(sender As Object, e As EventArgs) Handles btn_clear.Click
        txt_skor1.Clear()
        txt_skor2.Clear()
        txt_skor3.Clear()
        lbl_rata.Text = ""
        lbl_ucapan.Text = ""
    End Sub

    Private Sub btn_exit_Click(sender As Object, e As EventArgs) Handles btn_exit.Click
        Me.Close()

    End Sub
End Class


Latihan 3
1. buat form baru
2. buat interface seperti dibawah ini


3. Masukan koding dibawah ini
Public Class Form3
    Private Sub btn_hitung_Click(sender As Object, e As EventArgs) Handles btn_hitung.Click
        Dim skor1 As Double
        Dim skor2 As Double
        Dim skor3 As Double
        Dim rata2 As Double

        Const num_scores As Integer = 3 ' jumlah skor yang ada, dihitung menurut jumlah tex box
        Const high_scores As Integer = 95.0


        skor1 = CDbl(txt_skor1.Text)
        skor2 = CDbl(txt_skor2.Text)
        skor3 = CDbl(txt_skor3.Text)

        rata2 = (skor1 + skor2 + skor3) / num_scores

        lbl_rata.Text = rata2.ToString("n2")

        If rata2 > high_scores Then
            lbl_ucapan.Text = "Selamat !! Nilai anda bagus"
        Else
            lbl_ucapan.Text = "Coba Lagi"
        End If
    End Sub

End Class