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


Tidak ada komentar:

Posting Komentar