“Type of Numbers” dengan Visual Basic 6.0
Selagi surfing di internet saya menemukan soal latihan untuk membedakan bilangan ganjil dan genap berdasarkan masukan pengguna. Saya coba membuatnya dan gambar di samping sebagai jawabannya. Setelah mencari info melalui wikipedia saya improfisasi dengan tambahkan bilangan asli, cacah dan bulat. Saya belum mencobanya secara mendetil. Dan bila teman-teman sudah mencobanya dan menemukan kesalahan. Jangan sungkan-sungkan beritahu saya. Karena itu bisa membantu mensuport saya untuk melanjutkan blog ini. Trims.
1. Jalankan aplikasi Visual Basic 6.0
2. Pada jendela “New Project” pilih “Standard EXE” kemudian tekan tombol “Open”
3. Berikut setingan kontrol properti yang terdapat pada aplikasi ini
Object | Name | Properties | Setting |
Form | Form1 | Border Style | 1 - Fixed Single |
Caption | Type of Numbers | ||
Font | Tahoma; 10pt | ||
Start Up Position | 2 - Center Screen | ||
Label | Label1 | Caption | Number: |
Text Box | Text1 | Alignment | 1 – Right Justify |
Font | Tahoma; 14pt | ||
Command Button | Command1 | Caption | Analyze |
Enable | False | ||
Image | Image1 | Stretch | True |
Label | Label5 | Caption | Natural numbers |
Image | Image2 | Stretch | True |
Label | Label6 | Caption | Integer |
Image | Image3 | Stretch | True |
Label | Label2 | Caption | Even number |
Image | Image4 | Stretch | True |
Label | Label3 | Caption | Odd number |
Command Button | Command2 | Caption | Clear |
4. Berikut event program aplikasi ini:
Private Sub Command1_Click()
If Text1.Text = Text1.Text Then Image2.Picture = LoadPicture(App.Path & "\Images\1.jpg")
If CDbl(Text1.Text) >= 0 Then
Image1.Picture = LoadPicture(App.Path & "\Images\1.jpg")
Else
Image1.Picture = LoadPicture(App.Path & "\Images\0.jpg")
End If
If Val(Text1.Text) Mod 2 = 0 Then
Image3.Picture = LoadPicture(App.Path & "\Images\1.jpg")
Else
Image3.Picture = LoadPicture(App.Path & "\Images\0.jpg")
End If
If Val(Text1.Text) Mod 2 Then
Image4.Picture = LoadPicture(App.Path & "\Images\1.jpg")
Else
Image4.Picture = LoadPicture(App.Path & "\Images\0.jpg")
End If
Command2.SetFocus
End Sub
Private Sub Command2_Click()
Text1.Text = ""
Image1.Picture = Nothing
Image2.Picture = Nothing
Image3.Picture = Nothing
Image4.Picture = Nothing
Text1.SetFocus
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("Exit the aplication?", vbYesNo + vbQuestion, "Confirmation") = vbNo Then
Cancel = 1
End If
End Sub
Private Sub Text1_Change()
Command1.Enabled = True
Command2.Enabled = True
If Text1.Text = "" Then
Command1.Enabled = False
Command2.Enabled = False
End If
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii >= vbKey0 And KeyAscii <= vbKey9 Or KeyAscii = 45 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyReturn) Then
KeyAscii = 0
ElseIf KeyAscii = vbKeyReturn Then
Command1_Click
End If
End Sub
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda