VB函数将数组返回给ASP [英] VB Function to return array to ASP

查看:71
本文介绍了VB函数将数组返回给ASP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要VB函数来返回集合数组,例如


私有类型员工

empname as string

address as string

工资为整数

deptno为整数

结束类型


dim employees()as员工


公共职能getEmployees()作为员工()

getEmployees =员工

结束职能

我将在ASP中调用该函数。


这是行不通的任何其他方法。


问候,


Raj。

解决方案



" Raj" < ra*@track-mate.netwrote in message

news:el ************* @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
我需要VB函数来返回集合数组,例如


私有类型员工

empname as string

地址为字符串

工资为整数

deptno为整数

结束类型


dim employees()as Employee


Public Function getEmployees()as Employee()

getEmployees = employees

End功能


我将在ASP中调用该功能。


这是行不通的任何其他方法。

问候,


Raj。



首先,上面的代码无法编译。您不能公开私人类型

作为公共成员的返回值。您需要使Employee类型

public才能进行编译。不幸的是,仍然没有帮助与ASP达成一个很好的协议。


ASP只有一种数据类型,变量(如果算上一个,则为两个)

变种作为一种类型的数组)。现在虽然可以重新安排VB代码,但是b $ b将对用户定义类型的引用传递给一个变体,从而进入VBScript

你无法访问该类型的成员。 VBScript解析不允许
允许''type.member''符号同时用于对象和UDT

,就像在VB6中一样。 />

如果ASP只需要保持对传递给

另一个组件的类型的引用,那么只要适当的措施是

用于确保接口以这种方式与脚本兼容(IE

采用变量ByRef)。


如果需要ASP代码能够访问该类型的成员然后

你将需要使用一个类: -


''班级员工

公共empname为字符串

公共地址为字符串

公共工资为整数

公共deptno为整数

''你的班级


Dim employees()as Variant''Actuall包含雇员对象


公共函数getEmployees()As Variant

getEmployees =员工

End Public


然而,这可能会变得昂贵。将您的班级变成一个集合的形式可能会更好。例如,


Dim employess()作为员工

Dim mlCount为长


公共财产获取物品(ByVal索引为长)作为员工

设置项目=员工(索引)

结束财产


公共财产获取Count()as很长

点数= mlCount

结束物业


blockquote>

Thanx确实有价值输入,但我仍然有问题:


这就是我做的:


创建了一个包含两个类的标准exe项目:


员工:

公共empname为字符串

公共地址字符串

公共薪水作为整数

Public deptno As Integer


公司:

Dim employess()作为员工

Dim mlCount长期


公共财产获取数量()为长

计数= mlCount

结束财产

我有一个带有Command Button的表单。关于它的点击事件,我写道:


Private Sub Command1_Click()

Dim cmp1作为新公司


cmp1.Item(1)=新员工

cmp1.Item(1).deptno =" 10"

cmp1.Item(1).empname = Raj


cmp1.Item(2)=新员工

cmp1.Item(2).deptno =" 20"

cmp1.Item(2).empname =" Ram"


打印cmp1.Count

End Sub

然后我收到编译错误:

公共财产获取项目(ByVal Index As Long)作为员工

Set Item = employees(Index)

结束财产


错误信息:Sub或Function未定义。


似乎我遗漏了一些东西。 />

请告诉我。


非常感谢。


问候,


Raj。

-----原始消息-----

来自:" Anthony Jones" < An*@yadayadayada.com>

新闻组:microsoft.public.inetserver.asp.general

已发送:2007年3月23日星期五上午4:32

主题:Re:VB函数将数组返回到ASP


>

" Raj" ; < ra*@track-mate.netwrote in message

news:el ************* @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
>我需要一个VB函数来返回集合数组,如

私有类型员工
empname as string
address as string <薪水为整数
deptno为整数
结束类型

dim employees()as Employee

Public Function getEmployees()as Employee()
getEmployees =员工
结束功能

我将在ASP中调用该功能。

这是行不通的任何其他方法受欢迎。

问候,

Raj。



首先,上面的代码无法编译。您不能公开私人类型

作为公共成员的返回值。你需要让员工

类型

公共来进行编译。不幸的是,仍然没有帮助一个很好的

处理ASP。


ASP只有一种数据类型,变体(或两个如果你计算一个

变体的数组作为一种类型)。现在虽然可以重新安排VB代码



将对用户定义类型的引用传递给变体,从而进入

VBScript

您无法访问该类型的成员。 VBScript解析不允许
允许''type.member''符号同时用于对象和UDT

,就像在VB6中一样。 />

如果ASP只需要保持对传递给

另一个组件的类型的引用,那么只要采取适当的措施,这是可能的。

$

用于确保接口以这种方式与脚本兼容

(IE

采用变量ByRef)。


如果你需要ASP代码才能访问该类型的成员那么

你将需要使用一个类: -


''班级员工

公共empname为字符串

公共地址为字符串

公共薪水为整数

公共deptno为整数


''你的班级


Dim employees()as Variant''Actuall包含雇员对象


公共函数getEmployees()As Variant

getE mployees =员工

End Public


然而,这可能会变得昂贵。最好将你的课程变成

a

形式的集合。例如,


Dim employess()作为员工

Dim mlCount为长


公共财产获取物品(ByVal索引为长)作为员工

设置项目=员工(索引)

结束财产


公共财产获取Count()as很长

点数= mlCount

结束物业



" Anthony Jones" < An*@yadayadayada.com写信息

新闻:Ot **************** @ TK2MSFTNGP03.phx.gbl ...


>

" Raj" < ra*@track-mate.netwrote in message

news:el ************* @ TK2MSFTNGP05.phx.gbl ...
< blockquote class =post_quotes>
>我需要一个VB函数来返回集合数组,如

私有类型员工
empname as string
address as string <薪水为整数
deptno为整数
结束类型

dim employees()as Employee

Public Function getEmployees()as Employee()
getEmployees =员工
结束功能

我将在ASP中调用该功能。

这是行不通的任何其他方法受欢迎。

问候,

Raj。



首先,上面的代码无法编译。您不能公开私人类型

作为公共成员的返回值。你需要让员工

类型

公共来进行编译。不幸的是,仍然没有帮助一个很好的

处理ASP。


ASP只有一种数据类型,变体(或两个如果你计算一个

变体的数组作为一种类型)。现在虽然可以重新安排VB代码



将对用户定义类型的引用传递给变体,从而进入

VBScript

您无法访问该类型的成员。 VBScript解析不允许
允许''type.member''符号同时用于对象和UDT

,就像在VB6中一样。 />

如果ASP只需要保持对传递给

另一个组件的类型的引用,那么只要采取适当的措施,这是可能的。

$

用于确保接口以这种方式与脚本兼容

(IE

采用变量ByRef)。


如果你需要ASP代码才能访问该类型的成员那么

你将需要使用一个类: -


''班级员工

公共empname为字符串

公共地址为字符串

公共薪水为整数

公共deptno为整数


''你的班级


Dim employees()as Variant''Actuall包含雇员对象


公共函数getEmployees()As Variant

getE mployees =员工

End Public


然而,这可能会变得昂贵。最好将你的课程变成

a

形式的集合。例如,


Dim employess()作为员工

Dim mlCount为长


公共财产获取物品(ByVal索引为长)作为员工

设置项目=员工(索引)

结束财产


公共财产获取Count()as很长

点数= mlCount

结束物业





" Raj" < ra*@track-mate.netwrote in message

news:%2 **************** @ TK2MSFTNGP05.phx.gbl ...


Thanx确实是有价值的输入,但我仍有问题:


这就是我所做的:


创建了一个包含两个类的标准exe项目:


员工:

公共empname为字符串

公共地址As String

公共薪水作为整数

Public deptno As Integer


公司:

Dim employess()作为员工

Dim mlCount As Long


公共财产获取数量()为长

Count = mlCount

结束属性


我有一个带有Command Button的表单。关于它的点击事件,我写道:


Private Sub Command1_Click()

Dim cmp1作为新公司


cmp1.Item(1)=新员工

cmp1.Item(1).deptno =" 10"

cmp1.Item(1).empname = Raj


cmp1.Item(2)=新员工

cmp1.Item(2).deptno =" 20"

cmp1.Item(2).empname =" Ram"


打印cmp1.Count

End Sub

然后我收到编译错误:

公共财产获取项目(ByVal Index As Long)作为员工

Set Item = employees(Index)

结束财产


错误信息:Sub或Function未定义。


似乎我遗漏了一些东西。 />

请告诉我。


非常感谢。


问候,


Raj。



是的,你在昏暗中拼错了员工。然而,这是一个更完整的

解决方案: -


公司:

私人maoEmployees()作为员工

私人mlCount为长


公共财产获取数量()为长

计数= mlCount

结束财产


Public Function AddEmployee()as Employee


如果mlCount = UBound(maoEmployees)那么

ReDim保留maoEmployess(mlCount) * 2)作为员工

结束如果


mlCount = mlCount + 1


设置AddEmployee = New Employess


设置maoEmployees(mlCount)= AddEmployee


结束功能


公共功能项目(ByVal Index) as Long)作为员工

Set Item = maoEmployees(Index)

End Public


Private Sub Class_Initialise()


ReDim maoEmployees(16)作为员工


结束子


现在您填写: -


Dim cmp1作为新公司


使用cmp1.AddEmployee

.deptno =" 10"

.empname =" Raj"


使用cmp1.AddEmployee

.deptno =" 20"

.empname =" Ram"

结束


我现在的问题是为什么VB6?

为什么不只是使用VBScripts自己的类等?


I need a VB function to return array of collections like

Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type

dim employees() as Employee

Public Function getEmployees() as Employee()
getEmployees=employees
End Function

I will call that function in ASP.

This was not working any other method is welcomed.

Regards,

Raj.

解决方案


"Raj" <ra*@track-mate.netwrote in message
news:el*************@TK2MSFTNGP05.phx.gbl...

I need a VB function to return array of collections like

Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type

dim employees() as Employee

Public Function getEmployees() as Employee()
getEmployees=employees
End Function

I will call that function in ASP.

This was not working any other method is welcomed.

Regards,

Raj.

First off the code above doesn''t compile. You can''t expose a private type
as a return value of a public member. You would need make the Employee type
public to get it to compile. Unfortunately that still doesn''t help a great
deal with ASP.

ASP only has one data type, the variant (or two if you count an array of
variants as a type). Now whilst it is possible to re-arrange the VB code to
pass a reference to User-Defined type into a variant and thus into VBScript
you can''t access the members of the type. The VBScript parsing doesn''t
allow for the ''type.member'' notation to work both for objects and for UDTs
as it does in VB6.

If the ASP merely needs to hold reference to a type that is passed to
another component then that is possible as long as appropriate measures are
taken to ensure the interfaces are compatible with Script in this way (I.E.
takes a variant ByRef).

If you need the ASP code to be able to access the members of the type then
you will need to use a class instead:-

''Class Employee
Public empname as string
Public address as string
Public salary as integer
Public deptno as integer
''Your class

Dim employees() as Variant '' Actuall contains employess objects

Public Function getEmployees() As Variant
getEmployees = employees
End Public

However that can get expensive. It may be better to turn your class into a
form of a collection. E.g.,

Dim employess() as Employee
Dim mlCount as Long

Public Property Get Item(ByVal Index As Long) As Employee
Set Item = employees(Index)
End Property

Public Property Get Count() as Long
Count = mlCount
End Property



Thanx indeed for the valuable input, but I still have problems:

Here''s what I did:

Have created a standard exe project with two classes:

Employee:
Public empname As String
Public address As String
Public salary As Integer
Public deptno As Integer

Company:
Dim employess() As Employee
Dim mlCount As Long

Public Property Get Count() As Long
Count = mlCount
End Property

I had a form with Command Button. On it''s click event I wrote like:

Private Sub Command1_Click()
Dim cmp1 As New Company

cmp1.Item(1) = New Employee
cmp1.Item(1).deptno = "10"
cmp1.Item(1).empname = "Raj"

cmp1.Item(2) = New Employee
cmp1.Item(2).deptno = "20"
cmp1.Item(2).empname = "Ram"

Print cmp1.Count
End Sub

Then I got a compile error at:
Public Property Get Item(ByVal Index As Long) As Employee
Set Item = employees(Index)
End Property

Error Message: Sub or Function not defined.

It seems I am missing something.

Please let me know.

Thank you very much.

Regards,

Raj.
----- Original Message -----
From: "Anthony Jones" <An*@yadayadayada.com>
Newsgroups: microsoft.public.inetserver.asp.general
Sent: Friday, March 23, 2007 4:32 AM
Subject: Re: VB Function to return array to ASP

>
"Raj" <ra*@track-mate.netwrote in message
news:el*************@TK2MSFTNGP05.phx.gbl...

>I need a VB function to return array of collections like

Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type

dim employees() as Employee

Public Function getEmployees() as Employee()
getEmployees=employees
End Function

I will call that function in ASP.

This was not working any other method is welcomed.

Regards,

Raj.


First off the code above doesn''t compile. You can''t expose a private type
as a return value of a public member. You would need make the Employee
type
public to get it to compile. Unfortunately that still doesn''t help a
great
deal with ASP.

ASP only has one data type, the variant (or two if you count an array of
variants as a type). Now whilst it is possible to re-arrange the VB code
to
pass a reference to User-Defined type into a variant and thus into
VBScript
you can''t access the members of the type. The VBScript parsing doesn''t
allow for the ''type.member'' notation to work both for objects and for UDTs
as it does in VB6.

If the ASP merely needs to hold reference to a type that is passed to
another component then that is possible as long as appropriate measures
are
taken to ensure the interfaces are compatible with Script in this way
(I.E.
takes a variant ByRef).

If you need the ASP code to be able to access the members of the type then
you will need to use a class instead:-

''Class Employee
Public empname as string
Public address as string
Public salary as integer
Public deptno as integer
''Your class

Dim employees() as Variant '' Actuall contains employess objects

Public Function getEmployees() As Variant
getEmployees = employees
End Public

However that can get expensive. It may be better to turn your class into
a
form of a collection. E.g.,

Dim employess() as Employee
Dim mlCount as Long

Public Property Get Item(ByVal Index As Long) As Employee
Set Item = employees(Index)
End Property

Public Property Get Count() as Long
Count = mlCount
End Property

"Anthony Jones" <An*@yadayadayada.comwrote in message
news:Ot****************@TK2MSFTNGP03.phx.gbl...

>
"Raj" <ra*@track-mate.netwrote in message
news:el*************@TK2MSFTNGP05.phx.gbl...

>I need a VB function to return array of collections like

Private Type Employee
empname as string
address as string
salary as integer
deptno as integer
End Type

dim employees() as Employee

Public Function getEmployees() as Employee()
getEmployees=employees
End Function

I will call that function in ASP.

This was not working any other method is welcomed.

Regards,

Raj.


First off the code above doesn''t compile. You can''t expose a private type
as a return value of a public member. You would need make the Employee
type
public to get it to compile. Unfortunately that still doesn''t help a
great
deal with ASP.

ASP only has one data type, the variant (or two if you count an array of
variants as a type). Now whilst it is possible to re-arrange the VB code
to
pass a reference to User-Defined type into a variant and thus into
VBScript
you can''t access the members of the type. The VBScript parsing doesn''t
allow for the ''type.member'' notation to work both for objects and for UDTs
as it does in VB6.

If the ASP merely needs to hold reference to a type that is passed to
another component then that is possible as long as appropriate measures
are
taken to ensure the interfaces are compatible with Script in this way
(I.E.
takes a variant ByRef).

If you need the ASP code to be able to access the members of the type then
you will need to use a class instead:-

''Class Employee
Public empname as string
Public address as string
Public salary as integer
Public deptno as integer
''Your class

Dim employees() as Variant '' Actuall contains employess objects

Public Function getEmployees() As Variant
getEmployees = employees
End Public

However that can get expensive. It may be better to turn your class into
a
form of a collection. E.g.,

Dim employess() as Employee
Dim mlCount as Long

Public Property Get Item(ByVal Index As Long) As Employee
Set Item = employees(Index)
End Property

Public Property Get Count() as Long
Count = mlCount
End Property




"Raj" <ra*@track-mate.netwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...

Thanx indeed for the valuable input, but I still have problems:

Here''s what I did:

Have created a standard exe project with two classes:

Employee:
Public empname As String
Public address As String
Public salary As Integer
Public deptno As Integer

Company:
Dim employess() As Employee
Dim mlCount As Long

Public Property Get Count() As Long
Count = mlCount
End Property

I had a form with Command Button. On it''s click event I wrote like:

Private Sub Command1_Click()
Dim cmp1 As New Company

cmp1.Item(1) = New Employee
cmp1.Item(1).deptno = "10"
cmp1.Item(1).empname = "Raj"

cmp1.Item(2) = New Employee
cmp1.Item(2).deptno = "20"
cmp1.Item(2).empname = "Ram"

Print cmp1.Count
End Sub

Then I got a compile error at:
Public Property Get Item(ByVal Index As Long) As Employee
Set Item = employees(Index)
End Property

Error Message: Sub or Function not defined.

It seems I am missing something.

Please let me know.

Thank you very much.

Regards,

Raj.

Yeah you spelt employees wrong in the Dim. However here is a more complete
solution:-

Company:
Private maoEmployees() As Employee
Private mlCount As Long

Public Property Get Count() As Long
Count = mlCount
End Property

Public Function AddEmployee() as Employee

If mlCount = UBound(maoEmployees) Then
ReDim Preserve maoEmployess(mlCount * 2) As Employee
End If

mlCount = mlCount + 1

Set AddEmployee = New Employess

Set maoEmployees(mlCount) = AddEmployee

End Function

Public Function Item(ByVal Index as Long) As Employee
Set Item = maoEmployees(Index)
End Public

Private Sub Class_Initialise()

ReDim maoEmployees(16) As Employee

End Sub

Now you populate with:-

Dim cmp1 As New Company

With cmp1.AddEmployee
.deptno = "10"
.empname = "Raj"
End With

With cmp1.AddEmployee
.deptno = "20"
.empname = "Ram"
End With

My question now is why VB6?
Why not just use VBScripts own Classes etc?



这篇关于VB函数将数组返回给ASP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆