Minggu, 30 Januari 2011

Cara membuat aplikasi kalkulator sederhana pada vb


                Langkah awal:
1.       Buka project vb
2.       Tambahkan label1 dan dan text1,agar masukan tulisan text1 hanya angka saja dan menggunakan tombol enter untuk memindah pointer ,masukan program dibawah ini:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Text1.Text = "" Then
    Text1.SetFocus
    Else
    Text2.SetFocus
    End If
ElseIf Not (KeyAscii >= Asc("0") & Chr(13) And KeyAscii <= Asc("9") & Chr(13) Or KeyAscii = 13 Or KeyAscii = vbKeyBack Or KeyAscii = vbkyedelete Or KeyAscii = (13)) Then
KeyAscii = 0
MsgBox "maaf khusus angka saja"
End If
End Sub
















3.       Tambahkan label2 dan text2,agar pada text2 juga hanya boleh angka saja,,masukan program
Di bawah ini:
Private Sub Text2_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
    If Text1.Text = "" Then
    Else
    Combo1.SetFocus
    End If
ElseIf Not (KeyAscii >= Asc("0") & Chr(13) And KeyAscii <= Asc("9") & Chr(13) Or KeyAscii = 13 Or KeyAscii = vbKeyBack Or KeyAscii = vbKeyDelete Or KeyAscii = (13)) Then
KeyAscii = 0
MsgBox "maaf khusus angka saja"
End If
End Sub

 

























4.       Tambahkan label3 dan commboBox,,pada commbox listnya harus diisi(tambah,kurang,kali,bagi)dan pada comboBox masukan program dibawah ini:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If 
End Sub


















5.       Tambahkan command1 dan command2,pada command1 masukan program dibawah ini:
Private Sub Combo1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command1.SetFocus
End If
End Sub
Private Sub Command1_Click()
If Combo1.Text = "tambah" Then
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
ElseIf Combo1.Text = "kurang" Then
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
ElseIf Combo1.Text = "kali" Then
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
ElseIf Combo1.Text = "bagi" Then
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
Else
MsgBox "maaf anda harus memilih jenis penghitungan terlebih dahulu", vbCritical, "critical"
End If
End Sub

Private Sub Command1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
Command2.SetFocus
End If
End Sub

Pada command2 masukan program di bawah ini:
Private Sub Command2_Click()
MsgBox " terima kasih telah menggunakan program ini", vbInformation, "exit"
End
End Sub
 













Terima kasih selamat mencoba "semoga bermanfaat"



jika anda ingin mengdownload file diatas klik disini


1 komentar:

WISATAACEH mengatakan...

terima kasih atas materinya

Posting Komentar