Using an array as an object property 
Author Message
 Using an array as an object property

I wanted to use a dynamic array as a property for a user control
object.  But when I do what seems logical to me --actually even it
doesn't quite make sense, but I'm not sure what to do, I get an error
message that says that the definitions are inconsistent

Here's what I tried

Public Property Get BatchArray() As String
    BatchArray = mvarBatchArray
End Property
Public Property Let BatchArray(vdata() As String)
    mvarBatchArray = vdata
End Property

I'm not sure how to tell the Get that this is an array, so that the Let
can use it as one as well.  What am I missing?

Thanks,
Marty



Wed, 09 Jan 2002 03:00:00 GMT  
 Using an array as an object property
Marty,

The trick is that arrays are in fact passed as variants.  The following
should work (it does for me):

Private mvarBatchArray

Public Property Get BatchArray() As Variant
    BatchArray = mvarBatchArray
End Property

Public Property Let BatchArray(vdata As Variant)
    mvarBatchArray = vdata
End Property

You can drop the "As Variant" in both, but it is better to include them as
a reminder to yourself and others.

John...........

Quote:

> I wanted to use a dynamic array as a property for a user control
> object.  But when I do what seems logical to me --actually even it
> doesn't quite make sense, but I'm not sure what to do, I get an error
> message that says that the definitions are inconsistent

> Here's what I tried

> Public Property Get BatchArray() As String
>     BatchArray = mvarBatchArray
> End Property
> Public Property Let BatchArray(vdata() As String)
>     mvarBatchArray = vdata
> End Property

> I'm not sure how to tell the Get that this is an array, so that the Let
> can use it as one as well.  What am I missing?

> Thanks,
> Marty



Wed, 09 Jan 2002 03:00:00 GMT  
 Using an array as an object property
Quote:
>The trick is that arrays are in fact passed as variants

?i?think?you?meant?to?say?that?to?pass?an?array?you?need?to?use?a?Variant?
BUT, THIS IS NO LONGER TRUE!!!  In VB6 one can get away with:
Quote:
> Public Property Get BatchArray() As String()
>     BatchArray = mvarBatchArray
> End Property
> Public Property Let BatchArray(vdata() As String)
>     mvarBatchArray = vdata
> End Property

WILL PEOPLE PLEASE POST VB VERSION NUMBER WITH THEIR QUESTIONS !
Neila
Quote:

>Marty,

>The trick is that arrays are in fact passed as variants.  The following
>should work (it does for me):

>Private mvarBatchArray

>Public Property Get BatchArray() As Variant
>    BatchArray = mvarBatchArray
>End Property

>Public Property Let BatchArray(vdata As Variant)
>    mvarBatchArray = vdata
>End Property

>You can drop the "As Variant" in both, but it is better to include them as
>a reminder to yourself and others.

>John...........


>> I wanted to use a dynamic array as a property for a user control
>> object.  But when I do what seems logical to me --actually even it
>> doesn't quite make sense, but I'm not sure what to do, I get an error
>> message that says that the definitions are inconsistent

>> Here's what I tried

>> Public Property Get BatchArray() As String
>>     BatchArray = mvarBatchArray
>> End Property
>> Public Property Let BatchArray(vdata() As String)
>>     mvarBatchArray = vdata
>> End Property

>> I'm not sure how to tell the Get that this is an array, so that the Let
>> can use it as one as well.  What am I missing?

>> Thanks,
>> Marty



Wed, 09 Jan 2002 03:00:00 GMT  
 Using an array as an object property
Marty,

Try:

Public Property Let BatchArray(vdata() As String)
End Property

Public Property Get BatchArray() As String() ' note parentheses
End Property

--A



Fri, 11 Jan 2002 03:00:00 GMT  
 Using an array as an object property
I believe the only way you can pass arrays as properties is as Variants,
since arrays are always passed as Variants anyway. So the code should be:

Dim m_BatchArray as String()

Public Property Let BatchArray(inarray as Variant)
    m_BatchArray = inarray
End Property

Public Property Get BatchArray() as Variant
    BatchArray = m_BatchArray
End Property


Quote:
> Marty,

> Try:

> Public Property Let BatchArray(vdata() As String)
> End Property

> Public Property Get BatchArray() As String() ' note parentheses
> End Property

> --A



Sun, 13 Jan 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Object Properties, Array Properties

2. Array as a Property of an Object, and Collection

3. Property Array in an Object ?

4. array object property possible?

5. Objects with arrays as public properties

6. Using arrays as arguments in Let and Get Properties

7. Setting of properties using an array

8. Need help passing an array to an Oracle procedure using Oracle Objects for OLE

9. Using Object Arrays

10. How to pass vbscript array variable to shared object using ByRef

11. How to reference JavaScript Array object using VBScript?

12. Passing array using COM objects

 

 
Powered by phpBB® Forum Software