Membuat Aplikasi “Simple Calculator” dengan Visual Basic 6.0
Setelah pada posting-posting sebelumnya saya menggunakan huruf sebagai masukan dan hasilnya maka pada postingan ini saya menggunakan angka dalam memproses prosedur aritmatika. Walaupun tergolong sederhana akan tetapi saya berharap dapat memberikan tambahan logika pemrograman untuk teman-teman dan pada postingan saya yang selanjutnya saya akan mengadaptasikan pembuatan aplikasi ini pada Visual Basic.NET.
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 | Simple Calculator | ||
Start Up Position | 2 - Center Screen | ||
Label | lblFirst | Caption | First Number : |
Font | Tahoma; 10pt | ||
Text Box | txtFirst | Alignment | 1 – Right Justify |
Font | Tahoma; 12pt | ||
Label | lblSecond | Caption | Second Number : |
Font | Tahoma; 10pt | ||
Text Box | txtSecond | Alignment | 1 – Right Justify |
Font | Tahoma; 12pt | ||
Command Button | cmdAdd | Caption | Add |
Enabled | False | ||
Font | Tahoma; 10pt | ||
Command Button | cmdSubtract | Caption | Subtract |
Enabled | False | ||
Font | Tahoma; 10pt | ||
Command Button | cmdMultiple | Caption | Multiple |
Enabled | False | ||
Font | Tahoma; 10pt | ||
Command Button | cmdDevide | Caption | Divide |
Enabled | False | ||
Font | Tahoma; 10pt | ||
Label | lblResult | Caption | Result : |
Font | Tahoma; 10pt | ||
Text Box | txtResult | Alignment | 1 – Right Justify |
Enabled | False | ||
Font | Tahoma; 12pt | ||
Command Button | cmdClear | Caption | Clear |
Enabled | False | ||
Font | Tahoma; 10pt | ||
Command Button | cmdExit | Caption | Exit |
Font | Tahoma; 10pt |
4. Berikut event code program
Private Sub cmdAdd_Click()
txtResult.Text = Val(txtFirst.Text) + Val(txtSecond.Text)
End Sub
Private Sub cmdClear_Click()
txtFirst.Text = ""
txtSecond.Text = ""
txtResult.Text = ""
cmdClear.Enabled = False
txtFirst.SetFocus
End Sub
Private Sub cmdDevide_Click()
txtResult.Text = Val(txtFirst.Text) / Val(txtSecond.Text)
End Sub
Private Sub cmdExit_Click()
End
End Sub
Private Sub cmdMultiple_Click()
txtResult.Text = Val(txtFirst.Text) * Val(txtSecond.Text)
End Sub
Private Sub cmdSubtract_Click()
txtResult.Text = Val(txtFirst.Text) - Val(txtSecond.Text)
End Sub
Private Sub txtFirst_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If
End Sub
Private Sub txtResult_Change()
cmdClear.Enabled = True
End Sub
Private Sub txtSecond_Change()
cmdAdd.Enabled = True
cmdSubtract.Enabled = True
cmdMultiple.Enabled = True
cmdDevide.Enabled = True
If txtSecond.Text = "" Then
cmdAdd.Enabled = False
cmdSubtract.Enabled = False
cmdMultiple.Enabled = False
cmdDevide.Enabled = False
End If
End Sub
Private Sub txtSecond_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
SendKeys "{tab}"
KeyAscii = 0
End If
If Not (KeyAscii >= Asc("0") And KeyAscii <= Asc("9") Or KeyAscii = vbKeyBack) Then
KeyAscii = 0
End If
End Sub
Label: VB6
0 Komentar:
Posting Komentar
Berlangganan Posting Komentar [Atom]
<< Beranda