VB - VISUAL STUDIO 2010

Download Untuk Ebook Visual Studio 2010 Click here
======================================


Download Konektor Odbc 5.2.7 Click here
untuk koneksi ke database download konektor odbc
untuk menampilkan cristal riport download cristal riportnya

==================================
Provider => Penyediaan pelayanan untuk menghubungkan 
ke database/sumber data
Connection =>Perintah untuk menghubungkan ke database
Command => kode program untuk menjalankan printah edit,delet,hapus,simpan
Datareader =>Perintah untuk membaca table pada database/sumber data
DataAdapter =>untuk menghubungkan database/sumberdata dg dataset
Dataset => Objek terpish dari database/sumberdata 
seprti kolom ,baris,tabel,relasi dll

koneksi ke database
1.msaccess gunakan oledb liat vb8
conn = New OleDbConnection("Provider = microsoft.jet.oledb.4.0;data source=dbitem.mdb")
            conn.Open()

2.mysql gunakan odbc liat vb9
conn = New OdbcConnection("driver={mysql odbc 5.2 unicode driver};database=db_data;server=localhost;uid=root") conn.Open()

3.sql server gunaka sqlClient liat vb9
conn = New SqlConnection("data source=SANCESE-PC;initial catalog=dbtes;integrated security=true") conn.Open()


==================================


VB-1   => Untuk Cancel
VB-2   => Membuat Penjumlahan Dengan menggunakan Combobox
VB-3   => Membuat MessageBox di vb
VB-4   => Membuat Decision
VB-5   => Membuat Looping Di Visual Studio 2010
VB-6   => Membuat Procedure dan Function
VB-7   => Membuat Menubar dan toolbar (no desc just vidio in fb)
VB-8   => Menampilkan Data ms access Divisual Studio 2010
VB-9   => Koneksi Ke Database MySql Dan Sql Server
VB-10 => Untuk Merancang Program Simpan
VB-11 => Membuat tombol cari,update dan delete

VB-12 => Membuat Cristal riport
VB 14 => Menampilkan Data Dicristal riport Berdasarkan Tgl 
 https://youtu.be/Wc1GgBa6c74

========================================================
VIDIO

VB-1
1.1 Membuat tombol hapus dan keluar di visual studio 2010 VB 1
https://www.youtube.com/watch?v=NDxGmPj49ws
Untuk menutup semua form yang berjalan
http://pustakavb.blogspot.com/2017/02/2-langkah-simple-membuat-tombol-close-x.html?m=1

1.2 Membuat Tombol Cancel Dan Exit Di Visual Studio 2010
https://www.youtube.com/watch?v=C20KKVcGtWo

VB-2
Membuat Penjumlahan Dengan Menggunakan Combobox
https://www.youtube.com/watch?v=JvJpEbIHuZQ

VB-3
Membuat Messagebox icon divisual Studio 2010VB 3
https://www.youtube.com/watch?v=3OaK6yIaeww

VB-4
Membuat Form Decision Di Visual Studio 2010 VB 4
https://www.youtube.com/watch?v=R5yf87o4yNw

VB-5
Membuat Looping Perulangan VB 5
https://www.youtube.com/watch?v=7uZ7vSfoEL4

VB-6
Membuat Procedure dan Function Di visual Studio 2010 VB 6
https://www.youtube.com/watch?v=hP8lsSbIotg

VB-7
Membuat Menustrip dan toolstrip divisual studio 2010 VB 7
https://www.youtube.com/watch?v=41AaJFhnr3E

VB-8 
Menampilkan Data microsoft access Di Visual Studio 2010 VB 8
https://www.youtube.com/watch?v=-1WQy1VD5E0

VB-9
1.1 Koneksi Dengan Sql Server 2008 Di Visual Studio 2010 VB 9
https://www.youtube.com/watch?v=Dibi_3bd4z0
1.2 Koneksi Dengan Mysql Di Visual Studio 2010 VB 9
https://www.youtube.com/watch?v=ptouEhfex88

VB-13
Membuat relasi di sql server 2008 VB 13
https://www.youtube.com/watch?v=pdh4Ok-5nbE

VB-14
Menampilkan Data berdasarkan tanggal di Crystal Report vb 14
https://www.youtube.com/watch?v=bfkmI_iFCQI

-Menampilkan data sql server di combobox
-Penjumlahan/perkalian
-Cara Menampilkan data kedalam list dan combobox(Sql server)
-Penggunaan KeyPress / Berpindah Saat Di Enter
-Kode Login
-Menampilkan Nama Setelah Login
-Membuat format pada datetimepicker
-Pengecekan untuk nilai Null
-Print langsung ke Printer
===================================
-Print langsung ke Printer

1.Buatlah Form masukan kode
Public Class frmDirectPrint

    Private Sub Button1_Click(ByVal sender As System.Object, _
        ByVal As System.EventArgs) Handles Button1.Click
        Dim strPrint As String
        strPrint = "Toko Jualan Saya" & vbCrLf
        strPrint = strPrint & "------------------------------" & vbCrLf
        strPrint = strPrint & "No   : TN1254389" & vbCrLf
        strPrint = strPrint & "Kasir: Lana" & vbCrLf
        strPrint = strPrint & " " & vbCrLf
        strPrint = strPrint & "Nama   Qty. Harga SubTotal" & vbCrLf
        strPrint = strPrint & 
"------------------------------" & vbCrLf
        strPrint = strPrint & "Ciki     2   5000    10000" & vbCrLf
        strPrint = strPrint & "Akua     3   1000     3000" & vbCrLf
        strPrint = strPrint & 
"------------------------------" & vbCrLf
        strPrint = strPrint & "Total                13000" & vbCrLf

        Printer.Print(strPrint)
    End Sub

End Class

2.Buatlah class Printer

Public Class Printer
    Private Shared Lines As New Queue(Of String)
    Private Shared _myfont As Font
    Private Shared prn As Printing.PrintDocument

    Shared Sub New()
        _myfont = New Font("Courier New", _
                  8, FontStyle.Regular, GraphicsUnit.Point)
        prn = 
New Printing.PrintDocument
        AddHandler prn.PrintPage, AddressOf PrintPageHandler
    End Sub

    Public Shared Sub Print(ByVal text As String)
        Dim linesarray() = text.Split(New String() _
            {Environment.NewLine}, StringSplitOptions.None)

        For Each line As String In linesarray
            Lines.Enqueue(line)
        Next
        prn.Print()
    End Sub

    Private Shared Sub PrintPageHandler(ByVal sender As Object, _
        ByVal As Printing.PrintPageEventArgs)

        
Dim sf As New StringFormat()
        
Dim vpos As Single = e.PageSettings.HardMarginY

        Do While Lines.Count > 0
            Dim line As String = Lines.Dequeue
            Dim sz As SizeF = e.Graphics.MeasureString( _
                line, _myfont, e.PageSettings.Bounds.Size, sf)

            
Dim rct As New RectangleF( _
                e.PageSettings.HardMarginX, vpos, _
                e.PageBounds.Width - e.PageSettings.HardMarginX * 2, _
                e.PageBounds.Height - e.PageSettings.HardMarginY * 2)

            e.Graphics.DrawString(line, _myfont, Brushes.Black, rct)
            vpos += sz.Height
            If vpos > e.PageSettings.Bounds.Height - _
                e.PageSettings.HardMarginY * 2 Then
                e.HasMorePages = True
                Exit Sub
            End If
        Loop
    End Sub
End Class

 

===================================
-Pengecekan untuk nilai Null
Sub total_penjualan()
        Dim menit_tgl_awal As String
        Dim menit_tgl_akhir As String
        menit_tgl_awal = " 00:00:00"
        menit_tgl_akhir = " 23:59:59"
        t1.Text = tgl.Text & menit_tgl_awal
        Call koneksi()
        sql = "select sum(TotalPembayaran) from TransactionHeader where TransactionDate between '" & tgl.Text & menit_tgl_awal & "' and '" & tgl.Text & menit_tgl_akhir & "' "
        cmd = New SqlCommand(sql, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr.HasRows Then
            If dr(0) Is DBNull.Value Then
                MsgBox("Data transaksi Tidak Ada")
            Else
                total.Text = dr.GetInt32(0)
            End If
        End If
    End Sub

Referensi :
https://social.msdn.microsoft.com/Forums/id-ID/42e6fad5-cb89-406e-aa79-ce1506beccdb/tanya-cara-mengecek-null-value-dari-database-mysql-di-vbnet-2010?forum=visualbasicid

==============================
Membuat format pada datetimepicker
tgl.Format = DateTimePickerFormat.Custom
 tgl.CustomFormat = "yyyy/MM/dd"
atau
Format(tgl.Value, "yyyy-MM-dd")
===============================
Membatasi input data
https://youtu.be/P2Dc9KdvqYM

Penjumlahan/perkalian

t_total.Text = Val(t_quantity.Text) * Val(t_harga.Text)
/////
Dim quantity, harga As Integer
        quantity = Val(t_quantity.Text)
        harga = Val(t_harga.Text)
        t_total.Text = Format(quantity * harga, "#,###")
/////
========================================================
Cara Menampilkan data kedalam list dan combobox(Sql server)
kode program

Imports System.Data.SqlClient

 

Public Class Latihan

Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Dim cmd As SqlCommand
Dim dr As SqlDataReader

 

Sub Koneksi()
conn = New SqlConnection("data source=user-pc\sqlexpress;initial catalog=dbnashir;integrated security=true")
conn.Open()
End Sub

 

Private Sub Latihan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
cmd = New SqlCommand("select * from tblbarang", conn)
dr = cmd.ExecuteReader
Do While dr.Read
ListBox1.Items.Add(dr.Item("kode_barang"))
ComboBox1.Items.Add(dr.Item(1))
Loop
End Sub

End Class


Menampilkan data sql server di combobox

Private Sub ComboBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox2.SelectedIndexChanged
        Call koneksi()
        sql = "select*from type where id='" & ComboBox2.Text & "'"
        cmd = New SqlCommand(sql, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr.HasRows Then
            TextBox1.Text = dr.GetString(1)
            TextBox2.Text = dr.GetInt32(2)

        Else
            cmd.Dispose()
            conn.Close()
            MsgBox("data tidak ditemukan")
        End If
    End Sub


========================================================
Kode Login 

Imports System.Data.SqlClient
Public Class Form1 // kode dari system
    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dr As SqlDataReader
    Dim ds As DataSet
    Dim sql As String
    Sub koneksi()
        Try
            conn = New SqlConnection("Data Source=SANCE-PC\SQLEXPRESS;initial catalog=dbSekolah;integrated security=true")
            conn.Open()
        Catch ex As Exception

        End Try
    End Sub

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
        Call koneksi()
        sql = "Select * from tbLogin where username ='" & t1.Text & "' and password ='" & t2.Text & "'"
        cmd = New SqlCommand(sql, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr.HasRows Then
            Menu_Utama.ShowDialog()

        Else
            MessageBox.Show("Silahkan Cek Kembali username dan passwordnya" + Chr(13) + "Silahkan Login Lagi", "Gagal Login", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
            t1.Text = ""
            t2.Text = ""
        End If
    End Sub

========================================================
Penggunaan KeyPress / Berpindah Saat Di Enter

If (e.KeyChar = ChrW(Keys.Enter)) Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If

Contoh Pneggunaan pada even key press :
 Private Sub t2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t2.KeyPress
        If (e.KeyChar = ChrW(Keys.Enter)) Then
            SendKeys.Send("{TAB}")
            e.Handled = True
        End If
    End Sub

atau menggunakan ini untuk posisi tertentu
Private Sub t_itemcode_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t_itemcode.KeyPress
        If (e.KeyChar = ChrW(Keys.Enter)) Then
            t_quantity.Focus()
        End If
    End Sub


Ref : Click here
========================================================
Menampilkan Nama Setelah Login

Main_Form.t_nama.Text = t1.Text

Ref : Click here

========================================================

VB 14 
Rangkuman kode program

Buat Form1
Berisi tgl awal dan akhir yang diarahkan ke form2 

-pastikan tool cristal ripot aktip 
liat vb12 tentng crstal riport (mengkatipkan .net framework 4 untuk cristal riport)
-Buat lah projek riport dari
project =>add windows form=>Cristal Riport RPT
-Baca vb12 dri no 5

Buat parameter awal dan akhir
isi name parameter 
type date
show on panel dont show klik ok

klik kanan pada blank riport
pilih riport =>selection formula=>record
kemuadian ketik
DateTimeValue({Stock.tgl})>={?awal} and

DateTimeValue({Stock.tgl})>={?akhir}

Buat Form 2
tambahkan cristal riport viewer
pada panah tiga choose a tool panel view pilih none
Downble klik pinggir judul agar masuk load form
pada load ketik yang merah

Imports CrystalDecisions.CrystalReports.Engine
Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim lap As New ReportDocument
        lap.Load("..\..\penjualan.rpt")
        lap.SetParameterValue("awal", Form1.tgl1.text)
        lap.SetParameterValue("akhir", Form1.tgl2.Text)
        CrystalReportViewer1.ReportSource = lap
    End Sub

End Class

kembali ke form1 beri format pada load

 tgl1.Format = DateTimePickerFormat.Custom
        tgl1.CustomFormat = "yyyy/MM/dd"
        tgl2.Format = DateTimePickerFormat.Custom

        tgl2.CustomFormat = "yyyy/MM/dd"

Selebihnya Silahkan lihat Vidionya
========================================================

VB-12 => Membuat Cristal riport

pilih salah satu saja untuk didownload
biasanya saya download dari google drive

1.Download cristal riport
alamat website =
http://www.intika34.com/2017/05/cara-instal-dan-menampilkan-crystal-report-di-vb-2010.html password : www.intika34.com  mediafire : 
http://www.mediafire.com/file/k09gpm533u82o6c/CRforVS_13_0_19.rar/file

2.Download dr Google Drive :
Click here

Buat lah projek baru ,pilih
1.projek =>windows aplication11 properites
2.compile=>Advanced Compile Options=>.net Framework 4(nanti akan muncul cristal riport)
3.Buat Cristal riport di menu riport ke Form
4.Plih segitiga kecil di cristal riport=>chose a tool panel view = none
5.create a new cristal riport => using the riport wizart
6.create new connection,plih Ole DB
7.cari Microsoft Ole DB provider for sql server
8.pilh name server,centang integrated security
9.pihih db =>finish
10.pindahkan table klik >
11.pilih semua klik >>
12.next sampe finish

13.plih expand table(+) pilih dbo tandai table tekan > kemudian tekan >>
pilih next sampe finish

cara menambahkan text
1.pilih menu cristal riport
2.insert =>text

========================================================
VB-11 => Membuat tombol cari,update dan delete






Imports System.Data.SqlClient Public Class Form1 Dim conn As SqlConnection Dim da As sqlDataadapter Dim dr As Sqldatareader Dim cmd As sqlcommand Dim ds As DataSet Dim sql As String Sub koneksi() Try conn = New SqlConnection("Data Source=ASUS-11\SQLEXPRESS;Initial Catalog=PERT11;Integrated Security=True") conn.Open() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Sub tampil() Call koneksi() sql = "select*from anggota" da = New SqlDataAdapter(sql, conn) ds = New DataSet ds.Clear() da.Fill(ds, "anggota") DataGridView1.DataSource = ds.Tables(0) End Sub Sub cari() Call koneksi() Dim xnoang = InputBox("masukkan nomor anggota") sql = "select*from anggota where noang='" & xnoang & "'" cmd = New SqlCommand(sql, conn) dr = cmd.ExecuteReader dr.Read() If dr.HasRows Then t1.Text = dr.GetString(0) t2.Text = dr.GetString(1) t3.Text = dr.GetString(2) t4.Text = dr.GetString(3) t5.Text = dr.GetDateTime(4) Else cmd.Dispose() conn.Close() MsgBox("data tidak ditemukan") End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call tampil() End Sub Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click Call cari() End Sub Private Sub b2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b2.Click Call koneksi() sql = "update anggota set nama='" & t2.Text & "',Kelas='" & t3.Text & "',alamat='" & t4.Text & "',tgldaftar='" & (Format(t5.Value, "yyyy-MM-dd")) & "' where noang='" & t1.Text & "'" cmd = New SqlCommand(sql, conn) cmd.ExecuteNonQuery() MsgBox("data sudah diedit") cmd.Dispose() conn.Close() Call tampil() t1.Text = " " t2.Text = " " t3.Text = " " t4.Text = " " End Sub Private Sub b3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3.Click Call koneksi() sql = "delete from anggota where noang='" & t1.Text & "'" cmd = New SqlCommand(sql, conn) cmd.ExecuteNonQuery() MsgBox("data sudah dihapus") cmd.Dispose() conn.Close() Call tampil() t1.Text = " " t2.Text = " " t3.Text = " " t4.Text = " " End Sub End Class



========================================================

VB-10 => Untuk Merancang Program Simpan

Untuk id yang menggunakan Primari key idnya tidak dituliskan lagi dlm
proses insert contoh nya

sql = "insert into mahasiswa (nama,alamat,nilai,ket) values ('" & t1.Text & "','" & t2.Text & "','" & t3.Text & "','" & t4.Text & "')"
   
 insert tanggal Di VB
http://rani-irsan.blogspot.com/2015/10/vbnet-bekerja-dengan-date-dan-time.html

sql = "insert into TransactionHeader values('" & 123 & "','" & c_layanan.Text & "','" & t_harga.Text & "','" & t_diskon.Text & "','" & t_quantity.Text & "','" & 1000 & "','" & Now & 


Imports System.Data.SqlClient
Public Class Form1

    Dim conn As SqlConnection
    Dim cmd As SqlCommand
    Dim da As SqlDataAdapter
    Dim dr As SqlDataReader
    Dim ds As DataSet
    Dim sql As String
    Sub koneksi()
        Try
            conn = New SqlConnection("Data Source = HP-15;initial catalog=satu;integrated security=true")
            conn.Open()
        Catch ex As Exception

        End Try
    End Sub
    Sub tampil()
        Call koneksi()
        Sql = "Select * from anggota"
        da = New SqlDataAdapter(sql, conn)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "anggota")
        DataGridView1.DataSource = ds.Tables("anggota")
    End Sub
    Sub keadaan(ByVal a As Boolean)
        t1.Enabled = a
        t2.Enabled = a
        t3.Enabled = a
        t4.Enabled = a
    End Sub
    Sub kosong()
        t1.Text = ""
        t2.Text = ""
        t3.Text = ""
        t4.Text = ""
    End Sub
 

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call tampil()
        Call keadaan(False)
        t3.Items.Add("X")
        t3.Items.Add("XI")
        t3.Items.Add("XII")
    End Sub

 

    Private Sub b1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b1.Click
        Call keadaan(True)
        Call kosong()
        t1.Focus()

    End Sub
    Sub simpan()
        Call koneksi()
        sql = "insert into anggota values('" & t1.Text & "','" & t2.Text & "','" & t3.Text & "','" & t4.Text & "','" & (Format(t5.Value, "yyyy-MM-dd")) & "')"
        cmd = New SqlCommand(sql, conn)
        cmd.ExecuteNonQuery()
        MsgBox("Data sudah disimpan")
        cmd.Dispose()
        conn.Close()
    End Sub
    Sub ujidata()
        Call koneksi()
        sql = "select * from anggota where noang ='" & t1.Text & "'"
        cmd = New SqlCommand(sql, conn)
        dr = cmd.ExecuteReader
        dr.Read()
        If dr.HasRows Then
            MsgBox("Data tersebut sudah ada")
            Exit Sub
        Else
            cmd.Dispose()
            conn.Close()
            Call simpan()
        End If
    End Sub
    Private Sub b2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b2.Click
        Call ujidata()

        Call tampil()
        Call keadaan(False)
        Call kosong()
    End Sub

    Private Sub b3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b3.Click
        Call kosong()
    End Sub

    Private Sub b4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles b4.Click
        Me.Close()
    End Sub
End Class


========================================================

VB-9 => Koneksi Ke Database MySql Dan Sql Server

-Koneksi ke mysql

Imports System.Data.Odbc Public Class Form1 Dim conn As OdbcConnection Dim cmd As OdbcCommand Dim da As OdbcDataAdapter Dim dr As OdbcDataReader Dim ds As DataSet Sub koneksi() Try conn = New OdbcConnection("driver={mysql odbc 5.2 unicode driver};database=db_data;server=localhost;uid=root") conn.Open() Catch ex As Exception End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call koneksi() da = New OdbcDataAdapter("select * from pesan1", conn) ds = New DataSet ds.Clear() da.Fill(ds, "pesan1") DataGridView1.DataSource = ds.Tables("pesan1") End Sub End Class




-Koneksi ke Sql server di visual studio 2010

Imports System.Data.SqlClient Public Class Form1 Dim conn As SqlConnection Dim cmd As SqlCommand Dim da As SqlDataAdapter Dim dr As SqlDataReader Dim ds As DataSet Sub koneksi() Try conn = New SqlConnection("data source=SANCESE-PC;initial catalog=dbtes;integrated security=true") conn.Open() Catch ex As Exception End Try End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call koneksi() da = New SqlDataAdapter("select * from tb_Absent", conn) ds = New DataSet ds.Clear() da.Fill(ds, "tb_Absent") DataGridView1.DataSource = ds.Tables("tb_Absent") End Sub End Class


========================================================
VB-8 => Menampilkan Data ms access Divisual Studio 2010

Simpan database.mdb nya di folder
D:\namaFile\namaProject\bin\debug
pindahkan filenya disini



Imports System.Data.OleDb
Public Class Form1
    Dim conn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim da As OleDbDataAdapter
    Dim ds As DataSet
    Sub koneksi()
        Try
            conn = New OleDbConnection("Provider = microsoft.jet.oledb.4.0;data source=dbitem.mdb")
            conn.Open()
        Catch ex As Exception

        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Call koneksi()
        da = New OleDbDataAdapter("select * from item", conn)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "item")
        dg1.DataSource = ds.Tables("item")
    End Sub
End Class

========================================================

VB-6 Membuat Procedure dan Function
Form 1 Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load For a = 2000 To 2020 Step 1 cbo1.Items.Add(a) Next Call keadaan(False) End Sub Sub keadaan(ByVal a As Boolean) t1.Enabled = a t2.Enabled = a t3.Enabled = a cbo1.Enabled = a r1.Enabled = a r2.Enabled = a End Sub Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click Call keadaan(True) End Sub Private Sub btnNonaktif_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNonaktif.Click Call keadaan(False) End Sub Sub tampil(ByVal a As Boolean) t1.Visible = a t2.Visible = a t3.Visible = a cbo1.Visible = a r1.Visible = a r2.Visible = a End Sub Private Sub btnTampil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTampil.Click Call tampil(True) End Sub Private Sub btnSembunyi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSembunyi.Click Call tampil(False) End Sub Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click t1.Text = "" t2.Text = "" t3.Text = "" cbo1.Text = "" r1.Text = "" r2.Text = "" End Sub Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click Me.Close() End Sub Private Sub btnNextForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNextForm.Click Form2.Show() End Sub End Class Form 2 Public Class Form2 Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub t2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles t2.KeyDown If e.KeyCode = 13 Then If t2.Text = "A01" Then t3.Text = "BUKU" t4.Text = 1000 ElseIf t2.Text = "A02" Then t3.Text = "LAPTOP" t4.Text = 2000 ElseIf t2.Text = "A03" Then t3.Text = "HANDPHONE" t4.Text = 3000 Else t3.Text = "AC" t4.Text = 4000 End If End If End Sub Private Sub t2_MouseWheel(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles t2.MouseWheel End Sub Private Sub t2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t2.TextChanged End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click t1.Text = vbEmpty t2.Text = "" t3.Text = "" t4.Text = "" t5.Text = "" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click Me.Close() End Sub Function penjumlahan(ByVal a As Decimal, ByVal b As Decimal) Return a + b End Function Private Sub r1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r1.CheckedChanged t1.Text = Format(penjumlahan(t4.Text, t5.Text), "#,###") End Sub Function pengurangan(ByVal a As Decimal, ByVal b As Decimal) Return a - b End Function Private Sub r2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r2.CheckedChanged t1.Text = Format(pengurangan(t4.Text, t5.Text), "#,###") End Sub Function perkalian(ByVal a As Decimal, ByVal b As Decimal) Return a * b End Function Private Sub r3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r3.CheckedChanged t1.Text = Format(perkalian(t4.Text, t5.Text), "#,###") End Sub Function pembagian(ByVal a As Decimal, ByVal b As Decimal) Return a / b End Function Private Sub r4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r4.CheckedChanged t1.Text = Format(pembagian(t4.Text, t5.Text), "#,###") End Sub Function sisabagi(ByVal a As Decimal, ByVal b As Decimal) Return a Mod b End Function Private Sub r5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles r5.CheckedChanged t1.Text = Format(sisabagi(t4.Text, t5.Text), "#,###") End Sub End Class ======================================================== VB-5 Membuat Looping Di Visual Studio 2010
Public Class Form1 Private Sub btnFor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFor.Click For a = 1 To 10 Step 1 cbo1.Items.Add(a) Next End Sub Private Sub btnWhile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnWhile.Click Dim b As Integer b = 1 While b <= 10 l1.Items.Add(b) b = b + 1 End While End Sub Private Sub btnLoopUntil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoopUntil.Click Dim c As Integer c = 1 Do cbo2.Items.Add(c) c = c + 1 Loop Until c > 10 End Sub Private Sub btnDoWhile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoWhile.Click Dim d As Integer d = 1 Do While d <= 10 If d Mod 2 = 1 Then ganjil.Items.Add(d) Else genap.Items.Add(d) End If d = d + 1 Loop End Sub End Class

========================================================
VB-4
Membuat Decision

FORM 1
Public Class Form1

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

    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cb1.Items.Add("MI")
        cb1.Items.Add("TK")
        cb1.Items.Add("KA")
    End Sub

    Private Sub cb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb1.SelectedIndexChanged
        If cb1.Text = "MI" Then
            t1.Text = "MANAGEMENT INFORMATIKA"
            t2.Text = 1000
        ElseIf cb1.Text = "TK" Then
            t1.Text = "TEKNIK KOMPUTER"
            t2.Text = 2000
        Else
            t1.Text = "KOMPUTER AKUTANSI"
            t2.Text = 3000
        End If
    End Sub

    Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
        Dim hapus As String
        hapus = MessageBox.Show("APAKAH ANDA INGIN MENGHAPUSNYA", "PEMBERITAHUAN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If hapus = vbYes Then
            t1.Text = ""
            t2.Text = ""
            cb1.Text = ""
        End If
    End Sub

    Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
        Me.Close()
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Form2.Show()
    End Sub
End Class

FORM 2

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cb1.Items.Add("A")
        cb1.Items.Add("B")
        cb1.Items.Add("C")
        cb1.Items.Add("D")
    End Sub

    Private Sub cb1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles cb1.KeyDown
        If e.KeyCode = 13 Then
            Select Case cb1.Text
                Case "A"
                    t1.Text = 1000
                Case "B"
                    t1.Text = 2000
                Case "C"
                    t1.Text = 3000
                Case Else
                    t1.Text = 4000
            End Select
        End If
    End Sub

    Private Sub cb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb1.SelectedIndexChanged

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim hapus As String
        hapus = MessageBox.Show("APAKAH ANDA YAKIN INGIN MENGHAPUS NYA", "PEMBERITAHUAN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
        If hapus = vbYes Then
            t1.Text = ""
            cb1.Text = ""
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class
========================================================
VB-3
Membuat MessageBox di vb

Macam2 Messagebox
Exclamation,Information,question,error

Membuat MessageBox Di Visual Studio 2010
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
MessageBox.Show("SELAMAT DATANG " + Chr(13) + "DIFORM PENDAFTARAN", "FORM PENDAFTARAN", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub
Private Sub t1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles t1.KeyPress
If e.KeyChar = Chr(13) Then
If t1.Text = "" Then
MessageBox.Show("NIM TIDAK BOLEH KOSONG")
ElseIf IsNumeric(t1.Text) = False Then
MessageBox.Show("NIM HARUS BERUPA ANGKA")
ElseIf Len(t1.Text) < 8 Then
MessageBox.Show("NIM TIDAK BOLEH KURANG DARI 8")
Else
t2.Focus()
End If
End If
End Sub
Private Sub t1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.TextChanged
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
Dim cek As String
cek = MessageBox.Show("APAKAH ANDA INGIN MENGHAPUSNYA ?? ", "PEMBERITAHUAN", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation)
If cek = vbYes Then
t1.Text = ""
t2.Text = ""
t1.Focus()
End If
End Sub
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
Me.Close()
End Sub
End Class
========================================================
VB-2
Membuat Penjumlahan Dengan menggunakan Combobox

Membuat Penjumlahan Dengan Menggunakan Combobox Di Visual Studio 2010
Public Class Form1
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub t1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles t1.TextChanged
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
cb1.Items.Add("+")
cb1.Items.Add("-")
cb1.Items.Add("*")
cb1.Items.Add("/")
End Sub
Private Sub cb1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cb1.SelectedIndexChanged
If cb1.Text = "+" Then
t3.Text = Val(t1.Text) + Val(t2.Text)
ElseIf cb1.Text = "-" Then
t3.Text = Val(t1.Text) - Val(t2.Text)
ElseIf cb1.Text = "*" Then
t3.Text = Val(t1.Text) * Val(t2.Text)
Else
t3.Text = Val(t1.Text) / Val(t2.Text)
End If
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
t1.Text = ""
t2.Text = ""
t3.Text = ""
cb1.Text = ""
End Sub
Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click
Me.Close()
End Sub
End Class
========================================================
VB-1
Untuk Cancel

 Private Sub bCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bCancel.Click
        t1.Text = ""
        t2.Text = ""
        cb1.Text = ""
        t1.Focus()
 End Sub


Untuk Exit

 Private Sub bExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bExit.Click
        Me.Close()
End Sub



VB - VISUAL STUDIO 2010 VB - VISUAL STUDIO 2010 Reviewed by Leo on 12:32 Rating: 5

No comments