求VB 计算器代码,截图

来源:百度知道 编辑:UC知道 时间:2024/05/13 05:10:13
求VB 计算器代码
界面是三个文本框
那个四个+-*/是一个控件组哦

首先添加一个按键,三个文本框,三个标签和四个单选框按钮.
各控件属性如下
控件 名称 caption
按键 Command1 计算
第一个文本框 Text1
第二个文本框 Text2
第三个文本框 Text3
第一个标签 Label1 第一个数据:
第二个标签 Label2 第二个数据:
第三个标签 Label3 结果值:
第一个单选框 Optionadd 加
第二个单选框 Optionsub 减
第三个单选框 Optionmult 乘
第四个单选框 Optiondiv 除

代码如下:
Private Sub Command1_Click()
Dim x As Double
Dim y As Double
Dim result As Double

On Error GoTo errstep

x = CDbl(Text1.Text)
y = CDbl(Text2.Text)
If Optionadd.Value = True Then result = x + y
If Optionsub.Value = True Then result = x - y
If Optionmult.Value = True Then result = x * y
If Optiondiv.Value = True Then
result = x / y
End If
Text3.Text = CStr(result)
Exit Sub

errstep: Text3.Text = "计算错误"

End Sub