做起来还真有点纠结…… 简单的例子:x,y的四则运算:新建一工程,添加text三个,command一个,粘贴如下代码,输入x,y的值和运算方式,按command:Private Sub Command1_Click() x = Val(Text1.Text) y = Val(Text2.Text) s = Text3.Text f = "+,-,*,/" ff = Split(f, ",") For i = 0 To UBound(ff) ss = Split(s, ff(i)) If UBound(ss) > 0 Then If ss(0) = "x" Then Select Case ff(i) Case "+" Print Text3.Text & "=" & x + y Case "-" Print Text3.Text & "=" & x - y Case "*" Print Text3.Text & "=" & x * y Case "/" Print Text3.Text & "=" & x / y End Select End If If ss(1) = "x" Then Select Case ff(i) Case "+" Print Text3.Text & "=" & y + x Case "-" Print Text3.Text & "=" & y - x Case "*" Print Text3.Text & "=" & y * x Case "/" Print Text3.Text & "=" & y / x End Select End If End If Next End SubPrivate Sub Form_Load() Text1.Text = "x的值" Text2.Text = "y的值" Text3.Text = "x+y" End Sub
简单的例子:x,y的四则运算:新建一工程,添加text三个,command一个,粘贴如下代码,输入x,y的值和运算方式,按command:Private Sub Command1_Click()
x = Val(Text1.Text)
y = Val(Text2.Text)
s = Text3.Text
f = "+,-,*,/"
ff = Split(f, ",")
For i = 0 To UBound(ff)
ss = Split(s, ff(i))
If UBound(ss) > 0 Then
If ss(0) = "x" Then
Select Case ff(i)
Case "+"
Print Text3.Text & "=" & x + y
Case "-"
Print Text3.Text & "=" & x - y
Case "*"
Print Text3.Text & "=" & x * y
Case "/"
Print Text3.Text & "=" & x / y
End Select
End If
If ss(1) = "x" Then
Select Case ff(i)
Case "+"
Print Text3.Text & "=" & y + x
Case "-"
Print Text3.Text & "=" & y - x
Case "*"
Print Text3.Text & "=" & y * x
Case "/"
Print Text3.Text & "=" & y / x
End Select
End If
End If
Next
End SubPrivate Sub Form_Load()
Text1.Text = "x的值"
Text2.Text = "y的值"
Text3.Text = "x+y"
End Sub
提取公式,使用scriptcontrol控件或者对象进行计算