|
We intend to start a series of VB projects so that together we will make this tutorial website more interesting learning platform for all VB hobbyists in the world. We will first post the ideas of any project in our blog( http://vbtutorblog.blogspot.com/) and then gradually well work through the steps until it is completed. We wish that everyone will contribute your ides so that we can make better and more efficient VB programs. Our first project is a scientific calculator. We have entered the second phase of the project and the details were posted in the vbtutor blog. Phase 1 Creating a scientific calculator is not an easy task in Visual Basic 6. However, you don't have to worry. we will start with a simple interface and gradually we will progress to a more complex interface, and then a fully functional scientific calculator. So, please follow our tutorial or our blog as often as possible for updates on this project. Meanwhile, if you have any idea about the calculator, please share with us. The Interface for phase 1.
The code:
Private Sub Command1_Click(index As
Integer) *In Visual Basic, we have to convert degree to radian before we can compute the values of the trigonometric functions. The conversion is based on the formula pi radian=180o , therefore 1 degree=pi/180.
|
The Code:
Dim Num_of_digit As Integer
Private Sub buttonNum_Click(Index As Integer)
If Num_of_digit > 0 And Num_of_digit <> "0" Then
panel.Caption = panel.Caption + Right$(Str$(Index), 1)
ElseIf panel.Caption = "0" Then
panel.Caption = Str$(Index)
End If
ElseIf Num_of_digit >= 30 Then
panel.Caption = "Data Overflow"
Else
panel.Caption = Right$(Str$(Index), 1)
End If
Num_of_digit = Num_of_digit + 1
End Sub
Private Sub Clear_Click()
panel.Caption = "0"
Num_of_digit = 0
End Sub
Private Sub Command1_Click(Index As Integer)
Dim x As Double
Dim pi As Double
pi = Atn(1) * 4
Select Case Index
Case 0
x = Val(panel.Caption)
panel.Caption = Round((Sin(x * pi / 180)), 4)
Num_of_digit = 0
Case 1
x = Val(panel.Caption)
panel.Caption = Round((Cos(x * pi / 180)), 4)
Num_of_digit = 0
Case 2
x = Val(panel.Caption)
panel.Caption = Round((Tan(x * pi / 180)), 4)
Num_of_digit = 0
End Select
End Sub