关于vb类模块的一个小问题
在vb6中的class1中的代码Privatem,d'定义class1的成员变量PublicSubss(x,y)'把x值赋值给m,y值赋值给dm=x:d=yEndSubP...
在vb6中的class1中的代码
Private m, d '定义class1的成员变量
Public Sub ss(x, y)'把x值赋值给m,y值赋值给d
m = x: d = y
End Sub
Public Function re(x)'返回成员变量函数
If x = 1 Then
re = m
ElseIf x = 2 Then
re = d
Else
End If
End Function
Public Function cs()'显示成员变量的值
cs = a & "-" & b
End Function
主窗体form1的代码
Public Function add(cl1 As Class2, cl2 As Class2) As Class2 '定义class2中的运算函数
Dim c As New Class2
Call c.ss(cl1.re(1) + cl2.re(2), cl1.re(2) + cl2.re(2))
add = c: Set c = Nothing
End Function
Private Sub Command1_Click()'命令按钮单击事件
Dim cl1 As New Class2, cl2 As New Class2, cl3 As New Class2
cl1.ss 3, 4: cl2.ss 4, 5: cl3 = add(cl1, cl2)
Label1.Caption = cl3.cs
End Sub
但是点击命令按钮后出现对象变量或者with变量未设置,怎么回事? 展开
Private m, d '定义class1的成员变量
Public Sub ss(x, y)'把x值赋值给m,y值赋值给d
m = x: d = y
End Sub
Public Function re(x)'返回成员变量函数
If x = 1 Then
re = m
ElseIf x = 2 Then
re = d
Else
End If
End Function
Public Function cs()'显示成员变量的值
cs = a & "-" & b
End Function
主窗体form1的代码
Public Function add(cl1 As Class2, cl2 As Class2) As Class2 '定义class2中的运算函数
Dim c As New Class2
Call c.ss(cl1.re(1) + cl2.re(2), cl1.re(2) + cl2.re(2))
add = c: Set c = Nothing
End Function
Private Sub Command1_Click()'命令按钮单击事件
Dim cl1 As New Class2, cl2 As New Class2, cl3 As New Class2
cl1.ss 3, 4: cl2.ss 4, 5: cl3 = add(cl1, cl2)
Label1.Caption = cl3.cs
End Sub
但是点击命令按钮后出现对象变量或者with变量未设置,怎么回事? 展开
展开全部
代码改下在如下
'class块
Private m, d '定义class1的成员变量
Public Sub ss(x, y) '把x值赋值给m,y值赋值给d
m = x: d = y
End Sub
Public Function re(x) '返回成员变量函数
If x = 1 Then
re = m
ElseIf x = 2 Then
re = d
Else
End If
End Function
Public Function cs() '显示成员变量的值
cs = m & "-" & d '把a,b改为m,d
End Function
'form1块
Public Function add(cl1 As Class1, cl2 As Class1) As Class1 '把c1改为cl1
Dim c As New Class1
Call c.ss(cl1.re(1) + cl2.re(2), cl1.re(2) + cl2.re(2))
Set add = c '加关键字Set
Set c = Nothing
End Function
Private Sub Command1_Click()
Dim cl1 As New Class1, cl2 As New Class1, cl3 As New Class1
cl1.ss 3, 4
cl2.ss 4, 5
Set cl3 = add(cl1, cl2) '加关键字Set
Label1.Caption = cl3.cs
End Sub
'class块
Private m, d '定义class1的成员变量
Public Sub ss(x, y) '把x值赋值给m,y值赋值给d
m = x: d = y
End Sub
Public Function re(x) '返回成员变量函数
If x = 1 Then
re = m
ElseIf x = 2 Then
re = d
Else
End If
End Function
Public Function cs() '显示成员变量的值
cs = m & "-" & d '把a,b改为m,d
End Function
'form1块
Public Function add(cl1 As Class1, cl2 As Class1) As Class1 '把c1改为cl1
Dim c As New Class1
Call c.ss(cl1.re(1) + cl2.re(2), cl1.re(2) + cl2.re(2))
Set add = c '加关键字Set
Set c = Nothing
End Function
Private Sub Command1_Click()
Dim cl1 As New Class1, cl2 As New Class1, cl3 As New Class1
cl1.ss 3, 4
cl2.ss 4, 5
Set cl3 = add(cl1, cl2) '加关键字Set
Label1.Caption = cl3.cs
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询