VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB About Us

Simple Calculator



This is a simple calculator that uses a combo box that includes four operators, addition, subtraction, multiplication and division. It can perform the above four basic calculations by changing the arithmetic operators.



The Code

Private Sub Combo1_()

Select Case Combo1.ListIndex
Case 0
Label1 = Str$(Val(Text1.Text) + Val(Text2.Text))
Case 1
Label1 = Str$(Val(Text1.Text) - Val(Text2.Text))
End Select
End Sub

Private Sub Command1_Click()
Select Case Combo1.ListIndex
Case 0
Label1 = Str$(Val(Text1.Text) + Val(Text2.Text))
Case 1
Label1 = Str$(Val(Text1.Text) - Val(Text2.Text))
Case 2
Label1 = Str$(Val(Text1.Text) * Val(Text2.Text))
Case 3
Label1 = Str$(Val(Text1.Text) / Val(Text2.Text))

End Select
End Sub

Private Sub Command2_Click()
End
End Sub

Private Sub Form_Load()
Combo1.AddItem "+"
Combo1.AddItem "-"
Combo1.AddItem "x"
Combo1.AddItem "รท"
Combo1.ListIndex = 1

End Sub


 


Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy