Mudah2 an baek-baek ja and pulsa ny masih banyak… biar forum ne tetep AXIS… (AXIS baek y…)
Oke langsung ja… jika sebelumnya kita dah buat program animasi, X ini kita akan coba ngebuat program kalkulator dengan VB. Untuk lebih jelasnya mari kita ikuti langkah-langkah pembuatan nya.
1. Seperti biasa buka program VB dan buat project baru…
2. Desain form dengan memasukkan textbox dan dua bh commandButton..
3. Selanjutnya untuk commandButton yang pertama, kita akan menjadikannya sebagai fungsia array sebanyak 10 bh dengan cara mengcopy paste control tersebut dan menyusunnya seperti desain dibawah ini
4. Setelah mendesai dan menambahkan fungsi array, sekarang tambahkan enam bh commandButton pada form anda
5. Selanjutnya Listing program…. Ketik listing program dibawah ne
Dim intLeft As Integer
Dim intRight As Integer
Dim intInProg As Integer
Dim intOperator As Integer
Dim intPrevOperator As Integer
Dim intClear As Integer
Private Sub Calculate()
If intInProg = 0 Then
intLeft = Int(Text1.Text)
intInProg = 1
Text1.Text = ""
intPrevOperator = intOperator
Exit Sub
Else
intRight = Int(Text1.Text)
Text1.Text = ""
End If
Select Case intPrevOperator
Case 1
intLeft = intLeft + intRight
intRight = 0
Text1.Text = intLeft
Case 2
intLeft = intLeft - intRight
intRight = 0
Text1.Text = intLeft
Case 3
intLeft = intLeft * intRight
intRight = 0
Text1.Text = intLeft
Case 4
intLeft = intLeft / intRight
intRight = 0
Text1.Text = intLeft
End Select
intPrevOperator = intOperator
intClear = 1
End Sub
Private Sub Command1_Click(Index As Integer)
If intClear = 1 Then
Text1.Text = ""
intClear = 1
End If
If Index <> 10 Then
Text1.Text = Text1.Text & (Index + 0)
Else
Text1.Text = Text1.Text & "0"
End If
End Sub
Private Sub Command2_Click()
Text1.Text = ""
intLeft = 0
intRight = 0
intOperator = 0
intPrevOperator = 0
intInProg = 0
End Sub
Private Sub Command3_Click()
intOperator = 1
Calculate
End Sub
Private Sub Command4_Click()
intOperator = 2
Calculate
End Sub
Private Sub Command5_Click()
intOperator = 3
Calculate
End Sub
Private Sub Command6_Click()
intOperator = 5
Calculate
End Sub
Private Sub Command7_Click()
intOperator = 4
Calculate
End Sub
Private Sub Command8_Click()
Text1.Text = Text1.Text & "."
End Sub
Private Sub Form_Load()
intInProg = False
Text1.Text = ""
Command1(0).Caption = "0"
Command1(1).Caption = "1"
Command1(2).Caption = "2"
Command1(3).Caption = "3"
Command1(4).Caption = "4"
Command1(5).Caption = "5"
Command1(6).Caption = "6"
Command1(7).Caption = "7"
Command1(8).Caption = "8"
Command1(9).Caption = "9"
Command2.Caption = "Delete"
Command3.Caption = "+"
Command4.Caption = "-"
Command5.Caption = "*"
Command6.Caption = "="
Command7.Caption = "/"
Command8.Caption = "."
End Sub
6. TAMAT … run programnya… (akhirnya selesai juga…)
Tampilan program