Tugas 3 Pemrograman Visual

1.       Memodifikasi program :

  • Tampilan program  yang belum di modifikasi :

  • Program yang sudah di modifikasi :

  • Coding untuk program yang sudah di modifikasi :

2.    Tugas Program Games Puzzle

Program setelah d run :

Program setelah berhasil mengurutkan :

Berikut Kodingnya :

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

For Each control In Me.Controls

If control.GetType.Name = “Button” Then

Dim rndnumber As Random

Dim number As Integer

rndnumber = New Random

number = rndnumber.Next(1, 9)

control.Text = number

If Button2.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button2.Text = number

Loop Until Button2.Text <> Button1.Text

End If

If Button3.Text = Button2.Text Or Button3.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button3.Text = number

Loop Until Button3.Text <> Button2.Text And Button3.Text <> Button1.Text

End If

If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button4.Text = number

Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text

End If

If Button4.Text = Button3.Text Or Button4.Text = Button2.Text Or Button4.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button4.Text = number

Loop Until Button4.Text <> Button3.Text And Button4.Text <> Button2.Text And Button4.Text <> Button1.Text

End If

If Button5.Text = Button4.Text Or Button5.Text = Button3.Text Or Button5.Text = Button2.Text Or Button5.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button5.Text = number

Loop Until Button5.Text <> Button4.Text And Button5.Text <> Button3.Text And Button5.Text <> Button2.Text And Button5.Text <> Button1.Text

End If

If Button6.Text = Button5.Text Or Button6.Text = Button4.Text Or Button6.Text = Button3.Text Or Button6.Text = Button2.Text Or Button6.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button6.Text = number

Loop Until Button6.Text <> Button5.Text And Button6.Text <> Button3.Text And Button6.Text <> Button2.Text And Button6.Text <> Button1.Text

End If

If Button7.Text = Button6.Text Or Button7.Text = Button5.Text Or Button7.Text = Button4.Text Or Button7.Text = Button3.Text Or Button7.Text = Button2.Text Or Button7.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button7.Text = number

Loop Until Button7.Text <> Button6.Text And Button7.Text <> Button5.Text And Button7.Text <> Button4.Text And Button7.Text <> Button3.Text And Button7.Text <> Button2.Text And Button7.Text <> Button1.Text

End If

If Button8.Text = Button7.Text Or Button8.Text = Button6.Text Or Button8.Text = Button5.Text Or Button8.Text = Button4.Text Or Button8.Text = Button3.Text Or Button8.Text = Button2.Text Or Button8.Text = Button1.Text Then

Do

number = rndnumber.Next(1, 9)

Button8.Text = number

Loop Until Button8.Text <> Button7.Text And Button8.Text <> Button6.Text And Button8.Text <> Button5.Text And Button8.Text <> Button4.Text And Button8.Text <> Button3.Text And Button8.Text <> Button2.Text And Button8.Text <> Button1.Text

End If

End If

Button9.Text = “”

Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If Button2.Text = “” Then

Button2.Text = Button1.Text

Button1.Text = “”

ElseIf Button4.Text = “” Then

Button4.Text = Button1.Text

Button1.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

If Button9.Text = “” Then

Button9.Text = Button6.Text

Button6.Text = “”

ElseIf Button3.Text = “” Then

Button3.Text = Button6.Text

Button6.Text = “”

ElseIf Button5.Text = “” Then

Button5.Text = Button6.Text

Button6.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

If Button1.Text = “” Then

Button1.Text = Button4.Text

Button4.Text = “”

ElseIf Button7.Text = “” Then

Button7.Text = Button4.Text

Button4.Text = “”

ElseIf Button5.Text = “” Then

Button5.Text = Button4.Text

Button4.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

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

If Button1.Text = “” Then

Button1.Text = Button2.Text

Button2.Text = “”

ElseIf Button3.Text = “” Then

Button3.Text = Button2.Text

Button2.Text = “”

ElseIf Button5.Text = “” Then

Button5.Text = Button2.Text

Button2.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

If Button7.Text = “” Then

Button7.Text = Button8.Text

Button8.Text = “”

ElseIf Button9.Text = “” Then

Button9.Text = Button8.Text

Button8.Text = “”

ElseIf Button5.Text = “” Then

Button5.Text = Button8.Text

Button8.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

If Button2.Text = “” Then

Button2.Text = Button5.Text

Button5.Text = “”

ElseIf Button4.Text = “” Then

Button4.Text = Button5.Text

Button5.Text = “”

ElseIf Button6.Text = “” Then

Button6.Text = Button5.Text

Button5.Text = “”

ElseIf Button8.Text = “” Then

Button8.Text = Button5.Text

Button5.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

If Button2.Text = “” Then

Button2.Text = Button3.Text

Button3.Text = “”

ElseIf Button6.Text = “” Then

Button6.Text = Button3.Text

Button3.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

If Button4.Text = “” Then

Button4.Text = Button7.Text

Button7.Text = “”

ElseIf Button8.Text = “” Then

Button8.Text = Button7.Text

Button7.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

If Button6.Text = “” Then

Button6.Text = Button9.Text

Button9.Text = “”

ElseIf Button8.Text = “” Then

Button8.Text = Button9.Text

Button9.Text = “”

End If

If Button1.Text = “1” And Button2.Text = “2” And Button3.Text = “3” And Button4.Text = “4” And Button5.Text = “5” And Button6.Text = “6” And Button7.Text = “7” And Button8.Text = “8” And Button9.Text = “” Then

MsgBox(“Selamat Anda Menang”)

End If

End Sub

End Class

Tugas Pemrograman Visual 2

TUGAS MENGANALISA PEMROGRAMAN VISUAL

A. Latihan 1 Variabel Constanta Type Data

Berikut analisis program dari tugas Pemrograman Visual Basic :

1. Apa yang menyebabkan error btalamat1_Click pada baris program alamat = “kuningan”

  •    error dikarenakan belum ada pendeklarasian, seharusnya :

2. Kenapa saat ditekan tombol nama1 dan nama2 nama yang ditampilkan pada textbox nama berbeda sedangkan saat ditekan tombol alamat 1 dan alamat 2 alamat yang ditampilkan pada textbox alamat sama ??

  • Karena pada source code, tombol nama1 memanggil variabel nama dari local “Dim” sedangkan pada tombol nama2 memanggil variabel nama dari modul/keseluruhan “karena tidak terdapat “Dim” :

  • modul :

  • Sedangkan pada tombol alamat1 dan alamat2 apabila ditekan maka alamat yang ditampilkan di textbox sama, karena pada source code di form satu sudah terdapat variabel “Const” yaitu sebagai berikut :

3.   Kenapa saat ditekan tombol tambah umur1 umur selalu keluar angka 1 sedangkan saat ditekan tombol tambah umur2 umur selalu bertambah 1 dari umur sebelumnya ??

  • Karena tombol tambah umur1 menggunakan dim yang artinya lokal (tidak menyimpan nilai) sedangkan tombol tambah umur2 menggunakan static yang artinya nilainya tetap (disimpan) sehingga terus bertambah.

4.   Analisa pada form dua :

  • Pada form dua menggunakan “Option Explicit Off“, yang artinya pesan variabel tidak diharuskan terlebih dahulu digunakan. Sehingga tidak perlu didefinisikan lagi  karena program pada form dua ini akan mengambil definisi variabel dari public pada form satu ataupun di module.

B.  Latihan 2 If dan Case

  1. Kelamahan yang pertama adalah saat memilih item “TAS” di commbobox tidak muncul harga tetapi yang muncul “-“. Untuk perbaikannya kita lakukan cooding seperti di bawah ini :

  • Hasilnya :

2. Pada saat program dijalankan, setelah jumlah barang diisi pada textbox total bayar sudah langsung menampilkan jumlah sebelum kita pilih Tunai ataupun Kredit..

  
  
  • Cara memperbaiki dengan cara menghapus txttotalbayar.Text = Val (txtharga.Text) – Val (txtdiskon.Text) pada txt jmlbarang
   

3.  Pada saat kita klik tombol Clear ternyata total bayar masih ada angka 0, perbaikannya :

                     

4.   Ketika kita akan keluar dari program tidak ada pilihan (msg box)  untuk keluar sepeti Yes/No sehingga saat di tekan tombol tutup program akan secara langsung keluar . Maka untuk mnembahkan pilihan (msg box) tersebut di lakukan cooding seperi dibawah ini :

—> Sekian analisis yang bisa saya jelaskan, mohon maaf bila analisis yang saya berikan masih ada ksalahan dan kekurangan..

……Terimakasih …..