VB自定义函数的调用
我在模块中自定义了数据类型如下:PublicTypestandsaAsIntegerbAsIntegercAsIntegerd(1To3)AsIntegerEndType...
我在模块中自定义了数据类型如下:
Public Type stands
a As Integer
b As Integer
c As Integer
d(1 To 3) As Integer
End Type
同时还定于了一个函数如下:
Public Function read(x As Integer, y As Integer, z As Integer) As stands
a = x + y
b = x + z
c = y + z
d(1) = x + y + z
d(2) = x + y + z + 1
d(3) = x + y + z + 2
End Function
在form1中使用了call read(1,2,3)为什么执行的时候说d(1)没有定于呢??
我想在form1中使用该函数的返回值,用什么样的方法能使返回值像我定于的那样:a = ?
b = ?
c = ?
d(1) = ?
……
本人菜鸟,分也不是很多。望各位帮帮忙!谢谢! 展开
Public Type stands
a As Integer
b As Integer
c As Integer
d(1 To 3) As Integer
End Type
同时还定于了一个函数如下:
Public Function read(x As Integer, y As Integer, z As Integer) As stands
a = x + y
b = x + z
c = y + z
d(1) = x + y + z
d(2) = x + y + z + 1
d(3) = x + y + z + 2
End Function
在form1中使用了call read(1,2,3)为什么执行的时候说d(1)没有定于呢??
我想在form1中使用该函数的返回值,用什么样的方法能使返回值像我定于的那样:a = ?
b = ?
c = ?
d(1) = ?
……
本人菜鸟,分也不是很多。望各位帮帮忙!谢谢! 展开
4个回答
展开全部
目前来说定义类型最好用class不要用type。定义stands最好写成这样
Public Class stands
Public a As Integer
Public b As Integer
Public c As Integer
Public d(2) As Integer
Public Sub read(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
a = x + y
b = x + z
c = y + z
d(0) = x + y + z
d(1) = x + y + z + 1
d(2) = x + y + z + 2
End Sub
End Class
在form1里这样用
dim v as new stands
v.read(1,2,3)
然后比如需要知道a就x=v.a就可以了
还有就是不知道你用的什么版本的VB,我用的VB2008已经规定数组下限只能是0了。不能象d(1 To 3) As Integer 这样定义数组了。
Public Class stands
Public a As Integer
Public b As Integer
Public c As Integer
Public d(2) As Integer
Public Sub read(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer)
a = x + y
b = x + z
c = y + z
d(0) = x + y + z
d(1) = x + y + z + 1
d(2) = x + y + z + 2
End Sub
End Class
在form1里这样用
dim v as new stands
v.read(1,2,3)
然后比如需要知道a就x=v.a就可以了
还有就是不知道你用的什么版本的VB,我用的VB2008已经规定数组下限只能是0了。不能象d(1 To 3) As Integer 这样定义数组了。
展开全部
Private Type standsH
a As Integer
b As Integer
c As Integer
d(1 To 3) As Integer
End Type
Dim p1 As standsH
'同时还定于了一个函数如下:
Private Function read(x As Integer, y As Integer, z As Integer) As standsH
read.a = x + y
read.b = x + z
read.c = y + z
read.d(1) = x + y + z
read.d(2) = x + y + z + 1
read.d(3) = x + y + z + 2
End Function
Private Sub Form_Click()
Dim x As standsH
x = read(1, 2, 3)
p1 = read(1, 2, 3)
End Sub
a As Integer
b As Integer
c As Integer
d(1 To 3) As Integer
End Type
Dim p1 As standsH
'同时还定于了一个函数如下:
Private Function read(x As Integer, y As Integer, z As Integer) As standsH
read.a = x + y
read.b = x + z
read.c = y + z
read.d(1) = x + y + z
read.d(2) = x + y + z + 1
read.d(3) = x + y + z + 2
End Function
Private Sub Form_Click()
Dim x As standsH
x = read(1, 2, 3)
p1 = read(1, 2, 3)
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
定义:
sub
savedate()
……
end
sub
调用:
call
savedate
sub
savedate()
……
end
sub
调用:
call
savedate
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
call
...
...
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询