Salam belajar teman-teman,, nah apa salahnya kalau kita saling berbagi pengetahuan, saya akan memberikan sedikit pengetahuan yg bisa sy berikan, nah gambar d bawah ini merupakan hasil dari tugas kampus sya yang di berikan oleh dosen, untuk membuat aplikasi kalkulator sederhana dengan menggunakan bahasa pemrogrman Visual Basic 6.0 . bagi teman-teman yang ingin belajar lebih dalam, saya sarankan, kalau bisa fokuslah, satu bahasa pemrograman yang teman-teman sukai.
Private
cetak As Double
Private
nilaibaru As Boolean
Private
operator As Integer
Private
Const opNol = 0
Private
Const optambah = 1
Private
Const opkurang = 2
Private
Const opbagi = 3
Private
Const opkali = 4
Private
Const opsqrt = 5
Private
Const oppers = 6
Private
Const opsper = 7
Private
Sub command11_click()
If
nilaibaru Then
Text1.Text
= "-"
ElseIf
Left$(Text1.Text, 1) = "-" Then
Text1.Text
= Right$(Text1.Text, 2)
Else
Text1.Text
= "-" & Text1.Text
End
If
End
Sub
Private
Sub Command12_Click()
If
InStr(Text1.Text, ".") Then
Beep
Else
If
nilaibaru Then
Text1.Text
= "."
nilaibaru
= False
Else
Text1.Text
= Text1.Text & "."
End
If
End
If
End
Sub
Private Sub Command22_Click()
Dim min
As Integer
If
Left$(Text1.Text, 1) = "-" Then
min
= 2
Else
min
= 1
End
If
If
Len(Text1.Text) > min Then
Text1.Text
= Left$(Text1.Text, Len(Text1.Text) - 1)
Else
Text1.Text
= "0"
End
If
End
Sub
Private
Sub Command21_Click()
Text1.Text
= "0"
End
Sub
Private
Sub Text1_Change()
Text1.SelStart
= Len(Text1.Text)
End
Sub
Private
Sub Text1_GotFocus()
Text1_Change
End
Sub
Private
Sub Command20_Click()
Dim
cetakbaru As Double
If
Text1.Text = "" Then
cetakbaru
= 0
Else
cetakbaru
= CDbl(Text1.Text)
End
If
Select
Case operator
Case
opNol
cetak
= cetakbaru
Case
optambah
cetak
= cetak + cetakbaru
Case
opkurang
cetak
= cetak - cetakbaru
Case
opkali
cetak
= cetak * cetakbaru
Case
opbagi
If
cetakbaru = 0 Then
MsgBox "tidak bisa dibagi 0", vbOKOnly +
vbCritical, "error"
Call
Command21_Click
Else
cetak = cetak / cetakbaru
End
If
Case
opsqrt
cetak
= cetak ^ 2
Case
oppers
cetak
= cetak * 0.1
Case
opsper
cetak
= 1 / cetak
End
Select
operator
= opNol
nilaibaru
= True
Text1.Text
= Format$(cetak)
End
Sub
Private
Sub angka_click(index As Integer)
If
nilaibaru Then
Text1.Text
= Format$(index)
nilaibaru
= False
Else
Text1.Text
= Text1.Text & Format$(index)
End
If
End
Sub
Private
Sub Coperator_click(index As Integer)
Command20_Click
operator
= index
nilaibaru
= True
End
Sub
SEMOGA BERMANFAAT YA,,,,,,,,,,,,,,,,,,,,,,,,,,,
0 Komentar:
Post a Comment