“Menghitung Umur” dengan Visual Basic 6.0
Latihan “Menghitung Umur” yang terdapat pada eBook “Panduan Praktik Pemrograman Komputer”.
Tidak banyak modifikasi yang dibuat. Hanya sekedar menambahkan fitur tombol “Baru”. Untuk lebih lengkapnya dapat dilihat pada kode sumber yang disertakan.
VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Menghitung Umur"
ClientHeight = 3750
ClientLeft = 45
ClientTop = 405
ClientWidth = 4110
BeginProperty Font
Name = "Segoe UI"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
LinkTopic = "Form1"
LockControls = -1 'True
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 3750
ScaleWidth = 4110
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.StatusBar StatusBar
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 9
Top = 3375
Visible = 0 'False
Width = 4110
_ExtentX = 7250
_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.ComboBox Combo1
BeginProperty Font
Name = "Segoe UI"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 1320
Style = 2 'Dropdown List
TabIndex = 8
Top = 720
Width = 2535
End
Begin VB.CommandButton Command1
Caption = "Keluar"
Height = 495
Index = 1
Left = 2280
TabIndex = 7
Top = 3120
Width = 1575
End
Begin VB.TextBox Text1
Alignment = 2 'Center
BeginProperty Font
Name = "Segoe UI"
Size = 12
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 1320
Locked = -1 'True
TabIndex = 5
Top = 2160
Width = 1695
End
Begin VB.CommandButton Command1
Caption = "Hitung"
Height = 495
Index = 0
Left = 240
TabIndex = 3
Top = 1320
Width = 3615
End
Begin VB.TextBox Text1
BeginProperty Font
Name = "Segoe UI"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 0
Left = 1320
TabIndex = 1
Top = 180
Width = 2535
End
Begin VB.Line Line1
Index = 0
X1 = 240
X2 = 3840
Y1 = 3000
Y2 = 3000
End
Begin VB.Line Line1
BorderColor = &H00FFFFFF&
BorderWidth = 4
Index = 1
X1 = 240
X2 = 3840
Y1 = 3000
Y2 = 3000
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Tahun"
Height = 225
Index = 3
Left = 3120
TabIndex = 6
Top = 2205
Width = 510
End
Begin VB.Label Label1
Alignment = 1 'Right Justify
Caption = "Tahun ini anda berusia:"
Height = 705
Index = 2
Left = 240
TabIndex = 4
Top = 2040
Width = 1005
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Tahun Lahir:"
Height = 225
Index = 1
Left = 240
TabIndex = 2
Top = 795
Width = 990
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Nama:"
Height = 225
Index = 0
Left = 720
TabIndex = 0
Top = 240
Width = 525
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Sub Combo1_Click()
Command1_Click (0)
End Sub
Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
If Command1(Index).Caption = "Hitung" Then
If Combo1.Text = Empty Then
MsgBox "Anda belum memilih Tahun Kelahiran...!", _
vbExclamation, "Perhatian"
Combo1.SetFocus
Exit Sub
Else
Dim Tahun_Sekarang
Tahun_Sekarang = Format(Date, "yyyy")
Text1(1).Text = Tahun_Sekarang - Val(Combo1.Text)
End If
Command1(Index).Caption = "Baru"
Else
For i = 0 To 1
Text1(i).Text = Empty
Next
Combo1.Clear
Command1(Index).Caption = "Hitung"
Form_Load
Text1(Index).SetFocus
End If
Case 1:
Unload Me
End Select
End Sub
Private Sub Form_Load()
Dim i%
For i = 1910 To 2020
Combo1.AddItem i
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Keluar program ?", vbQuestion + vbYesNo, "Perhatian") = vbNo Then
Cancel = 1
End If
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
End Sub
Unduh Kode Sumber
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda