如何从VB6函数中获取用户自定义类型的数据返回?

2026-04-29 07:092阅读0评论SEO资讯
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计303个文字,预计阅读时间需要2分钟。

如何从VB6函数中获取用户自定义类型的数据返回?

我是VB的新手。我在网上看到,为了从函数返回值,你做了如下的事情:

- Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Res As Integer Res=x + y Add=Res use the function's nameEnd Function

我是VB的新手.我在网上看到,为了从函数返回,你做了如下的事情 –

Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Res as integer Res = x + y Add = Res ' use the function's name End Function

我的问题是,这种语法是否也适用于用户定义的类型?如果没有,那么语法是什么.我试过以下 –

如何从VB6函数中获取用户自定义类型的数据返回?

Public Function getDetails() As clsDetails Dim details As clsDetails Set details = New clsDetails With details .X = "R" .Y = "N" .Z = "N" ' more code follows End With getDetails = details 'gives error-> object variable or with block variable not set End Function

但是这给了我上面一行的错误 – “对象变量或没有设置块变量”.

我在这做错了什么?

我想clsDetails不是UDT,而是一个类.对于定义为对象的变量,您需要使用SET关键字.即:

set getDetails = details

有关使用UDT作为函数返回值或参数的详细信息,请参阅:User Defined Type (UDT) as parameter in public Sub in class module (VB6).

标签:类型

本文共计303个文字,预计阅读时间需要2分钟。

如何从VB6函数中获取用户自定义类型的数据返回?

我是VB的新手。我在网上看到,为了从函数返回值,你做了如下的事情:

- Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Res As Integer Res=x + y Add=Res use the function's nameEnd Function

我是VB的新手.我在网上看到,为了从函数返回,你做了如下的事情 –

Private Function Add(ByVal x As Integer, ByVal y As Integer) As Integer Dim Res as integer Res = x + y Add = Res ' use the function's name End Function

我的问题是,这种语法是否也适用于用户定义的类型?如果没有,那么语法是什么.我试过以下 –

如何从VB6函数中获取用户自定义类型的数据返回?

Public Function getDetails() As clsDetails Dim details As clsDetails Set details = New clsDetails With details .X = "R" .Y = "N" .Z = "N" ' more code follows End With getDetails = details 'gives error-> object variable or with block variable not set End Function

但是这给了我上面一行的错误 – “对象变量或没有设置块变量”.

我在这做错了什么?

我想clsDetails不是UDT,而是一个类.对于定义为对象的变量,您需要使用SET关键字.即:

set getDetails = details

有关使用UDT作为函数返回值或参数的详细信息,请参阅:User Defined Type (UDT) as parameter in public Sub in class module (VB6).

标签:类型