数学中国

 找回密码
 注册
搜索
热搜: 活动 交友 discuz
查看: 5|回复: 0

三角函数和反三角函数计算器的代码和界面

[复制链接]
发表于 2025-12-6 23:09 | 显示全部楼层 |阅读模式
三角函数和反三角函数计算器的代码和界面(几年以前弄的):
Option Explicit
Const pi = "3.141592653589793238462"
Dim x As Double, y As Double
Private Sub Form_Load()
Option1.Value = True
End Sub
Private Sub Command1_Click()
    Dim x As Double, y As Double
    Dim asin As Double
    x = Val(Text1.Text)
    If Option1 = True Then
    x = Val(x * pi / 180)
    Else
    x = x
    End If
    y = Sin(x)
    Text2 = y
     
End Sub


Function Sec(x) As Double '正割
Sec = 1 / Cos(x)
End Function
Function Csc(x) As Double '余割
Csc = 1 / Sin(x)
End Function
Function Cot(x) As Double '余切
Cot = 1 / Tan(x)
End Function
Function ArcSin(x) As Double '反正弦
ArcSin = Atn(x / Sqr(-x * x + 1))
End Function

Function ArcCos(x) As Double '反余弦
ArcCos = Atn(-x / Sqr(-x * x + 1)) + 2 * Atn(1)
End Function
Function ArcSec(x) As Double '反正割
ArcSec = Atn(x / Sqr(x * x - 1)) + Sgn((x) - 1) * (2 * Atn(1))
End Function
Function ArcCsc(x) As Double '反余割
ArcCsc = Atn(x / Sqr(x * x - 1)) + (Sgn(x) - 1) * (2 * Atn(1))
End Function
Function ArcCot(x) As Double '反余切
ArcCot = ArcSec(x) / ArcCsc(x)
End Function

Private Sub Command10_Click()
Text1 = ""
Text2 = ""
End Sub

Private Sub Command2_Click()
x = Text1
If x = 1 Then
y = pi / 2
ElseIf x = -1 Then
y = 0 - pi / 2
Else
y = ArcSin(x)
End If
If Option1 = True Then
    y = Val(y * 180 / pi)
    Else
    y = y
    End If
Text2 = y
End Sub

Private Sub Command3_Click()
Dim x, y
x = Text1
If Option1 = True Then
    x = Val(x * pi / 180)
    Else
    x = x
    End If
y = Cos(x)
Text2 = y
End Sub

Private Sub Command4_Click()

x = Text1
If x = 1 Then
y = 0
ElseIf x = -1 Then
y = pi
Else
y = ArcCos(x)
End If
If Option1 = True Then
    y = Val(y * 180 / pi)
    Else
    y = y
    End If
Text2 = y
End Sub

Private Sub Command5_Click()
x = Text1
If Option1 = True Then
    x = Val(x * pi / 180)
    Else
    x = x
    End If
y = Tan(x)
Text2 = y
End Sub

Private Sub Command6_Click()
Dim x, y
x = Text1
y = Atn(x)
If Option1 = True Then
    y = Val(y * 180 / pi)
    Else
    y = y
    End If
Text2 = y
End Sub

Private Sub Command7_Click()
x = Text1
If Option1 = True Then
    x = Val(x * pi / 180)
    Else
    x = x
    End If
y = 1 / Tan(x)
Text2 = y
End Sub

Private Sub Command8_Click()
Dim x, y
x = Text1
y = Atn(1 / x)
If Option1 = True Then
    y = Val(y * 180 / pi)
    Else
    y = y
    End If
Text2 = y
End Sub

Private Sub Command9_Click()
End
End Sub

Private Sub Option1_Click()
Option1 = True
End Sub

Private Sub Option2_Click()
Option2 = True
End Sub


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|数学中国 ( 京ICP备05040119号 )

GMT+8, 2025-12-7 15:50 , Processed in 0.087064 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表