Sabtu, 29 Maret 2014

Pemrograman Visual basic 2010 Menghitung Nilai akhir,penggunaan DataGriedview

Public Class Form1
    Dim Y As Byte
    Function NAKHIR(ByVal TUGAS As Single, ByVal UTS As Single, ByVal UAS As Single)
        NAKHIR = 0.2 * TUGAS + 0.3 * UTS + 0.5 * UAS

    End Function

    Sub NHRFBBT(ByVal NA As Single, ByRef HRF As String, ByRef BBT As Byte)
        If NA >= 81 Then
            HRF = "A"
            BBT = 4
        ElseIf NA > 76 Then
            HRF = "B+"
            BBT = 3.5
        ElseIf NA > 71 Then
            HRF = "B"
            BBT = 3
        ElseIf NA >= 66 Then
            HRF = "C+"
            BBT = 2.5
        ElseIf NA >= 61 Then
            HRF = "C"
            BBT = 2
        ElseIf NA >= 51 Then
            HRF = "D"
            BBT = 1.5
        ElseIf NA >= 40 Then
            HRF = "E"
            BBT = 0
        End If

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DataGridView1.RowCount = 1
        DataGridView1.ColumnCount = 9
        DataGridView1.Columns(0).HeaderText = "NO URUT"
        DataGridView1.Columns(1).HeaderText = "Nama"
        DataGridView1.Columns(2).HeaderText = "NPM"
        DataGridView1.Columns(3).HeaderText = "N.TUGAS"
        DataGridView1.Columns(4).HeaderText = "N.UTS"
        DataGridView1.Columns(5).HeaderText = "N..UAS"
        DataGridView1.Columns(6).HeaderText = "N.AKHIR"
        DataGridView1.Columns(7).HeaderText = "N.HRF"
        DataGridView1.Columns(8).HeaderText = "N.BOBOT"
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim NA As Single
        Dim NH As String
        Dim NB As Byte

        DataGridView1.RowCount = DataGridView1.RowCount + 1
        DataGridView1.Item(0, Y).Value = Y + 1
        DataGridView1.Item(1, Y).Value = TextBox1.Text
        DataGridView1.Item(2, Y).Value = TextBox2.Text
        DataGridView1.Item(3, Y).Value = TextBox3.Text
        DataGridView1.Item(4, Y).Value = TextBox4.Text
        DataGridView1.Item(5, Y).Value = TextBox5.Text
        NA = NAKHIR(Val(TextBox3.Text), Val(TextBox4.Text), Val(TextBox5.Text))
        DataGridView1.Item(6, Y).Value = NA
        Call NHRFBBT(NA, NH, NB)
        DataGridView1.Item(7, Y).Value = NH
        DataGridView1.Item(8, Y).Value = NB
        Y = Y + 1
     
    End Sub
    Sub VALIDASI(ByVal Nilai As Single)
        If (Nilai < 0) Or ((Nilai > 100)) Then
            MsgBox("Nilai Harus 0 S/D 100")
        End If
    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
        VALIDASI(Val(TextBox5.Text))
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim JUMA, JUMBB, JUMB, JUMCC, JUMC, JUMD, JUME, I As Integer

        DataGridView2.RowCount = 7
        DataGridView2.ColumnCount = 2
        DataGridView2.Columns(0).HeaderText = "Huruf"
        DataGridView2.Columns(1).HeaderText = "Jumlah Huruf"
        JUMA = 0
        JUMBB = 0
        JUMB = 0
        JUMCC = 0
        JUMC = 0
        JUMD = 0
        JUME = 0
        For I = 0 To DataGridView2.RowCount = 1

            If DataGridView1.Item(7, I).Value = "A" Then
                JUMA = JUMA + 1
            ElseIf DataGridView1.Item(7, I).Value = "B+" Then
                JUMBB = JUMBB + 1
            ElseIf DataGridView1.Item(7, I).Value = "B" Then
                JUMB = JUMB + 1
            ElseIf DataGridView1.Item(7, I).Value = "C+" Then
                JUMC = JUMC + 1
            ElseIf DataGridView1.Item(7, I).Value = "C" Then
                JUMCC = JUMCC + 1
            ElseIf DataGridView1.Item(7, I).Value = "D" Then
                JUMD = JUMD + 1
            ElseIf DataGridView1.Item(7, I).Value = "E" Then
                JUME = JUME + 1
            End If
        Next
        DataGridView2.Item(0, 0).Value = "A"
        DataGridView2.Item(1, 0).Value = JUMA
        DataGridView2.Item(0, 1).Value = "B+"
        DataGridView2.Item(1, 1).Value = JUMBB
        DataGridView2.Item(0, 2).Value = "B"
        DataGridView2.Item(1, 2).Value = JUMB
        DataGridView2.Item(0, 3).Value = "C+"
        DataGridView2.Item(1, 3).Value = JUMC
        DataGridView2.Item(0, 4).Value = "C"
        DataGridView2.Item(1, 4).Value = JUMCC
        DataGridView2.Item(0, 5).Value = "D"
        DataGridView2.Item(1, 5).Value = JUMD
        DataGridView2.Item(0, 6).Value = "E"
        DataGridView2.Item(1, 6).Value = JUME
    End Sub

    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        VALIDASI(Val(TextBox4.Text))

    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim X As Integer
        For X = 0 To DataGridView1.RowCount - 1
            If (DataGridView1.Item(1, X).Value = TextBox1.Text) Then
                MsgBox("Nim Sudah Ada")
                TextBox1.Clear()
                TextBox1.Focus()
            End If
        Next
    End Sub

    Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick

    End Sub
End Class


Tidak ada komentar: