Senin, 25 Januari 2016

MENENTUKAN BILANGAN GENAP DAN GANJIL

MENENTUKAN BILANGAN GENAP DAN GANJIL
ASSALAMU'ALAIKUM WARAHMATULLAHI WABAROKATUH :)
 
SELAMAT DATANG DI BLOG SAYA, SAYA AKAN MEMPOSTING MENGENAI  PROGRAM VISUAL BASIC 10 YANG SAYA BUAT

PROJECT LATIHAN  10
 BERIKUT ADALAH CODING MENENTUKAN BILANGAN GENAP DAN GANJIL
Public Class Frm_lat10
    Dim Genap, Ganjil, Akhir As Integer
    Dim ket As String


    Private Sub Frm_lat10_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        utama.Enabled = True
        utama.Show()
        Me.Hide()
    End Sub

    Private Sub Frm_lat10_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        utama.Enabled = True
        utama.Show()
        Me.Hide()
    End Sub

    Sub GenapGanjil()
        Dim I, Sisabagi As Integer
        Akhir = Val(Me.Txtakhir.Text)
        If Akhir < 0 Then
            MsgBox("Masukan bilangan Genap positif", vbCritical, "salah input")
            Me.Txtakhir.Text = ""
            Me.Txtakhir.Focus()

        ElseIf Akhir >= 0 And Akhir < 5 Then
            MsgBox("Masukan bilangan Genap positif ke atas ", vbCritical, "salah input")
            Me.Txtakhir.Text = ""
            Me.Txtakhir.Focus()
        Else

            'OK

            Me.cklsGenap.Items.Clear()
            Me.CbGanjil.Items.Clear()
            If ket = ". " Then
                For I = 0 To Akhir
                Sisabagi = I Mod 2
                If Sisabagi = 0 Then
                Me.cklsGenap.Items.Add(I)
                ElseIf Sisabagi = 1 Then
                Me.CbGanjil.Items.Add(I)
                    End If
                Next
            ElseIf ket = "+" Then
                For I = Akhir To 0 Step -1
                    Sisabagi = I Mod 2
                    If Sisabagi = 0 Then
                        Me.cklsGenap.Items.Add(I)
                    ElseIf Sisabagi = 1 Then
                        Me.CbGanjil.Items.Add(I)
                    End If
                Next

            End If
        End If
    End Sub


    Private Sub Txtakhir_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Txtakhir.LostFocus
        Call GenapGanjil()
    End Sub

   
    Private Sub Bnaik_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Bnaik.Click
        ket = "+"
        Call GenapGanjil()
    End Sub

    Private Sub Bturun_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Bturun.Click
        ket = "-"
        Call GenapGanjil()
    End Sub
End Class

Tidak ada komentar:

Posting Komentar