Thursday, May 27, 2010

Scientific Calculator

The value of pi is now obtained by using the Atn function (Arc Tangent). We know that Tan(pi/4)=1, so Atn(1)=pi/4, therefore pi=Atn(1)*4. By using this function, we will obtain a more accurate value of pi. 

In this project, we shall also limit the numbers to be less than 30 digit. If any user enters a number with more than 30 digits, an error message "data overflow" will be shown. 
The Interface:

 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

No comments:

Post a Comment