0
Posted by Unknown
on
15.32
1. IF & Case
Sourch Code
Public Class form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btclear.Click
MsgBox("Anda Yakin Ingin Menghapus")
txtbayar.Clear()
txtdiskon.Clear()
txtharga.Clear()
txtjumlah.Clear()
txtnama.Clear()
cmbkode.Text = ""
cmbkode.Items.Add("SPT")
cmbkode.Items.Add("SND")
cmbkode.Items.Add("TST")
cmbkode.Items.Add("TOP")
cmbkode.Items.Add("TAS")
Dim control As Windows.Forms.Control
For Each control In Me.Controls
If control.Tag = "T" Then
control.Enabled = False
End If
Next
btisidata.Enabled = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btisidata.Click
Dim control As Windows.Forms.Control
For Each control In Me.Controls
If control.Tag = "T" Then
control.Enabled = True
End If
Next
btisidata.Enabled = False
btclear.Enabled = True
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cmbkode.Items.Add("SPT")
cmbkode.Items.Add("SND")
cmbkode.Items.Add("TST")
cmbkode.Items.Add("TOP")
cmbkode.Items.Add("TAS")
Dim control As Windows.Forms.Control
For Each control In Me.Controls
If control.Tag = "T" Then
control.Enabled = False
ElseIf control.Tag = "S" Then
control.Enabled = False
End If
Next
End Sub
Private Sub bttutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bttutup.Click
MsgBox("Anda yakin ingin keluar ?")
Me.Close()
End Sub
Private Sub rbtunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtunai.CheckedChanged
txtdiskon.Text = Val(txtbayar.Text) * 10 / 100
txtbayar.Text = Val(txttotharga.Text) - Val(txtdiskon.Text)
End Sub
Private Sub cmbkode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbkode.SelectedIndexChanged
Dim kdbarang, namabarang As String
Dim harga As Single
kdbarang = cmbkode.Text
Select Case kdbarang
Case "SPT"
namabarang = "Sepatu"
harga = 200000
Case "SND"
namabarang = "Sandal"
harga = 100000
Case "TST"
namabarang = "T-Shirt"
harga = 150000
Case "TOP"
namabarang = "Topi"
harga = 500000
Case "TAS"
namabarang = "TAS"
harga = 250000
Case Else
namabarang = "---"
harga = 0
End Select
txtnama.Text = namabarang
txtharga.Text = harga
End Sub
Private Sub txtjumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtjumlah.TextChanged
txttotharga.Text = Val(txtharga.Text) * Val(txtjumlah.Text)
txtbayar.Text = Val(txttotharga.Text) - Val(txtdiskon.Text)
End Sub
Private Sub rbkredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbkredit.CheckedChanged
txtdiskon.Text = 0
txtbayar.Text = Val(txtbayar.Text) - Val(txtdiskon.Text)
End Sub
End Class
2. CheckBox
Sourch Code
Public Class Form1
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged,CheckBox2.CheckedChanged, CheckBox3.CheckedChanged, CheckBox4.CheckedChanged,CheckBox5.CheckedChanged, CheckBox6.CheckedChanged
TextBox1.Clear()
For Each item As Windows.Forms.CheckBox In GroupBox1.Controls
If item.Checked = True Then
If TextBox1.Text = TextBox1.Text & item.Text Then
TextBox1.Text = TextBox1.Text & item.Text
Else
TextBox1.Text = TextBox1.Text & "," & item.Text
End If
End If
Next
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
MsgBox("Apakah Anda Yakin")
Me.Close()
End Sub
End Class
3. Radio Button
Sourch Code
Public Class Form1
Private Sub rbtnKawin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnKawin.CheckedChanged
If rbtnPria.Checked = True Then
txtHasil.Text = "ISTRI"
ElseIf rbtnWanita.Checked = True Then
txtHasil.Text = "SUAMI"
Else
txtHasil.Text = ""
End If
End Sub
Private Sub rbtnTakKawin_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnTakKawin.CheckedChanged
If rbtnPria.Checked = True Or rbtnWanita.Checked = True Then
txtHasil.Text = "ANDA MASIH LAJANG"
Else
txtHasil.Text = ""
End If
End Sub
Private Sub rbtnPria_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnPria.CheckedChanged
If rbtnKawin.Checked = True Then
txtHasil.Text = "ISTRI"
ElseIf rbtnTakKawin.Checked = True Then
txtHasil.Text = "ANDA MASIH LAJANG"
Else
txtHasil.Text = ""
End If
End Sub
Private Sub rbtnWanita_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnWanita.CheckedChanged
If rbtnKawin.Checked = True Then
txtHasil.Text = "SUAMI"
ElseIf rbtnTakKawin.Checked = True Then
txtHasil.Text = "ANDA MASIH LAJANG"
Else
txtHasil.Text = ""
End If
End Sub
Private Sub btnTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTutup.Click
MsgBox("Anda Yakin")
Application.Exit()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnTutup.Cursor = Cursors.Hand
End Sub
End Class
4. ListBox
Sourch Code
Public Class Form1
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listkedua.SelectedIndexChanged
End Sub
Private Sub Btsatu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btsatu.Click
While Listkedua.SelectedIndices.Count > 0
Listketiga.Items.Add(Listkedua.Items(Listkedua.SelectedIndices(0)))
Listkedua.Items.Remove(Listkedua.Items(Listkedua.SelectedIndices(0)))
End While
End Sub
Private Sub List1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Txt1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Txt1.TextChanged
End Sub
Private Sub BtIsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtIsi.Click
Dim isi As String
isi = Txt1.Text
If isi.Trim <> "" Then
Listkedua.Items.Add(isi)
End If
Txt1.Text = ""
End Sub
Private Sub Btangka_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btangka.Click
Dim bil As Integer
For bil = 1 To 10
Listkedua.Items.Add(bil)
Next
End Sub
Private Sub BtBeberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtBeberapa.Click
Listkedua.SelectionMode = SelectionMode.MultiSimple
While Listkedua.SelectedIndices.Count > 0
Listketiga.Items.Add(Listkedua.Items(Listkedua.SelectedIndices(0)))
Listkedua.Items.Remove(Listkedua.Items(Listkedua.SelectedIndices(0)))
End While
End Sub
Private Sub Btsemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btsemua.Click
While Listkedua.Items.Count > 0
Listketiga.Items.Add(Listkedua.Items(0))
Listkedua.Items.RemoveAt(0)
End While
End Sub
Private Sub BtHapussatu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtHapussatu.Click
Listketiga.Items.Remove(Listketiga.SelectedItem)
End Sub
Private Sub BtHapusBeberapa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtHapusBeberapa.Click
Dim xy As Integer
Listketiga.SelectionMode = SelectionMode.MultiSimple
For xy = 0 To Listketiga.SelectedIndices.Count - 1
Listketiga.Items.RemoveAt(Listketiga.SelectedIndices(0))
Next
End Sub
Private Sub BtHapusSemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtHapusSemua.Click
Txt1.Focus()
Listketiga.Items.Clear()
End Sub
Private Sub BtTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtTutup.Click
MsgBox("Apakah Anda Yakin")
Me.Close()
End Sub
End Class
5. PUZZL
Sourch Code
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim Control As Windows.Forms.Control
Dim number As Integer
Dim rndnumber As Random
rndnumber = New Random
For Each Control In Me.Controls
If Control.GetType.Name = "Button" Then
number = rndnumber.Next(1, 9)
Control.Text = number
End If
If bt1.Text = Bt2.Text Then
Do
number = rndnumber.Next(1, 9)
Bt2.Text = number
Loop Until bt1.Text <> Bt2.Text
End If
If bt1.Text = Bt3.Text Or Bt2.Text = Bt3.Text Then
Do
number = rndnumber.Next(1, 9)
Bt3.Text = number
Loop Until bt1.Text <> Bt3.Text And Bt2.Text <> Bt3.Text
End If
If bt1.Text = Bt4.Text Or Bt2.Text = Bt4.Text Or Bt3.Text = Bt4.Text Then
Do
number = rndnumber.Next(1, 9)
Bt4.Text = number
Loop Until bt1.Text <> Bt4.Text And Bt2.Text <> Bt4.Text And Bt3.Text <> Bt4.Text
End If
If bt1.Text = Bt5.Text Or Bt2.Text = Bt5.Text Or Bt3.Text = Bt5.Text Or Bt4.Text = Bt5.Text Then
Do
number = rndnumber.Next(1, 9)
Bt5.Text = number
Loop Until bt1.Text <> Bt5.Text And Bt2.Text <> Bt5.Text And Bt3.Text <> Bt5.Text And Bt4.Text <> Bt5.Text
End If
If bt1.Text = Bt6.Text Or Bt2.Text = Bt6.Text Or Bt3.Text = Bt6.Text Or Bt4.Text = Bt6.Text Or Bt5.Text = Bt6.Text Then
Do
number = rndnumber.Next(1, 9)
Bt6.Text = number
Loop Until bt1.Text <> Bt6.Text And Bt2.Text <> Bt6.Text And Bt3.Text <> Bt6.Text And Bt4.Text <> Bt6.Text And Bt5.Text <> Bt6.Text
End If
If bt1.Text = Bt7.Text Or Bt2.Text = Bt7.Text Or Bt3.Text = Bt7.Text Or Bt4.Text = Bt7.Text Or Bt5.Text = Bt7.Text Or Bt6.Text = Bt7.Text Then
Do
number = rndnumber.Next(1, 9)
Bt7.Text = number
Loop Until bt1.Text <> Bt7.Text And Bt2.Text <> Bt7.Text And Bt3.Text <> Bt7.Text And Bt4.Text <> Bt7.Text And Bt5.Text <> Bt7.Text And Bt6.Text <> Bt7.Text
End If
If bt1.Text = Bt8.Text Or Bt2.Text = Bt8.Text Or Bt3.Text = Bt8.Text Or Bt4.Text = Bt8.Text Or Bt5.Text = Bt8.Text Or Bt6.Text = Bt8.Text Or Bt7.Text = Bt8.Text Then
Do
number = rndnumber.Next(1, 9)
Bt8.Text = number
Loop Until bt1.Text <> Bt8.Text And Bt2.Text <> Bt8.Text And Bt3.Text <> Bt8.Text And Bt4.Text <> Bt8.Text And Bt5.Text <> Bt8.Text And Bt6.Text <> Bt8.Text And Bt7.Text <> Bt8.Text
End If
If Bt0.Text <> "" Then
Bt0.Text = ""
End If
Next
End Sub
Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt1.Click
If Bt2.Text = "" Then
Bt2.Text = Bt1.Text
Bt1.Text = ""
ElseIf Bt4.Text = "" Then
Bt4.Text = Bt1.Text
Bt1.Text = ""
Else
Bt1.Text = Bt1.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt2.Click
If Bt1.Text = "" Then
Bt1.Text = Bt2.Text
Bt2.Text = ""
ElseIf Bt3.Text = "" Then
Bt3.Text = Bt2.Text
Bt2.Text = ""
ElseIf Bt5.Text = "" Then
Bt5.Text = Bt2.Text
Bt2.Text = ""
Else
Bt2.Text = Bt2.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt3.Click
If Bt2.Text = "" Then
Bt2.Text = Bt3.Text
Bt3.Text = ""
ElseIf Bt6.Text = "" Then
Bt6.Text = Bt3.Text
Bt3.Text = ""
Else
Bt3.Text = Bt3.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt4.Click
If Bt1.Text = "" Then
Bt1.Text = Bt4.Text
Bt4.Text = ""
ElseIf Bt7.Text = "" Then
Bt7.Text = Bt4.Text
Bt4.Text = ""
ElseIf Bt5.Text = "" Then
Bt5.Text = Bt4.Text
Bt4.Text = ""
Else
Bt4.Text = Bt4.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt5.Click
If Bt2.Text = "" Then
Bt2.Text = Bt5.Text
Bt5.Text = ""
ElseIf Bt4.Text = "" Then
Bt4.Text = Bt5.Text
Bt5.Text = ""
ElseIf Bt8.Text = "" Then
Bt8.Text = Bt5.Text
Bt5.Text = ""
ElseIf Bt6.Text = "" Then
Bt6.Text = Bt5.Text
Bt5.Text = ""
Else
Bt5.Text = Bt5.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt6.Click
If Bt0.Text = "" Then
Bt0.Text = Bt6.Text
Bt6.Text = ""
ElseIf Bt3.Text = "" Then
Bt3.Text = Bt6.Text
Bt6.Text = ""
ElseIf Bt5.Text = "" Then
Bt5.Text = Bt6.Text
Bt6.Text = ""
Else
Bt6.Text = Bt6.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt7.Click
If Bt8.Text = "" Then
Bt8.Text = Bt7.Text
Bt7.Text = ""
ElseIf Bt4.Text = "" Then
Bt4.Text = Bt7.Text
Bt7.Text = ""
Else
Bt7.Text = Bt7.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt8.Click
If Bt0.Text = "" Then
Bt0.Text = Bt8.Text
Bt8.Text = ""
ElseIf Bt7.Text = "" Then
Bt7.Text = Bt8.Text
Bt8.Text = ""
ElseIf Bt5.Text = "" Then
Bt5.Text = Bt8.Text
Bt8.Text = ""
Else
Bt8.Text = Bt8.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
Private Sub Bt0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Bt0.Click
If Bt8.Text = "" Then
Bt8.Text = Bt0.Text
Bt0.Text = ""
ElseIf Bt6.Text = "" Then
Bt6.Text = Bt0.Text
Bt0.Text = ""
Else
Bt0.Text = Bt0.Text
End If
If Bt1.Text = "1" And Bt2.Text = "2" And Bt3.Text = "3" And Bt4.Text = "4" And Bt5.Text = "5" And Bt6.Text = "6" And Bt7.Text = "7" And Bt8.Text = "8" And Bt0.Text = "" Then
MessageBox.Show("SELAMAT ANDA BERHASIL")
End If
End Sub
End Class
6. Program Kalkulator
Sourch Code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtJumlah.Click
TxtHasil.Text = Val(Txt1.Text) + Val(Txt2.Text)
End Sub
Private Sub BtKurang_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtKurang.Click
TxtHasil.Text = Val(Txt1.Text) - Val(Txt2.Text)
End Sub
Private Sub BtKali_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtKali.Click
TxtHasil.Text = Val(Txt1.Text) * Val(Txt2.Text)
End Sub
Private Sub BtBagi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtBagi.Click
TxtHasil.Text = Val(Txt1.Text) / Val(Txt2.Text)
End Sub
Private Sub BtClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtClear.Click
Txt1.Clear()
Txt2.Clear()
TxtHasil.Clear()
Txt1.Focus()
End Sub
Private Sub BtTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtTutup.Click
MsgBox("Yakin")
Me.Close()
End Sub
End Class
Posting Komentar