Membuat Program Perhitungan Sederhana Dengan Visual Basic
Kali ini saya coba membuat program perhitungan sederhana dengan program visual basic 6.0. Pertama - tama buat form seperti gambar dibawah
Kalo sudah memasukkan kode scriptnya yang ada di bawah ini
Private Sub Command1_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Command2_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) - Val(Text2.Text)
End Sub
Private Sub Command3_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) * Val(Text2.Text)
End Sub
Private Sub Command4_Click()
If Val(Text2.Text) = 0 Then
MsgBox "Angka Kedua Jangan bernilai nol", vbCritical, ""
Text2.SetFocus
Else
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) / Val(Text2.Text)
End If
End Sub
Private Sub Command5_Click()
Text1.Text = ""
Text2.Text = ""
Label4.Caption = ""
Label5.Caption = ""
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Text1.Enabled = True
Text2.Enabled = False
Text1.SetFocus
End Sub
Private Sub Command6_Click()
Dim x As Variant
Dim Pesan As String
Pesan = "Kalkulator Sederhana Versi " & App.Major & "." & App.Minor & "." & App.Revision & Chr(13) & Chr(13)
Pesan = Pesan & "Made In Dewek" & vbCrLf
Pesan = Pesan & "Email: afiyandevorawali@gmail.com " & Chr(13)
Pesan = Pesan & "website: http://afiyandevorawali.blogspot.com" & Chr(13)
Pesan = Pesan & " " & Chr(13) & Chr(13)
Pesan = Pesan & "created by : Afiyan Devo Rawali" & Chr(13)
Pesan = Pesan & "--------------------------------------------------" & Chr(13)
Pesan = Pesan & "Ayo belajar Visual Basic" & Chr(13)
x = MsgBox(Pesan, vbInformation, "Kalkulator Sederhana")
Text1.SetFocus
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Form_Load()
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Text2.Enabled = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr(KeyAscii)) = 0 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
'd = MsgBox("Maaf, Nilai yang Dimasukkan Harus Angka.", vbCritical, "Peringatan")
End If
End If
Text2.Enabled = True
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr(KeyAscii)) = 0 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
d = MsgBox("Maaf, Nilai yang Dimasukkan Harus Angka.", vbCritical, "Peringatan")
End If
End If
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
End Sub
Silahkan di Run
Kalo sudah memasukkan kode scriptnya yang ada di bawah ini
Private Sub Command1_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) + Val(Text2.Text)
End Sub
Private Sub Command2_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) - Val(Text2.Text)
End Sub
Private Sub Command3_Click()
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) * Val(Text2.Text)
End Sub
Private Sub Command4_Click()
If Val(Text2.Text) = 0 Then
MsgBox "Angka Kedua Jangan bernilai nol", vbCritical, ""
Text2.SetFocus
Else
Text1.Enabled = False
Text2.Enabled = False
Label4.Caption = "Hasilnya :"
Label5.Caption = Val(Text1.Text) / Val(Text2.Text)
End If
End Sub
Private Sub Command5_Click()
Text1.Text = ""
Text2.Text = ""
Label4.Caption = ""
Label5.Caption = ""
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Text1.Enabled = True
Text2.Enabled = False
Text1.SetFocus
End Sub
Private Sub Command6_Click()
Dim x As Variant
Dim Pesan As String
Pesan = "Kalkulator Sederhana Versi " & App.Major & "." & App.Minor & "." & App.Revision & Chr(13) & Chr(13)
Pesan = Pesan & "Made In Dewek" & vbCrLf
Pesan = Pesan & "Email: afiyandevorawali@gmail.com " & Chr(13)
Pesan = Pesan & "website: http://afiyandevorawali.blogspot.com" & Chr(13)
Pesan = Pesan & " " & Chr(13) & Chr(13)
Pesan = Pesan & "created by : Afiyan Devo Rawali" & Chr(13)
Pesan = Pesan & "--------------------------------------------------" & Chr(13)
Pesan = Pesan & "Ayo belajar Visual Basic" & Chr(13)
x = MsgBox(Pesan, vbInformation, "Kalkulator Sederhana")
Text1.SetFocus
End Sub
Private Sub Command7_Click()
End
End Sub
Private Sub Form_Load()
Command1.Enabled = False
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
Command5.Enabled = False
Text2.Enabled = False
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr(KeyAscii)) = 0 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
'd = MsgBox("Maaf, Nilai yang Dimasukkan Harus Angka.", vbCritical, "Peringatan")
End If
End If
Text2.Enabled = True
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
If InStr("0123456789.", Chr(KeyAscii)) = 0 Then
If KeyAscii <> vbKeyBack Then
KeyAscii = 0
d = MsgBox("Maaf, Nilai yang Dimasukkan Harus Angka.", vbCritical, "Peringatan")
End If
End If
Command1.Enabled = True
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
Command5.Enabled = True
End Sub
Silahkan di Run
boleh2 .. gewe Test ya OM ..
BalasHapus