Minggu, 28 Oktober 2012

Tugas Visual Studio ke - 3


Pembahasan :
  1. Buka dan klik Aplikasi Microsoft Visual Studio 2010 - File - New Project.
  2. Pilih Windows Forms Application. Atur name, location, dan solution namenya. Klik Ok
Apabila tidak muncul kotak dialog Windows Form Applicationnya, kita bias menampilkannya dengan cara ctrl+shift+n.
Membuat Formnya dahulu sesuai dengan soal yang diberikan oleh dosen pengajar. Atur pada toolsboxnya dengan cara ctrl+alt+x. Atur seperti ini formnya 



  1. Kemudian klik pada form tersebut masukkan listing program berikut ini :

Public Class Frm1

    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 = 1500000
            Case "TAS"
                namabarang = "Tas"
                harga = 400000
            Case Else
                namabarang = "-"
                harga = 0
        End Select

        TxtNama.Text = namabarang
        TxtHarga.Text = harga
    End Sub
    Private Sub Frm1_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
            control.Enabled = False
            BtIsiData.Enabled = True
            BtTutup.Enabled = True
        Next
        cmbkode.Items.Add("SPT")
        cmbkode.Items.Add("SND")
        cmbkode.Items.Add("TST")
        cmbkode.Items.Add("TOP")
        cmbkode.Items.Add("TAS")
    End Sub
    Private Sub TxtJumlah_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TxtJumlahBarang.TextChanged
        TxtTotalBayar.Text = Val(TxtHargaBarang.Text) * Val(TxtJumlahBarang.Text)
        TxtTotalBayar.Text = Val(TxtTotalBayar.Text) - Val(TxtDiskon.Text)
    End Sub
    Private Sub radiotunai_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radiotunai.CheckedChanged
        TxtDiskon.Text = Val(TxtTotalBayar.Text) * 10 / 100
        TxtTotalBayar.Text = Val(TxtTotalBayar.Text) - Val(TxtDiskon.Text)
    End Sub
    Private Sub radiokredit_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles radiokredit.CheckedChanged
        TxtDiskon.Text = 0
        TxtBayar.Text = Val(TxtTotal.Text) - Val(TxtDiskon.Text)
    End Sub
    Private Sub BtClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtClear.Click
        Dim control As Windows.Forms.Control
        For Each control In Me.Controls
            control.Enabled = False
            BtIsiData.Enabled = True
            BtTutup.Enabled = True
        Next
        TxtBayar.Clear()
        TxtDiskon.Clear()
        TxtHargaBarang.Clear()
        TxtJumlahBarang.Clear()
        TxtNamaBarang.Clear()
        TxtTotalBayar.Clear()
        Me.radiotunai_Checked = False
        Me.radiokredit_Checked = False
        cmbkode.Text = ""
    End Sub
    Private Sub BtTutup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtTutup.Click
        Me.Close()
    End Sub
    Private Sub BtIsiData_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
            control.Enabled = True
            BtIsiData.Enabled = False
        Next
    End Sub

    Private Sub Label8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label8.Click
    End Sub

    Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click
    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
    End Sub

    Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
    End Sub

    Private Sub Label5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label5.Click
    End Sub

    Private Sub Label6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label6.Click
    End Sub

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click
    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
    End Sub
End Class

Jalankan programnya !
Akan muncul tampilan seperti ini :
 
  1. Buka dan klik Aplikasi Microsoft Visual Studio 2010 - File - New Project.
  2. Pilih Windows Forms Application. Atur name, location, dan solution namenya. Klik Ok
Apabila tidak muncul kotak dialog Windows Form Applicationnya, kita bias menampilkannya dengan cara ctrl+shift+n
  1. Membuat Formnya dahulu sesuai dengan soal yang diberikan oleh dosen pengajar. Atur pada toolsboxnya dengan cara ctrl+alt+x. Atur seperti ini formnya :

Masukkan Listing programnya seperti berikut ini :
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Public Class Form1
    Dim control As Windows.Forms.Control
    For Each control In Me.Controls
        If control.GetType.Name = "Button" Then
    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
    Then
                Do
                    number = tndnumber.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

Masukkan listing program ini pada button 1 :
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        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 = "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("Congratulations you're the best ... !")

        End If
    End Sub

Masukkan listing program ini pada button 2:
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 3:
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 4:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 5:
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 6 :
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = ""
        ElseIf Button5.Text = "" Then
            Button5.Text = Button6.Text
            Button6.Text = ""
        End If

        If Button1.Text = "1" And Button2.Text = "2" And Button3 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 7 :
    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button4.Text = "" Then
            Button4.Text = Button7.Text
            Button7.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 8 :
    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        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 = "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("Congratulations you're the best ... !")
        End If
    End Sub

Masukkan listing program ini pada button 9 :
    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If Button6.Text = "" Then
            Button6.Text = Button9.Text
            Button9.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.Text = Button9.Text
            Button9.Text = ""
        ElseIf Button8.Text = "" Then
            Button8.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 = "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("Congratulations you're the best ... !")
        End If
    End Sub
Jalankan programnya !
Tekan F5 atau Debug – Start Debugging



 

0 komentar:

Posting Komentar

Template by:

Free Blog Templates