Google

Sabtu, 07 Juni 2008

Membuat Aplikasi Dasar VB Penjumlahan

Setelah membaca posting saya terdahulu.mari kita mulai dengan aplikasi dasar penjumlahan.
1. Jalankan visual basic6
2. (Pilih) file-new project-(pilih) standard.exe
3. Click and drag pada form1,ambil textbox sebanyak 3 textbox,berturut-turut 1 command button 1 line, 1 label.
4. click pada masing masing control(text1 dst) dan ganti properties name dari :text1 =>txt1, text2=>txt2, text3=>txt3 (ket: => menjadi)
ganti properties name commandbutton menjadi cmdj.
5. Atur sesuai gambar.



6. Copy paste kan code dibawah ini .

Private Sub cmdj_Click()
on error goto salah 'ini adalah code perangkap kesalahan

Dim j1 As Integer
Dim j2 As Integer
Dim j3 As Integer
Dim j4 As Integer

j1 = txt1
j2 = txt2
j4 = txt3

j3 = j1 + j2

If j4 = j3 Then
MsgBox "Jawaban Benar Jose", vbOKCancel, "HEBAT"

Else
MsgBox "Jawaban Salah Jose", vbOKCancel, "ERROR"
txt3 = ""
End If

txt3.SetFocus

exit sub
salah: msgbox err.description

End Sub

Private Sub txt1_KeyPress(KeyAscii As Integer)

If KeyAscii = 13 Then 'ini adalah kode berpindah ke control berikut apabila tombol "enter " 'ditekan(seperti text box,command
' button yg memiliki properties tabstop=true)
txt2.SetFocus
End If

End Sub

Private Sub txt2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
txt3.SetFocus
End If
End Sub


7. Tekan F5 untuk menjalankan program. (run - start)
8. Selamat mencoba semoga bermanfaat.

Tidak ada komentar: