Minggu, 27 Maret 2011

Memanggil & Membersihkan Method

Public Class lat1
    Dim jurusan As String
    Dim kelas, jenjang As String, waktu As Integer
    Dim d As Integer = 5
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call perintah()
    End Sub
    Sub perintah()
        Dim lo As String
        If TextBox1.Text = "TI" Then
            lo = "60"
            TextBox2.Text = "Teknik Informatika"
        Else
            If TextBox1.Text = "SI" Then
                TextBox2.Text = "Sistem Informasi"
            End If
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Call perintah()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        pros3()
    End Sub
    Sub pros3()
        ListBox1.Items.Add(TextBox3.Text + " " + TextBox4.Text + " " + TextBox5.Text + " " + TextBox6.Text + " " + TextBox7.Text)
    End Sub
    Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox4.Focus()
        End If

    End Sub

    Private Sub TextBox4_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox4.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox5.Focus()
        End If

    End Sub

    Private Sub TextBox5_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox5.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox6.Focus()
        End If
    End Sub

    Private Sub TextBox6_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox6.KeyPress
        If e.KeyChar = Chr(13) Then
            TextBox7.Focus()
        End If
    End Sub

    Private Sub TextBox7_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox7.KeyPress
        If e.KeyChar = Chr(13) Then
            Call pros3()
            Call bersihpros3()
            TextBox3.Focus()
        End If
    End Sub
    Sub bersihpros3()
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox6.Text = ""
        TextBox7.Text = ""

    End Sub
End Class


Perbedaan Dalam Penggunaan Object

Public Class Form1

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If e.KeyChar = Chr(13) Then
            ComboBox1.Items.Add(TextBox1.Text)
        End If
    End Sub

   
Dari program tersebut maka kita dapat melihat perbedaannya,ComboBox hanya dapat atau hanya untuk menampilkan satu persatu kata yang telah di input sebelumnya . namun ListBox dapat menampilkan semua kata yang di input sebelumnya.

Untuk Pengulangan Looping ,berikut programnya :

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim i As Integer
        ListBox1.Items.Clear()
        For i = 1 To Val(TextBox2.Text)
            ListBox1.Items.Add(i)
        Next
    End Sub

    Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim j, u As Integer
        u = 5

        For j = 0 To Val(TextBox2.Text)

        Next
        If j Mod u = 0 Then
            ListBox1.Items.Add(j)
            u = j

        End If

    End Sub

End Class


Perkalian Bilangan Ganjil & Genap

Perkalian dan Membuat Bilangan Ganjil & Genap Dengan menggunakan Module 
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Call tampilnama()
        TextBox1.Text = nama
    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        h = TextBox2.Text
        b = TextBox3.Text
        Call hitung()
        TextBox4.Text = hasil

    End Sub
End Class

Jangan lupa tambahkan module,berikut isinya :

Module ary
    'variablepublic
    Public nama As String, hasil, h, b As Integer
    Sub tampilnama()
        nama = "sandhy aryardhana"
    End Sub
    Sub hitung()
        hasil = Val(h)* Val(b)
    End Sub
   
End Module

Dan berikutnya Bilangan Ganjil dan Genap
Kita buat dulu desainnya :