Cari Data
sub jurusan()
call koneksi
tampil2.connection = database
tampil2.CommandType = Commandtype.Text
tampil2.CommandText = "select * from jurusan where kdjur='" &Trim(TextBox1.Text)& "'
tampilkan = tampil2.Executereader
if tampilkan.Hasrows = True than
while tampilkan.read()
if ISDBNull (Tampilkan("kdjur")) Then
TextBox2.text="_"
else
TextBox2.Text = Tampilkan("nmjur")
End if
End While
End if
CEK RECORD
Sub cekrecord()
call koneksi()
tampil.connection = database
tampil.commandType=commandtype.Text
tampil.commandText = "Select * from jurusan where kd='" & trim(Textbox1.text)& "'
tampilkan = tampil.executeReader
if tampilkan.Hasrows = true then
hasilcek = true
else
hasilcek = false
end if
end sub
INSERT DATA
if TextBox1.Text = "" Then exit sub
if TextBox2.Text = "" Then Exit Sub
call koneksi()
Try
if hasilcek = "false" then
call koneksi()
tampil.connection = database
tampil.commandType = CommandText.Text
tampil.commandType = " insert into jurusan (kdjur,nmjur)values('" & TextBox1.text & "','" & TextBox.text & "')"
tampil.ExecuteNonQuery()
call kosong()
else
msgBox("data sudah ada", msgboxStyle.Critical,"input data")
textbox1.focus()
end if
Catch ex As exception
msgBox(ex.ToString())
end if
end sub
UBAH DATA/ UPDATE/b>
Try
call koneksi()
tampil.connection= database
tampil.commandType = commandType.Text
tampil.commandText = " update jurusan set nmjur='"& Trim(TextBox2.Text) & "' where
kdjur = '" & Trim(TextBox1.Text) & "'"
tampil.ExecuteNonQuery()
call kosong()
TextBox1.Focus()
catch ex As Exception
msgBox(ex.ToString())
end try
end sub
Rabu, 08 Juni 2011
Kamis, 19 Mei 2011
Koneksi VB 2010 Database SQL sever
Untuk menghubungkan VB ke SQL Server diperlukan variabel
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Untuk konek database sever:
Database.connectionstring = "Provider = SQLOLEDB.1; Password=sandi; persist security
Info = True; User ID = SS; Initial Catalog = nmdatabase; Data Source = 192.168.10.44" ( Data source bisa nama komputer sever atau no IP nya)
Untuk koneksi ke database lokal:
Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"
Contoh:
Buat dulu class module
Module konek
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Public nmjur, kdjur, hasilcek As String
Public Sub koneksi()
Try
Database.Close()
Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"
Database.Open()
MsgBox("koneksi berhasil")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Module
Coding di form:
Public Class Form1
Sub jurusan()
Call koneksi()
Tampil2.Connection = Database
Tampil2.CommandType = CommandType.Text
Tampil2.CommandText = " select * from jurusan where kdjur ='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil2.ExecuteReader
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kdjur")) Then
TextBox2.Text = "_"
Else
TextBox2.Text = Tampilkan("nmjur")
End If
End While
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call koneksi()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call jurusan()
End Sub
End Class
Hasilnya :
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Untuk konek database sever:
Database.connectionstring = "Provider = SQLOLEDB.1; Password=sandi; persist security
Info = True; User ID = SS; Initial Catalog = nmdatabase; Data Source = 192.168.10.44" ( Data source bisa nama komputer sever atau no IP nya)
Untuk koneksi ke database lokal:
Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"
Contoh:
Buat dulu class module
Module konek
Public Database As New OleDb.OleDbConnection
Public Tampil As New OleDb.OleDbCommand
Public Tampil2 As New OleDb.OleDbCommand
Public Tampilkan As OleDb.OleDbDataReader
Public nmjur, kdjur, hasilcek As String
Public Sub koneksi()
Try
Database.Close()
Database.ConnectionString = "Provider = SQLOLEDB.1; Integrated Security = SSPI; Persist Security Info= False; Initial Catalog = jurusan; Data Source = BATURADE-D8AD88\SQLEXPRESS;"
Database.Open()
MsgBox("koneksi berhasil")
Catch ex As Exception
MsgBox(ex.ToString())
End Try
End Sub
End Module
Coding di form:
Public Class Form1
Sub jurusan()
Call koneksi()
Tampil2.Connection = Database
Tampil2.CommandType = CommandType.Text
Tampil2.CommandText = " select * from jurusan where kdjur ='" & Trim(TextBox1.Text) & "'"
Tampilkan = Tampil2.ExecuteReader
If Tampilkan.HasRows = True Then
While Tampilkan.Read()
If IsDBNull(Tampilkan("kdjur")) Then
TextBox2.Text = "_"
Else
TextBox2.Text = Tampilkan("nmjur")
End If
End While
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call koneksi()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call jurusan()
End Sub
End Class
Hasilnya :
Selasa, 19 April 2011
Looping
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim j, u, y As Integer
u = 4
y = 7
For j = 1 To Val(TextBox1.Text)
If j Mod u = 0 Then
ListBox1.Items.Add(j)
u = j
Else
If j Mod y = 0 Then
ListBox1.Items.Add(j)
y = j
End If
End If
Next
End Sub
End Class
Kamis, 31 Maret 2011
input ke listview
Public Class Form1
Dim isitext(4) As String 'var Array
Dim mylisitem As ListViewItem
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isi_combo()
Call Set_Tampilan()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = "06 Teknik Informatika"
End Sub
Sub isi_combo()
ComboBox1.Items.Add("06 Teknik Informatika")
ComboBox1.Items.Add("07 Sistem Informasi")
ComboBox1.Items.Add("67. Komputer Akuntansi")
ComboBox1.Items.Add("05 Teknik Komputer")
ComboBox1.Items.Add("26 Manajemen Informatika")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Button1.Text = "Simpan"
Button2.Enabled = False 'INI
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
'membuat array
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text) 'UNTUK MENAMPILKAN SEMUA
isitext(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 2) 'mengambil 2 digit dari kiri dari kombobox
mylisitem = New ListViewItem(isitext) 'dipindahkan secara permanen
ListView1.Items.Add(mylisitem)
Call bersih()
TextBox1.Focus()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "keluar" Then
Me.Close() 'FUNGSI UNTUK KELUAR DALAM FORM SENDIRI
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Tambah"
Button1.Enabled = True 'INI
Button2.Text = "Ubah"
Button2.Enabled = True 'INI
Button3.Text = "Hapus"
Button3.Enabled = True 'INI
Button4.Text = "keluar"
Button4.Enabled = True 'INI
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "Ubah" Then
Button2.Text = "Simpan"
Button1.Enabled = False 'INi
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.Text = "Hapus" Then
Button3.Text = "Simpan"
Button1.Enabled = False 'INI
Button2.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Sub Set_Tampilan()
ListView1.View = View.Details 'membentuk tampilan menjadi macam2
'membuat kolom : ( nama kolom, lebar kolom, posisi tulisan)
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Jurusan", 100, HorizontalAlignment.Center)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox1.Text = e.Item.Text 'INI --> e
End Sub
End Class
Dim isitext(4) As String 'var Array
Dim mylisitem As ListViewItem
Private Sub Form1_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Call bersih()
Call isi_combo()
Call Set_Tampilan()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
ComboBox1.Text = "06 Teknik Informatika"
End Sub
Sub isi_combo()
ComboBox1.Items.Add("06 Teknik Informatika")
ComboBox1.Items.Add("07 Sistem Informasi")
ComboBox1.Items.Add("67. Komputer Akuntansi")
ComboBox1.Items.Add("05 Teknik Komputer")
ComboBox1.Items.Add("26 Manajemen Informatika")
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Button1.Text = "Tambah" Then
Button1.Text = "Simpan"
Button2.Enabled = False 'INI
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
'membuat array
isitext(0) = Trim(TextBox1.Text)
isitext(1) = Trim(TextBox2.Text)
isitext(2) = Trim(TextBox3.Text) 'UNTUK MENAMPILKAN SEMUA
isitext(3) = Microsoft.VisualBasic.Left(Trim(ComboBox1.Text), 2) 'mengambil 2 digit dari kiri dari kombobox
mylisitem = New ListViewItem(isitext) 'dipindahkan secara permanen
ListView1.Items.Add(mylisitem)
Call bersih()
TextBox1.Focus()
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
If Button4.Text = "keluar" Then
Me.Close() 'FUNGSI UNTUK KELUAR DALAM FORM SENDIRI
Else
Call bersih()
Call normal()
End If
End Sub
Sub normal()
Button1.Text = "Tambah"
Button1.Enabled = True 'INI
Button2.Text = "Ubah"
Button2.Enabled = True 'INI
Button3.Text = "Hapus"
Button3.Enabled = True 'INI
Button4.Text = "keluar"
Button4.Enabled = True 'INI
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
If Button2.Text = "Ubah" Then
Button2.Text = "Simpan"
Button1.Enabled = False 'INi
Button3.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If Button3.Text = "Hapus" Then
Button3.Text = "Simpan"
Button1.Enabled = False 'INI
Button2.Enabled = False 'INI
Button4.Text = "Batal"
TextBox1.Focus()
Else
End If
End Sub
Sub Set_Tampilan()
ListView1.View = View.Details 'membentuk tampilan menjadi macam2
'membuat kolom : ( nama kolom, lebar kolom, posisi tulisan)
ListView1.Columns.Add("NPM", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Nama", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Alamat", 100, HorizontalAlignment.Center)
ListView1.Columns.Add("Jurusan", 100, HorizontalAlignment.Center)
End Sub
Private Sub ListView1_ItemSelectionChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.ListViewItemSelectionChangedEventArgs) Handles ListView1.ItemSelectionChanged
TextBox1.Text = e.Item.Text 'INI --> e
End Sub
End Class
Input Data
List Programnya
Public Class Form1
Sub BERSIH()
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox3.Focus()
End Sub
Sub perintah()
Dim s As Integer
s = 6
If TextBox1.Text = "TI" Then
TextBox2.Text = "Teknik Informatika"
Else
If TextBox1.Text = "SI" Then
TextBox2.Text = "Sistem Informatika"
End If
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Call perintah()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
ListBox1.Items.Add(Trim(TextBox3.Text) + " " + Trim(TextBox4.Text) + " " + Trim(TextBox5.Text))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Call BERSIH()
End Sub
End Class
pengulangan
Operasi Perulangan
Operasi Perulangan dengan for....
contoh 1 . menampilkan bilangan genap
cuplikan program
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If i Mod 2 = 0 Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class
contoh 2 Menampilkan bilangan 4,7,8,14,16,28,32,56...
Listing programnya:
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, u, y As Integer
u = 4
y = 7
For i = 1 To Val(TextBox1.Text)
If i Mod u = 0 Then
ListBox1.Items.Add(i)
u = i
Else
If i Mod y = 0 Then
ListBox1.Items.Add(i)
y = i
End If
End If
Next
End Sub
End Class
Operasi Perulangan dengan for....
contoh 1 . menampilkan bilangan genap
cuplikan program
Public Class Form1
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If i Mod 2 = 0 Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class
contoh 2 Menampilkan bilangan 4,7,8,14,16,28,32,56...
Listing programnya:
Public Class Form2
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i, u, y As Integer
u = 4
y = 7
For i = 1 To Val(TextBox1.Text)
If i Mod u = 0 Then
ListBox1.Items.Add(i)
u = i
Else
If i Mod y = 0 Then
ListBox1.Items.Add(i)
y = i
End If
End If
Next
End Sub
End Class
Rabu, 30 Maret 2011
Mod
Mod 4 sisa 3
List Programnya
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If (i Mod 4 = 3) Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class
Bilangan yang jabis di bagi 7 dan 4
list Programnya
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim i As Integer
ListBox1.Items.Clear()
For i = 1 To Val(TextBox1.Text)
If (i Mod 7 = 0) And (i Mod 4 = 0) Then
ListBox1.Items.Add(i)
End If
Next
End Sub
End Class
Membuat tombol pindah
Listing programnya:
Public Class Form1
Dim vButton As System.Windows.Forms.Button
'buat variabel general utk menyimpan tombol yang invisible, misal vButton
'buat procedure aktif untuk memindah tulisan dan warna tombol ke lokasi yang kosong(tombol yang invisible)
Sub aktif(ByVal b As System.Windows.Forms.Button)
vButton.Visible = True
vButton.Text = b.Text
vButton.BackColor = b.BackColor
b.Visible = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click
Call aktif(sender)
vButton = sender
'panggil procedure aktif
'ganti variable vButton
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vButton = Button6
'setting awal tombol 6 di invisible
End Sub
End Class
cara lain yang lebih panjang tapi secara logika lebih mudah dimengerti:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'cara 1 masukkan kode ini di setiap tombol, dan ganti tombol yang visible dan invisible
'warna tolbol belum dimasukkan
'If Button2.Visible = False Then
' Button2.Visible = True
' Button2.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button3.Visible = False Then
' Button3.Visible = True
' Button3.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button4.Visible = False Then
' Button4.Visible = True
' Button4.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button5.Visible = False Then
' Button5.Visible = True
' Button5.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button6.Visible = False Then
' Button6.Visible = True
' Button6.Text = Button1.Text
' Button1.Visible = False
'End If
'===========================sampai sini cara panjang 1;
'cara 2
'===========================
Call aktif(Button1)
'panggil prosedur aktif, buat disemua tombol seperti ini
End Sub
'buat prosedure aktif
Sub aktif(ByVal b As System.Windows.Forms.Button)
If Button1.Visible = False Then
Button1.Visible = True
Button1.Text = b.Text
Button1.BackColor = b.BackColor
b.Visible = False
ElseIf Button2.Visible = False Then
Button2.Visible = True
Button2.Text = b.Text
Button2.BackColor = b.BackColor
b.Visible = False
ElseIf Button3.Visible = False Then
Button3.Visible = True
Button3.Text = b.Text
Button3.BackColor = b.BackColor
b.Visible = False
ElseIf Button4.Visible = False Then
Button4.Visible = True
Button4.Text = b.Text
Button4.BackColor = b.BackColor
b.Visible = False
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button5.Text = b.Text
Button5.BackColor = b.BackColor
b.Visible = False
ElseIf Button6.Visible = False Then
Button6.Visible = True
Button6.Text = b.Text
Button6.BackColor = b.BackColor
b.Visible = False
End If
End Sub
Public Class Form1
Dim vButton As System.Windows.Forms.Button
'buat variabel general utk menyimpan tombol yang invisible, misal vButton
'buat procedure aktif untuk memindah tulisan dan warna tombol ke lokasi yang kosong(tombol yang invisible)
Sub aktif(ByVal b As System.Windows.Forms.Button)
vButton.Visible = True
vButton.Text = b.Text
vButton.BackColor = b.BackColor
b.Visible = False
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click
Call aktif(sender)
vButton = sender
'panggil procedure aktif
'ganti variable vButton
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
vButton = Button6
'setting awal tombol 6 di invisible
End Sub
End Class
cara lain yang lebih panjang tapi secara logika lebih mudah dimengerti:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'cara 1 masukkan kode ini di setiap tombol, dan ganti tombol yang visible dan invisible
'warna tolbol belum dimasukkan
'If Button2.Visible = False Then
' Button2.Visible = True
' Button2.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button3.Visible = False Then
' Button3.Visible = True
' Button3.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button4.Visible = False Then
' Button4.Visible = True
' Button4.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button5.Visible = False Then
' Button5.Visible = True
' Button5.Text = Button1.Text
' Button1.Visible = False
'ElseIf Button6.Visible = False Then
' Button6.Visible = True
' Button6.Text = Button1.Text
' Button1.Visible = False
'End If
'===========================sampai sini cara panjang 1;
'cara 2
'===========================
Call aktif(Button1)
'panggil prosedur aktif, buat disemua tombol seperti ini
End Sub
'buat prosedure aktif
Sub aktif(ByVal b As System.Windows.Forms.Button)
If Button1.Visible = False Then
Button1.Visible = True
Button1.Text = b.Text
Button1.BackColor = b.BackColor
b.Visible = False
ElseIf Button2.Visible = False Then
Button2.Visible = True
Button2.Text = b.Text
Button2.BackColor = b.BackColor
b.Visible = False
ElseIf Button3.Visible = False Then
Button3.Visible = True
Button3.Text = b.Text
Button3.BackColor = b.BackColor
b.Visible = False
ElseIf Button4.Visible = False Then
Button4.Visible = True
Button4.Text = b.Text
Button4.BackColor = b.BackColor
b.Visible = False
ElseIf Button5.Visible = False Then
Button5.Visible = True
Button5.Text = b.Text
Button5.BackColor = b.BackColor
b.Visible = False
ElseIf Button6.Visible = False Then
Button6.Visible = True
Button6.Text = b.Text
Button6.BackColor = b.BackColor
b.Visible = False
End If
End Sub
Rabu, 09 Maret 2011
Visual Basic 2008
Variabel public : Variabel yang bisa digunakan kesemua program/ form (dalam satu project)
Variabel General : Variabel dimana variabel bisa digunakan/ dipanggil dalam satu class
Variabel Lokal : Variabel yang bisa dibaca/ dipanggil pada satu private/ satu sub/ satu procedure saja.
Setiap objek dalam pembuatan coding pasti diikuti dengan properties
contoh :
TextBox1.Text (Text dibelakang merupakan properties)
public class form1
Dim Jurusan as string (variabel general)
Dim Kelas, Jenjang as string, Waktu as string (variabel general)
Dim d as string (variabel konstanta)
private sub Button Click....
Dim lo as sring (variabel lokal)
lo=6
If TextBox1.Text="TI" Then
TextBox2.Text="Tehnik Informatika" + Trim(lo)
else
If TextBox1.Text="SI" Then
TextBox2.Text="Sistem Informatika"
end if
end if
end sub
untuk lebih mudah kita dapat menggunakan "call" karena perintah ini dapat dipakai pada beberapa sub.
sub perintah()
Dim lo as sring
private sub Button Click....
call perintah (perintah call)
end sub
call perintah (perintah call)
end sub
sub perintah()
Dim lo as sring
lo=6
If TextBox1.Text="TI" Then
TextBox2.Text="Tehnik Informatika" + Trim(lo)
else
If TextBox1.Text="SI" Then
TextBox2.Text="Sistem Informatika"
end if
end if
end sub
Membuat cursor berpindah aktif ke text berikutnya dengan tombol enter.
if e.key char = chr (13) Then
TextBox1.focus() (perintah focus untuk cursor aktif ke text berikutnya)
ListBox
Listbox1.Items.add(nilai yang dimasukkan)
contoh:
Listbox1.Items.add(TextBox1.text+""+Textbox2.text)
Combobox
Combobox.Items.add(Textbox1.text)
u=4
y=7
for j=4 To Val(Textbox2.text)
If j Mod u=0 Then
Listbox1.Items.add(j)
u=j
else
If j mod y=0 Then
Listbox1.Items.add(j)
y=j
end if
end if
hasilnya=4 7 8 14 16 28 32
end sub
Membuat cursor berpindah aktif ke text berikutnya dengan tombol enter.
if e.key char = chr (13) Then
TextBox1.focus() (perintah focus untuk cursor aktif ke text berikutnya)
ListBox
Listbox1.Items.add(nilai yang dimasukkan)
contoh:
Listbox1.Items.add(TextBox1.text+""+Textbox2.text)
Combobox
Combobox.Items.add(Textbox1.text)
Looping
Contoh:
Dim j,u,y as integeru=4
y=7
for j=4 To Val(Textbox2.text)
If j Mod u=0 Then
Listbox1.Items.add(j)
u=j
else
If j mod y=0 Then
Listbox1.Items.add(j)
y=j
end if
end if
hasilnya=4 7 8 14 16 28 32
Jumat, 18 Februari 2011
Langganan:
Postingan (Atom)