求一个VB做的计算器

来源:百度知道 编辑:UC知道 时间:2024/05/02 15:48:46
要简单的,初学者能编出来的代码,最好跟教科书类似比较规范的。就只用计算器就行了,谢谢
不希望输入代码有错误,谢谢

command1是一个数组由command1(0),command1(1)...(9)代表数字0....9
command2也是一个数组由command2(0),command2(1)....(3)代表+,-,*,/,
command3 小数点
command4 "="
command5 是退格
command6 清除
command7 正负号"+/-"
command8 开方
command9 "%"不用做
command10 "倒数"

Dim shu1 As Single, shu2 As Single
Dim op As String
Dim second As Boolean

Private Sub Command1_Click(Index As Integer)
If Not second Then
If Val(Text1.Text) = 0 And InStr(Text1.Text, ".") = 0 Then
Text1.Text = Trim(Str(Index))
Else
Text1.Text = Text1.Text & Trim(Str(Index))
End If
Else
shu1 = Val(Text1.Text)
Text1.Text = Str(Index)
second = False
End If
End Sub

Private Sub Command10_Click()
Text1.Text = 1 / (Val(Text1.Text))
End Sub

Private Sub Command2_Click(Index As Integer)
Command4_Click
op = Command2(Inde