VB 一个简单的VB小测试程序,帮忙查错

来源:百度知道 编辑:UC知道 时间:2024/06/17 21:51:46
'类模块
'模块名为CMath
Function Add(a As Integer, b As Integer) As Integer
Add = a + b
End Function

Function Subtract(a As Integer, b As Integer) As Integer
Subtract = a - b
End Function

Function Multiply(a As Integer, b As Integer) As Integer
Multiply = a * b
End Function

Function Divide(a As Integer, b As Integer) As Integer
Divide = a / b
End Function

'Form1 :
Private Sub Command1_Click()
Dim math As CMath
Text3.Text = CStr(math.Add(Val(Text1.Text), Val(Text2.Text)))
End Sub

按下Command1按扭后,提示对象变量或With块变量未设置是怎么回事??

在 Dim math As CMath 后面
添加 Set math = new CMath

math对象没有初始化,在按钮单击事件中添加:
'Form1 :
Private Sub Command1_Click()
Dim math As CMath
set math=new cmath
Text3.Text = CStr(math.Add(Val(Text1.Text), Val(Text2.Text)))
End Sub