Minggu, 28 September 2014

Contoh Penerapan “Properti ListBox” dengan Visual Basic 6.0

VB6SP6_logo

Contoh sederhana implementasi Properti ListBox pada Visual Basic 6.0.

Seperti menambahkan data ke dalam daftar ListBox, menghitung banyaknya data yang terdapat pada daftar ListBox, merubah nama data yang dipilih, menghapus data yang dipilih, dan membersihkan semua daftar pada ListBox. Dengan menggunakan kontrol Text Box, Label, Button, dan ListBox untuk mengimplementasikan perintah kejadian pada program.

ListBoxPropertiesVB6

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form frmListProperties
BorderStyle = 1 'Fixed Single
Caption = "List Properties"
ClientHeight = 5535
ClientLeft = 45
ClientTop = 435
ClientWidth = 7215
BeginProperty Font
Name = "Segoe UI"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form14"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 5535
ScaleWidth = 7215
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 19
Top = 5160
Visible = 0 'False
Width = 7215
_ExtentX = 12726
_ExtentY = 661
_Version = 393216
BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628}
NumPanels = 1
BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628}
EndProperty
EndProperty
End
Begin VB.Frame Frame1
Caption = "Keterangan Item:"
Height = 4455
Left = 4440
TabIndex = 8
Top = 120
Width = 2535
Begin VB.CommandButton Command1
Caption = "Batal"
Enabled = 0 'False
Height = 495
Index = 6
Left = 240
TabIndex = 14
Top = 3240
Width = 2055
End
Begin VB.CommandButton Command1
Caption = "Simpan"
Enabled = 0 'False
Height = 495
Index = 5
Left = 240
TabIndex = 13
Top = 2520
Width = 2055
End
Begin VB.TextBox Text1
BackColor = &H8000000F&
Enabled = 0 'False
Height = 405
Index = 1
Left = 240
TabIndex = 12
Top = 1605
Width = 2055
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "0 Karakter 0 spasi"
Height = 255
Index = 6
Left = 240
TabIndex = 17
Top = 2030
Width = 2055
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "0 Karakter"
Height = 255
Index = 5
Left = 240
TabIndex = 16
Top = 1050
Width = 2055
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Sesudah:"
Height = 225
Index = 3
Left = 240
TabIndex = 11
Top = 1320
Width = 705
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Sebelum:"
Height = 225
Index = 1
Left = 240
TabIndex = 10
Top = 360
Width = 735
End
Begin VB.Label Label1
BorderStyle = 1 'Fixed Single
Enabled = 0 'False
Height = 375
Index = 2
Left = 240
TabIndex = 9
Top = 640
Width = 2055
End
End
Begin VB.CommandButton Command1
Caption = "Bersihkan Daftar"
Enabled = 0 'False
Height = 495
Index = 3
Left = 240
TabIndex = 7
Top = 4080
Width = 3975
End
Begin VB.CommandButton Command1
Caption = "Edit Item"
Enabled = 0 'False
Height = 495
Index = 1
Left = 240
TabIndex = 6
Top = 3480
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "Hapus Item"
Enabled = 0 'False
Height = 495
Index = 2
Left = 2280
TabIndex = 5
Top = 3480
Width = 1935
End
Begin VB.CommandButton Command1
Caption = "Keluar"
Height = 495
Index = 4
Left = 240
TabIndex = 4
Top = 4800
Width = 6735
End
Begin VB.ListBox List1
Height = 1410
Left = 240
TabIndex = 3
Top = 1680
Width = 3975
End
Begin VB.CommandButton Command1
Caption = "Salin"
Enabled = 0 'False
Height = 495
Index = 0
Left = 240
TabIndex = 2
Top = 1080
Width = 3975
End
Begin VB.TextBox Text1
Height = 375
Index = 0
Left = 2160
TabIndex = 0
Top = 240
Width = 2055
End
Begin VB.Label Label1
Alignment = 2 'Center
Caption = "0 item"
Height = 255
Index = 7
Left = 240
TabIndex = 18
Top = 3195
Width = 3975
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "0 Karakter 0 spasi"
Height = 255
Index = 4
Left = 2160
TabIndex = 15
Top = 675
Width = 1935
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Tuliskan nama Anda :"
Height = 225
Index = 0
Left = 240
TabIndex = 1
Top = 300
Width = 1710
End
End
Attribute VB_Name = "frmListProperties"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i%
Dim PosisiKarakter As Long
Dim InputKarakter As String
Dim InputSpasi As Integer

Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
With Text1(0)
List1.AddItem .Text
.Text = Empty
.SetFocus
End With

For i = 1 To 3
Command1(i).Enabled = True
Next

Banyak_Item
Case 1:
If List1.Text = Empty Then
Tampilkan_Pesan
Command1(1).SetFocus
Else
Disable_Button
With Label1(2)
.Enabled = True
.BackColor = SystemColorConstants. _
vbWindowBackground
.Caption = List1.Text
End With

With Text1(1)
.Enabled = True
.BackColor = SystemColorConstants. _
vbWindowBackground
.SetFocus
End With
Command1(6).Enabled = True
End If
Case 2:
If List1.Text = Empty Then
Tampilkan_Pesan
Command1(2).SetFocus
Else
List1.RemoveItem List1.ListIndex
If List1.ListCount = Empty Then
Disable_Button
End If
Banyak_Item
Text1(0).SetFocus
End If
Case 3:
List1.Clear
Banyak_Item
Text1(0).SetFocus
Disable_Button
Case 4:
Dim Respon

Respon = MsgBox("Keluar program", _
vbQuestion + vbYesNo, _
"Perhatian")
If Respon = vbYes Then
End
Else
Text1(0).SetFocus
End If
Case 5:
List1.List(List1.ListIndex) = Text1(1).Text
Command1_Click (6)
Case 6:
With Label1(2)
.Caption = Empty
.Enabled = False
.BackColor = SystemColorConstants. _
vbButtonFace
End With

With Text1(1)
.Text = Empty
.Enabled = False
.BackColor = SystemColorConstants. _
vbButtonFace
End With

Command1(6).Enabled = False

For i = 1 To 3
Command1(i).Enabled = True
Next
End Select
End Sub


Private Sub Disable_Button()
For i = 1 To 3
Command1(i).Enabled = False
Next
End Sub

Private Sub Label1_Change(Index As Integer)
PosisiKarakter = 1
InputSpasi = 0
InputKarakter = Label1(2).Caption
If InputKarakter = Empty Then
Label1(5).Caption = "0 karakter"
ElseIf Len(InputKarakter) > 0 Then
Do While PosisiKarakter > 0
PosisiKarakter = InStr(PosisiKarakter, InputKarakter, " ")
If PosisiKarakter > 0 Then
While Mid(InputKarakter, PosisiKarakter, 1) = " "
PosisiKarakter = PosisiKarakter + 1
InputSpasi = InputSpasi + 1
Wend
End If
Loop
Label1(5).Caption = Len(Label1(2).Caption) - InputSpasi & " karakter"
End If
End Sub

Private Sub Tampilkan_Pesan()
MsgBox "Tidak ada data yang dipilih..." & vbCrLf _
& vbCrLf & "Harap pilih data yang " _
& "terdapat pada daftar diatas" & vbCrLf _
& "kemudian coba kembali perintah ini.", _
vbExclamation, "Perhatian"
End Sub


Private Sub Text1_Change(Index As Integer)
Select Case Index
Case 0:
If Text1(Index).Text = Empty Then
Command1(0).Enabled = False
Else
Command1(0).Enabled = True
End If

PosisiKarakter = 1
InputSpasi = 0
InputKarakter = Text1(Index).Text
If InputKarakter = Empty Then
Label1(4).Caption = "0 karakter 0 spasi"
ElseIf Len(InputKarakter) > 0 Then
Do While PosisiKarakter > 0
PosisiKarakter = InStr(PosisiKarakter, InputKarakter, " ")
If PosisiKarakter > 0 Then
While Mid(InputKarakter, PosisiKarakter, 1) = " "
PosisiKarakter = PosisiKarakter + 1
InputSpasi = InputSpasi + 1
Wend
End If
Loop
Label1(4).Caption = Len(Text1(Index).Text) - InputSpasi _
& " karakter " & InputSpasi & " Spasi"
End If
Case 1:
If Text1(Index).Text = Empty Then
Command1(5).Enabled = False
Else
Command1(5).Enabled = True
End If

PosisiKarakter = 1
InputSpasi = 0
InputKarakter = Text1(Index).Text
If InputKarakter = Empty Then
Label1(6).Caption = "0 Karakter 0 spasi"
ElseIf Len(InputKarakter) > 0 Then
Do While PosisiKarakter > 0
PosisiKarakter = InStr(PosisiKarakter, InputKarakter, " ")
If PosisiKarakter > 0 Then
While Mid(InputKarakter, PosisiKarakter, 1) = " "
PosisiKarakter = PosisiKarakter + 1
InputSpasi = InputSpasi + 1
Wend
End If
Loop
Label1(6).Caption = Len(Text1(Index).Text) - InputSpasi _
& " karakter " & InputSpasi & " Spasi"
End If
End Select
End Sub

Private Sub Text1_KeyPress(Index As Integer, KeyAscii As Integer)
If (KeyAscii >= Asc("0") And KeyAscii <= Asc("9")) Then
Beep
KeyAscii = 0
End If

Select Case Index
Case 0:
If (KeyAscii = 13) Then
Command1_Click (0)
End If
Case 1:
If (KeyAscii = 13) Then
Command1_Click (5)
End If
End Select
End Sub

Private Sub Banyak_Item()
Label1(7).Caption = List1.ListCount & " item"
End Sub


Unduh Kode Sumber

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda