VB.NET

Rabu, 17 Agustus 2011

syntax vb net

Syntax di FORM 1

Public Class Form1


Private Sub TransaksiToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TransaksiToolStripMenuItem1.Click
Form2.Show()

End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
MsgBox(" Terima kasih sudah menggunakan aplikasi kami", MsgBoxStyle.Information, "perhatian")
Me.Close()

End Sub

Private Sub LaporanToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LaporanToolStripMenuItem.Click
Form3.Show()
End Sub
End Class




Di FORM 2

Imports System.Data
Imports System.Data.SqlClient

Public Class Form2
Public koneksi As String
Public sql1, sql2, sql3 As String
Public conn As SqlClient.SqlConnection = Nothing
Public cmd As SqlClient.SqlCommand = Nothing
Public dtadapter As New SqlClient.SqlDataAdapter
Public dttable As New DataTable

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
koneksi = "Data Source=.;Initial Catalog=penjualan;Integrated Security=True"
conn = New SqlClient.SqlConnection(koneksi)
conn.Open()
daftar()
ComboBox1.Items.Add("Tipe 21")
ComboBox1.Items.Add("Tipe 29")
ComboBox1.Items.Add("Tipe 36")

End Sub

Sub delete()
sql3 = "delete from transaksi3 where kode_transaksi ='" & Me.TextBox1.Text & "'"
cmd = New SqlClient.SqlCommand(sql3)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Sub bersih()
Me.TextBox1.Focus()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.ComboBox1.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.TextBox5.Text = ""
Me.TextBox6.Text = ""
End Sub

Sub simpan()
sql1 = "insert into transaksi3 values ('" & Me.TextBox1.Text & "','" & Me.TextBox2.Text & "','" & Me.TextBox3.Text & "','" & Me.ComboBox1.Text & "','" & Val(Me.TextBox4.Text) & "','" & Val(Me.TextBox5.Text) & "','" & Val(Me.TextBox6.Text) & "')"
cmd = New SqlClient.SqlCommand(sql1)
cmd.Connection = conn
cmd.ExecuteNonQuery()
End Sub

Sub daftar()
sql2 = "select * from transaksi3"
dtadapter = New SqlDataAdapter(sql2, conn)
Dim brg As New DataTable
brg.Clear()
dtadapter.Fill(brg)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
bersih()
MsgBox(" Data baru, Silahkan anda isi !!!!", MsgBoxStyle.Information, "perhatian")
TextBox1.Focus()

End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bersih()
MsgBox(" Data anda dibatalkan !", MsgBoxStyle.Information, "perhatian")

End Sub

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

simpan()
daftar()
bersih()
MsgBox(" Data sudah berhasil disimpan !", MsgBoxStyle.Information, "perhatian")
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
delete()
MsgBox(" Data berhasil dihapus !", MsgBoxStyle.Information, "perhatian")

End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Me.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
Dim harga, pajak, total As New Double
Select Case Me.ComboBox1.Text
Case "Tipe 21"
harga = 140000000
Case "Tipe 29"
harga = 180000000
Case "Tipe 36"
harga = 220000000
End Select

'hitung pajak dan total

pajak = 0.1 * Val(harga)
total = Val(harga) + Val(pajak)

'Menampilkan data hasil hitung
TextBox4.Text = harga
TextBox5.Text = pajak
TextBox6.Text = total


End Sub


End Class

0 komentar:


Posting Komentar