Passing data arrays from object to object 
Author Message
 Passing data arrays from object to object

Hello.

I'm experiencing some difficulties (syntax, I presume) relating to
passing arrays of data between objects.  You can see in the code below
that I have tried this two different ways (marked "option #1" and
"option #2" in the Form1 code).  Variations on the syntax produce
different kinds of errors but in general they are along the lines of
the arrays can't be copied one from another (different type or number
of elements is wrong), the let/get/set statements aren't right, and so
forth.  Can anyone help me with this?  My code is shown below.  Thanks
very much!

Andrew

---- In Form1: ----
Option Explicit

Private Sub Form_Load()
   Dim DataSourceObject As Class1
   Dim DataReceivingObject As Class2
   Set DataSourceObject = New Class1
   Set DataReceivingObject = New Class2

   Call DataReceivingObject.SetDataArrayAnotherWay(DataSourceObject)
'option #1
   DataReceivingObject.DataArray = DataSourceObject.DataSource 'option
#2
   DataReceivingObject.AddDataArray

   End
End Sub

---- In Class1: ----
Option Explicit

Private m_DataSource() As Long
Private i As Long

Private Sub Class_Initialize()
   ReDim m_DataSource(10)
   For i = 0 To 10 Step 1
      m_DataSource(i) = i
   Next i
End Sub

Public Property Get DataSource() As Long
   DataSource = m_DataSource
End Property

---- In Class2: ----
Option Explicit

Private m_DataArray() As Long
Private i As Long
Private total As Long

Private Sub Class_Initialize()
   ReDim m_DataArray(10)
End Sub

Public Property Let DataArray(ByRef DataArray() As Long)
   m_DataArray = DataArray
End Property

Public Sub AddDataArray()
   total = 0
   For i = 1 To UBound(m_DataArray) Step 1
      total = total + m_DataArray(i)
   Next i
   MsgBox total, , "Sum of all data:"
End Sub

Public Sub SetDataArrayAnotherWay(ByRef DataSourceObject As Class1)
   m_DataArray = DataSourceObject.DataSource
End Sub



Mon, 14 Jun 2004 22:47:40 GMT  
 Passing data arrays from object to object

Quote:

> I'm experiencing some difficulties (syntax, I presume) relating to
> passing arrays of data between objects. [...] Variations on the syntax
> produce different kinds of errors but in general they are along the lines
> of the arrays can't be copied one from another

You could try using the Variant data type. Variants can be passed in many
contexts where arrays cannot, and you can assign an entire array to a
Variant.

Eq.

--

Equinox Tetrachloride
Atheist, nihilist, logophile and polymath.
www.cl4.org - www.insecurities.org



Mon, 14 Jun 2004 23:21:10 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing Array to COM Object

2. Problem passing a variant array out of VBasic object to ASP

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

4. Passing an Array of Objects to DLL

5. Passing Array from VB to COM objects

6. Passing arrays between objects...

7. Passing Arrays to COM Object Slows Performance

8. Passing array to COM object

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

10. Passing Multi-Dimensional arrays to COM objects from VBScript/ASP

11. Passing an array from an ASP to a COM object

12. Passing an array from an ASP to a COM object

 

 
Powered by phpBB® Forum Software