Selasa, 30 September 2014

“Latihan Visual Basic 1” dengan Visual Basic 6.0

VB6SP6_logo

Modifikasi soal dan jawaban “Latihan Visual Basic 1” yang terdapat pada blog Steven Tandiono.

Tidak banyak modifikasi yang dibuat. Hanya sekedar menambahkan beberapa fungsi tambahan seperti bila pada sumber, soal dan jawaban terdiri dari dua project disini saya gabungkan menjadi satu buah project dan lain sebagainya. Untuk lebih lengkapnya dapat dilihat pada kode sumber yang disertakan.

 

Soal 1: Bilangan Ganjil dan Genap

LatihanVB_JenisBilangan

Soal 2: Lulus dan Gagal (Kriteria: >= 70 “Lulus” ; > 70 “Gagal”)

LatihanVB_HasilKelulusan 

VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.1#0"; "MSCOMCTL.OCX"
Begin VB.Form Form1
BorderStyle = 1 'Fixed Single
Caption = "Latihan Visual Basic 1"
ClientHeight = 3495
ClientLeft = 45
ClientTop = 435
ClientWidth = 3855
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 = 3495
ScaleWidth = 3855
StartUpPosition = 2 'CenterScreen
Begin MSComctlLib.StatusBar StatusBar1
Align = 2 'Align Bottom
Height = 375
Left = 0
TabIndex = 8
Top = 3120
Visible = 0 'False
Width = 3855
_ExtentX = 6800
_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
Height = 345
Left = 240
Style = 2 'Dropdown List
TabIndex = 1
Top = 120
Width = 3375
End
Begin VB.CommandButton Command1
Caption = "Keluar"
Height = 495
Index = 2
Left = 240
TabIndex = 5
Top = 2760
Width = 3375
End
Begin VB.CommandButton Command1
Caption = "Baru"
Height = 495
Index = 1
Left = 2040
TabIndex = 4
Top = 2040
Width = 1575
End
Begin VB.CommandButton Command1
Caption = "Proses"
BeginProperty Font
Name = "Segoe UI"
Size = 9
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 495
Index = 0
Left = 240
TabIndex = 3
Top = 2040
Width = 1575
End
Begin VB.TextBox Text1
Alignment = 2 'Center
BeginProperty Font
Name = "Segoe UI"
Size = 9.75
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Index = 1
Left = 1920
Locked = -1 'True
TabIndex = 2
Top = 1320
Width = 1695
End
Begin VB.TextBox Text1
Alignment = 1 'Right Justify
BeginProperty Font
Name = "Tahoma"
Size = 9
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 435
Index = 0
Left = 1920
TabIndex = 0
Top = 660
Width = 1695
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Jenis Bilangan:"
BeginProperty Font
Name = "Segoe UI"
Size = 9.75
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 255
Index = 1
Left = 240
TabIndex = 7
Top = 1395
Width = 1260
End
Begin VB.Label Label1
AutoSize = -1 'True
Caption = "Masukan Bilangan:"
Height = 225
Index = 0
Left = 240
TabIndex = 6
Top = 720
Width = 1500
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim i%

Private Sub Combo1_Click()
If Combo1.ListIndex = 0 Then
Label1(Index).Caption = "Masukan Bilangan:"
Label1(1).Caption = "Jenis Bilangan:"
Text1(0).MaxLength = 0
Clear_Text
Else
Label1(Index).Caption = "Masukan Nilai:"
Label1(1).Caption = "Keterangan:"
Text1(0).MaxLength = 3
Clear_Text
Text1(Index).SetFocus
End If
End Sub

Private Sub Clear_Text()
For i = 0 To 1
Text1(i).Text = Empty
Next
End Sub

Private Sub Command1_Click(Index As Integer)
Select Case Index
Case 0:
With Text1(1)
If Combo1.ListIndex = Index Then
If Val(Text1(Index).Text) Mod 2 = 0 Then
.Text = UCase$("genap")
Else
.Text = UCase$("ganjil")
End If
Else
If Val(Text1(Index).Text) >= 70 Then
.Text = UCase$("lulus")
Else
.Text = UCase$("gagal")
End If
End If
Command1(1).SetFocus
If Combo1.ListIndex = 0 Then
If Text1(Index).Text = Empty Then
MsgBox "Tidak ada bilangan yang dimasukan !", _
vbExclamation, "Perhatian"
Command1_Click (1)
End If
Else
If Text1(Index).Text = Empty Then
MsgBox "Tidak ada nilai yang dimasukan !", _
vbExclamation, "Perhatian"
Command1_Click (1)
End If

If Val(Text1(Index).Text) > 100 Then
MsgBox "Input nilai salah !" & vbCrLf & vbCrLf & _
"Input maksimum bernilai 100", _
vbExclamation, "Perhatian"
Command1_Click (1)
End If
End If
End With
Case 1:
For i = 0 To 1
Text1(i).Text = Empty
Next
Text1(0).SetFocus
Case 2:
Dim Respon
Respon = MsgBox("Keluar program ?", _
vbQuestion + vbYesNo, _
"Perhatian")
If Respon = vbYes Then
End
Else
Text1(0).SetFocus
End If
End Select
End Sub

Private Sub Form_Load()
With Combo1
.AddItem "Jenis Bilangan"
.AddItem "Hasil Kelulusan"
.ListIndex = 0
End With
End Sub

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

If (KeyAscii = 13) Then
Command1_Click (0)
End If
End Sub



Unduh Kode Sumber

Label:

0 Komentar:

Posting Komentar

Berlangganan Posting Komentar [Atom]

<< Beranda