用VB编程设计一个类似于Windows附件中的计算器,如图所示,可进行简单的算术运算、三角函数和自然对数运算

1个回答

  • 我已帮你全部做好,工程下载地址我已发给你

    Dim pi As Double

    Dim temp As Double

    Dim j As Integer

    Dim te As String

    Dim yf As String

    Dim m As Boolean

    Dim f As Boolean

    Private Sub Command1_Click(Index As Integer)

    If f = True Then Text1 = ""

    If Index = 10 Then

    Text1.Text = Text1.Text & "."

    Else

    Text1.Text = Text1.Text & Index

    End If

    f = False

    End Sub

    Private Sub Command2_Click(Index As Integer)

    Call kl

    temp = Text1

    Text1 = ""

    Text1 = Command2(Index).Caption

    f = True

    yf = Command2(Index).Caption

    End Sub

    Private Sub Command3_Click()

    If m = True Then

    Call kl

    Else

    Select Case yf

    Case "+"

    Text1 = temp + Val(Text1)

    Case "-"

    Text1 = temp - Val(Text1)

    Case "*"

    Text1 = temp * Val(Text1)

    Case "/"

    If Val(Text1) = 0 Then

    MsgBox "除数不为0"

    Else

    Text1 = temp / Val(Text1)

    End If

    End Select

    End If

    End Sub

    Sub kl()

    If m = True Then

    a = Val(Replace(Text1,te,""))

    If te = "sin" Then

    If Option1.Value = True Then

    Text1 = Sin(a * pi / 180)

    Else

    a = Val(Replace(Text1,"π/",""))

    Text1 = Sin(pi / a)

    End If

    ElseIf te = "sprt" Then

    Text1 = Sqr(a)

    ElseIf te = "1/x" Then

    Text1 = 1 / a

    ElseIf te = "%" Then

    Text1 = a * 100

    ElseIf te = "cos" Then

    If Option1.Value = True Then

    Text1 = Cos(a * pi / 180)

    Else

    a = Val(Replace(Text1,"π/",""))

    Text1 = Cos(pi / a)

    End If

    ElseIf te = "tan" Then

    If Option1.Value = True Then

    Text1 = Tan(a * pi / 180)

    Else

    a = Val(Replace(Text1,"π/",""))

    Text1 = Tan(pi / a)

    End If

    ElseIf te = "ln" Then '等号的ln计算

    Text1 = Log(Val(Text1.Text))

    End If

    m = False

    End If

    End Sub

    Private Sub Command4_Click()

    Text1.Text = Mid(Text1,1,Len(Text1.Text) - 1)

    End Sub

    Private Sub Command5_Click()

    Text1.Text = ""

    temp = 0

    m = False

    End Sub

    Private Sub Command6_Click(Index As Integer)

    Text1.Text = Command6(Index).Caption

    te = Command6(Index).Caption

    m = True

    End Sub

    Private Sub Command7_Click()

    End

    End Sub

    Private Sub Command8_Click()

    Text1 = "π/"

    End Sub

    Private Sub Form_Load()

    pi = 4 * Atn(1)

    End Su