03-23-07 12:24 PM
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" <Ant@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" <raj@track-mate.net> wrote in message
> news:elhHDhRbHHA.208@TK2MSFTNGP05.phx.gbl...
>
> 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" <Ant@yadayadayada.com> wrote in message
news:Ot%23by4SbHHA.1216@TK2MSFTNGP03.phx.gbl...
>
> "Raj" <raj@track-mate.net> wrote in message
> news:elhHDhRbHHA.208@TK2MSFTNGP05.phx.gbl...
>
> 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
>
>
>
>
[ Post a follow-up to this message ]
|