很简单的:窗口放入四个COMMAND控件(Caption属性分别为+、-、X、÷),三个TEXT控件,再放入三个Label控件(Caption属性分别为:操作数1、操作数2和计算结果),窗口的Caption属性改为“四则运算”
代码如下:
Private Sub Command1_Click()
If Val(Text1.Text) + Val(Text2.Text) <> Int(Val(Text1.Text) + Val(Text2.Text)) Then
Text3.Text = Format(Val(Text1.Text) + Val(Text2.Text), "0.######")
Else
Text3.Text = Val(Text1.Text) + Val(Text2.Text)
End If
End Sub
Private Sub Command2_Click()
If Val(Text1.Text) - Val(Text2.Text) <> Int(Val(Text1.Text) - Val(Text2.Text)) Then
Text3.Text = Format(Val(Text1.Text) - Val(Text2.Text), "0.######")
Else
Text3.Text = Val(Text1.Text) - Val(Text2.Text)
End If
End Sub
Private Sub Command3_Click()
If Val(Text1.Text) * Val(Text2.Text) <> Int(Val(Text1.Text) * Val(Text2.Text)) Then
Text3.Text = Format(Val(Text1.Text) * Val(Text2.Text), "0.######")
Else
Text3.Text = Val(Text1.Text) * Val(Text2.Text)
End If
End Sub
Private Sub Command4_Click()
If Val(Text1.Text) / Val(Text2.Text) <> Int(Val(Text1.Text) / Val(Text2.Text)) Then
Text3.Text = Format(Val(Text1.Text) / Val(Text2.Text), "0.######")
Else
Text3.Text = Val(Text1.Text) / Val(Text2.Text)
End If
End Sub
这个怎么样?
dim a as integer
dim b as integer
a=text1.text
b=text2.text
Private Sub Command1_Click()
text3.text=val(a+b)
end sub
Private Sub Command2_Click()
text3.text=val(a-b)
end sub
Private Sub Command3_Click()
text3.text=val(a*b)
end sub
Private Sub Command4_Click()
text3.text=val(a/b)
end sub