Sunday, May 1, 2011

Tugas Visual Basic - Minggu 1 Mei 2011

Tugas VB
Sederhana saja.Inti dari program ini kita akan menampilkan Kode Barang, Nama Barang , Harga , Qty , Total dan isi yang sudah kita input di TextBox, dengan ketentuan sebagai berikut 


Klik Tombol Mulai akan   mengosongkan semua Objek Textbox
Klik Tombol Simpan akan menyimpan hasil Input dari Textbox
Total Otomatis (Output) formula
Total=Harga * Qty
Klik Selesai akan keluar dari Modus Start /Run

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = ""
        TextBox2.Text = ""
        TextBox3.Text = ""
        TextBox4.Text = ""
        TextBox5.Text = ""
        TextBox1.Focus()

        On Error GoTo TakAdaFile
        Dim Var4 As Object
        Dim Var3 As Object
        Dim Var2 As Object
        Dim Var1 As Object
        Dim noFile As Short
        noFile = FreeFile()
        FileOpen(noFile, "F:\Tugas.CSV", OpenMode.Input)
        Do While Not EOF(noFile) ' Loop until end of file.
            Input(noFile, Var1)
            Input(noFile, Var2)
            Input(noFile, Var3)
            Input(noFile, Var4)
            ListBox1.Items.Add(Var1 & "--" & Var2 & "--" & Var3 & "--" & Var4)
        Loop
        FileClose(noFile)
        Exit Sub
TakAdaFile:
        MsgBox("File Tidak ada")
    End Sub



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

        Me.Close()
    End Sub


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

        Dim var5 As Object
        Dim Var4 As Object
        Dim Var3 As Object
        Dim Var2 As Object
        Dim Var1 As Object
        Dim noFile As Short
        noFile = FreeFile()
        FileOpen(noFile, "F:\Tugas.csv", OpenMode.Append)
        Var1 = TextBox1.Text
        Var2 = TextBox2.Text
        Var3 = TextBox3.Text
        Var4 = TextBox4.Text
        var5 = TextBox5.Text
        ListBox1.Items.Add(Var1 & "-----" & Var2 & "-----" & Var3 & "----" & Var4 & "-----" & var5)
        WriteLine(1, Var1, Var2, Var3, Var4, var5)
        FileClose(1)
    End Sub
  


    Private Sub TextBox4_TextChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles TextBox4.TextChanged
        If Not Len(TextBox4.Text) = 0 Then
            TextBox5.Text = CStr(CDbl(TextBox3.Text) * CDbl(TextBox4.Text))
        End If
    End Sub





    Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
        Dim var5 As Object
        Dim Var4 As Object
        Dim Var3 As Object
        Dim Var2 As Object
        Dim Var1 As Object
        Dim noFile As Short
        noFile = FreeFile()
        FileOpen(noFile, "F:\Tugas.csv", OpenMode.Input)
        Do While Not EOF(noFile)
            Input(1, Var1)
            Input(1, Var2)
            'Input(1, Var3)
            'Input(1, Var4)
            'Input(1, var5)
            ListBox1.Items.Add(Var1 & "-----" & Var2 & "-----" & Var3 & "----" & Var4 & "-----" & var5)
        Loop
        FileClose(noFile)
    End Sub


End Class

Tampilannya sebagai berikut





Monday, March 28, 2011

Tugas Vb kedua revisi terbaru

Program ini adalah program pembelian.Terdiri atas 2 form.

Form 1

Di sana ada 7 penyanyi/band di dalam list box.Setiap namanya memiliki case () dalam kurung.Ketika

 entry setiap case di checkbox  melalui button entrynya, akan muncul harga masing-masing casenya.

Setelah Kita mengetahui semua harga, di button berapa yang harus anda bayar, kita klik muncullah form

2 nya.

Tampilan Form 1


Form2

Pada form 2 ini

Kita akan menginput data belanja

Kita akan memilih salah satu penyanyi/band favorit kita(hanya salah satu)

Untuk fans Secondhand serenade dapat diskon 10%

Untuk fans Jason Miraz dapat diskon 20%

Untuk fans Kesha dapat diskon 7%

Untuk fans Lady dapat diskon 15%

Untuk fans Paramore Ignorance 10%

Untuk fans Owl city  5%

Untuk fans Bruno Mars 15%

 

Kalau dia bayarnya credit , semua diskonnya dibatalkan

Total Belanja = Harga Bersih

Kalau dia byarnya cash, sesuai dengan prosedur awal

Button exit untuk keluar

Button Data Baru untuk mengosongkan semua text

 

 

Source Code Form 1

 

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

        Select Case ComboBox1.Text

           Case 1

                TextBox1.Text = 1000000

            Case 2

                TextBox2.Text = 560000

            Case 3

                TextBox3.Text = 780000

            Case 4

                TextBox4.Text = 1500000

            Case 5

                TextBox5.Text = 1500000

            Case 6

                TextBox6.Text = 900000

            Case 7

                TextBox7.Text = 870000

        End Select

 

    End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a As Integer

        For a = 1 To 7
            ComboBox2.Items.Add(a)
  Next a

    End Sub
End Class

 

 

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

        Form2.Show()

    End Sub

 Source Kode Form 2

Public Class Form2 

Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged

        If CheckBox1.Checked = True Then

            TextBox5.Text = 10%

            TextBox3.Text = 10 / 100 * TextBox2.Text

            TextBox6.Text = "  Dapat "

            TextBox4.Text = TextBox2.Text - TextBox3.Text

 

        End If

    End Sub

 

Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

        If CheckBox2.Checked = True Then

            TextBox5.Text = 20%

            TextBox3.Text = 20 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

    End Sub 

Private Sub CheckBox3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox3.CheckedChanged

        If CheckBox3.Checked = True Then

            TextBox5.Text = 7%

            TextBox3.Text = 7 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

    End Sub 

Private Sub CheckBox4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox4.CheckedChanged

        If CheckBox4.Checked = True Then

            TextBox5.Text = 15%

            TextBox3.Text = 15 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

    End Sub 

Private Sub CheckBox5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox5.CheckedChanged

        If CheckBox5.Checked = True Then

            TextBox5.Text = 10%

            TextBox3.Text = 10 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

    End Sub 

Private Sub CheckBox6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox6.CheckedChanged

        If CheckBox6.Checked = True Then

            TextBox5.Text = 5%

            TextBox3.Text = 5 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

    End Sub 

Private Sub CheckBox7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox7.CheckedChanged

        If CheckBox7.Checked = True Then

            TextBox5.Text = 15%

            TextBox3.Text = 15 / 100 * TextBox2.Text

            TextBox4.Text = TextBox2.Text - TextBox3.Text

            TextBox6.Text = "  Dapat "

        End If

 

    End Sub

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

        End

    End Sub

Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged

        CheckBox1.Checked = False

        CheckBox2.Checked = False

        CheckBox3.Checked = False

        CheckBox4.Checked = False

        CheckBox5.Checked = False

        CheckBox6.Checked = False

        CheckBox7.Checked = False

        TextBox5.Text = " "

        TextBox4.Text = TextBox2.Text

        TextBox6.Text = " Maaf, Anda Tidak Dapat "

    End Sub

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

        CheckBox1.Checked = False

        CheckBox2.Checked = False

        CheckBox3.Checked = False

        CheckBox4.Checked = False

        CheckBox5.Checked = False

        CheckBox6.Checked = False

        CheckBox7.Checked = False

        TextBox1.Text = " "

        TextBox2.Text = " "

        TextBox3.Text = " "

        TextBox4.Text = " "

        TextBox6.Text = " "

        TextBox5.Text = " "

        RadioButton1.Checked = False

        RadioButton2.Checked = False

    End Sub

Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged

 

    End Sub

End Class