Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Multidimensional Arrays as Properties in Class Files?

Sorry for a second post that is similar to my previous but I did not
receive any direction and I'm fairly well lost here.

Can someone please give me an example of a Let and Get for a
multidimensional array of [say] 10 rows and 2 columns (9, 1).

What is passed back-and-forth to the class - the index and related
values or the array itself?

I'm using Excel XP on one machine and Excel 2002 on another (I assume
it would be that same solution for both versions).

Thanks everyone!

Trip

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Multidimensional Arrays as Properties in Class Files?

Trip,

Does this help?

Class module

Option Explicit

Private pArray

Public Function GetArray()
GetArray = pArray
End Function

Public Function PutArray(ary())
pArray = ary
End Function

Public Function AddOne()
Dim i As Long
For i = LBound(pArray) To UBound(pArray)
pArray(i, 3) = pArray(i, 3) + 1
Next i
End Function

Private Sub Class_Initialize()
pArray = [{"Bob","M", 123;"Lynne","F",898;"Amy","F",543}]
End Sub


Normal module

Sub TestArrayClass()
Dim myArray
Dim cArray As clsArray

Set cArray = New clsArray

With cArray
myArray = .GetArray
MsgBox myArray(1, 1) & " - " & myArray(1, 3)
.AddOne
myArray = .GetArray
MsgBox myArray(1, 1) & " - " & myArray(1, 3)
End With

End Sub


--
HTH

Bob Phillips

"Trip" wrote in message
oups.com...
Sorry for a second post that is similar to my previous but I did not
receive any direction and I'm fairly well lost here.

Can someone please give me an example of a Let and Get for a
multidimensional array of [say] 10 rows and 2 columns (9, 1).

What is passed back-and-forth to the class - the index and related
values or the array itself?

I'm using Excel XP on one machine and Excel 2002 on another (I assume
it would be that same solution for both versions).

Thanks everyone!

Trip



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Multidimensional Arrays as Properties in Class Files?

Hey Bob,

Thanks for taking the time to reply. This has helped but doesn't get
me completely out of the woods. I need to use indexes, i.e.;
MyArray(10000,2) and I need to use the index on in the non-class
module.

What I am finding is that if I simply define the array without defining
the the number of rows & columns that I get an error once I try to
store data via an index; i.e.; MyArray(2, 2) = "something". On the
other hand, if I do declare the array with the size parameters I can
not "get" the array stored in the class file; i.e.; MyArray = .GetArray

I find that this is true whether or not I use your method or standard
Public Property Get/Let. So, it seems as though I have to use one
array to set and another array to get - after the get I do a For i =
LBound(MyArray) to UBound(MyArray) swap setting each element in one
array equal to the other, then perform my operations and then set
again.

Any suggestions on how to avoid this?

Thanks!

Trip

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Multidimensional Arrays as Properties in Class Files?

Trip,

If I am understanding you correctly, why not swap the whole array out of the
class into the module (or vice versa) into a copy, and work on the copy,
then reverse the flow. You can easily tell how many elements the array has,
so there should be no fear of out-of-bounds.

--
HTH

Bob Phillips

"Trip" wrote in message
oups.com...
Hey Bob,

Thanks for taking the time to reply. This has helped but doesn't get
me completely out of the woods. I need to use indexes, i.e.;
MyArray(10000,2) and I need to use the index on in the non-class
module.

What I am finding is that if I simply define the array without defining
the the number of rows & columns that I get an error once I try to
store data via an index; i.e.; MyArray(2, 2) = "something". On the
other hand, if I do declare the array with the size parameters I can
not "get" the array stored in the class file; i.e.; MyArray = .GetArray

I find that this is true whether or not I use your method or standard
Public Property Get/Let. So, it seems as though I have to use one
array to set and another array to get - after the get I do a For i =
LBound(MyArray) to UBound(MyArray) swap setting each element in one
array equal to the other, then perform my operations and then set
again.

Any suggestions on how to avoid this?

Thanks!

Trip



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default Multidimensional Arrays as Properties in Class Files?

Bob,

You are correct in your understanding. Unfortunately, it is I who has
a lack of understanding. Would you be able to provide me an example of
how to swap a whole array with indexes out of AND into a class. I'm
not able to find a way to do both while maintaining the indicies.

This is how I am doing it right now...

In the Class Module cArrayClass...

Private pTestArray as Variant

Public Property Let TestArray(ByVal iTestArray as Variant)
pTestArray = iTestArray
ShiftArray
End Property
Public Property Get TestArray() as Variant
TestArray = pTestArray
End Property


Function ShiftArray

' Just mixes-up the array a little
Dim i As Integer
For i = 1 to 3
pTestArray(i - 1, 0) = pTestArray(i, 0)
Next i

End Function

In a non-Class module...

Sub Test
Dim i As Integer
Dim MyArray(3, 1) as Variant
Dim MyArray2 as Variant
Dim ThisTest as cArrayClass
Set ThisTest = New cArrayClass

MyArray(0, 0) = 1
MyArray(0, 1) = 2
MyArray(1, 0) = 3
MyArray(1, 1) = 4

ThisTest.TestArray = MyArray
MyArray2 = ThisTest.TestArray
' !!! NOTE: MyArray can not accept ThisTest.TestArray !!!

' Swap the array back in element-by-element
For i = LBound(MyArray2) to UBound(MyArray2)
MyArray(i, 0) = MyArray2(i, 0)
MyArray(i, 1) = MyArray2(i, 1)
Next i

For i = LBound(MyArray) to UBound(MyArray)
Msgbox MyArray(i, 0) & ", " & MyArray(i, 1)
Next i

End Sub

(Please excuse any typos - I re-entered and edited this (to provide a
decent example) by hand while looking at another computer. I'm too
tired to plug into my network and map drives right now. I know - this
sounds silly :-))

So, if you have a better way to do this I'm all ears (or eyes as the
case may be).

Thanks Bob!!

Trip



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 88
Default Multidimensional Arrays as Properties in Class Files?

Maybe using the Redim statement could help. Without changing the class
module at all I got this to run (no idea if it gave me the desired
results <g).

Sub Test()
Dim i As Integer
Dim MyArray() As Variant
Dim ThisTest As cArrayClass
Set ThisTest = New cArrayClass

ReDim MyArray(3, 1)
MyArray(0, 0) = 1
MyArray(0, 1) = 2
MyArray(1, 0) = 3
MyArray(1, 1) = 4

ThisTest.TestArray = MyArray
ReDim MyArray(3, 1)
MyArray = ThisTest.TestArray

For i = LBound(MyArray) To UBound(MyArray)
MsgBox MyArray(i, 0) & ", " & MyArray(i, 1)
Next i

End Sub

Hope this helps
Rowan

Trip wrote:
Bob,

You are correct in your understanding. Unfortunately, it is I who has
a lack of understanding. Would you be able to provide me an example of
how to swap a whole array with indexes out of AND into a class. I'm
not able to find a way to do both while maintaining the indicies.

This is how I am doing it right now...

In the Class Module cArrayClass...

Private pTestArray as Variant

Public Property Let TestArray(ByVal iTestArray as Variant)
pTestArray = iTestArray
ShiftArray
End Property
Public Property Get TestArray() as Variant
TestArray = pTestArray
End Property


Function ShiftArray

' Just mixes-up the array a little
Dim i As Integer
For i = 1 to 3
pTestArray(i - 1, 0) = pTestArray(i, 0)
Next i

End Function

In a non-Class module...

Sub Test
Dim i As Integer
Dim MyArray(3, 1) as Variant
Dim MyArray2 as Variant
Dim ThisTest as cArrayClass
Set ThisTest = New cArrayClass

MyArray(0, 0) = 1
MyArray(0, 1) = 2
MyArray(1, 0) = 3
MyArray(1, 1) = 4

ThisTest.TestArray = MyArray
MyArray2 = ThisTest.TestArray
' !!! NOTE: MyArray can not accept ThisTest.TestArray !!!

' Swap the array back in element-by-element
For i = LBound(MyArray2) to UBound(MyArray2)
MyArray(i, 0) = MyArray2(i, 0)
MyArray(i, 1) = MyArray2(i, 1)
Next i

For i = LBound(MyArray) to UBound(MyArray)
Msgbox MyArray(i, 0) & ", " & MyArray(i, 1)
Next i

End Sub

(Please excuse any typos - I re-entered and edited this (to provide a
decent example) by hand while looking at another computer. I'm too
tired to plug into my network and map drives right now. I know - this
sounds silly :-))

So, if you have a better way to do this I'm all ears (or eyes as the
case may be).

Thanks Bob!!

Trip

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Multidimensional Arrays as Properties in Class Files?

My example did just that Trip. What I didn't do and I am maybe suggesting
that you do is to manipulate it in the module macro, although personally I
would keep it all in the class.

I will knock up a bigger example today if I get a chance and mail it to you.

--
HTH

Bob Phillips

"Trip" wrote in message
oups.com...
Bob,

You are correct in your understanding. Unfortunately, it is I who has
a lack of understanding. Would you be able to provide me an example of
how to swap a whole array with indexes out of AND into a class. I'm
not able to find a way to do both while maintaining the indicies.

This is how I am doing it right now...

In the Class Module cArrayClass...

Private pTestArray as Variant

Public Property Let TestArray(ByVal iTestArray as Variant)
pTestArray = iTestArray
ShiftArray
End Property
Public Property Get TestArray() as Variant
TestArray = pTestArray
End Property


Function ShiftArray

' Just mixes-up the array a little
Dim i As Integer
For i = 1 to 3
pTestArray(i - 1, 0) = pTestArray(i, 0)
Next i

End Function

In a non-Class module...

Sub Test
Dim i As Integer
Dim MyArray(3, 1) as Variant
Dim MyArray2 as Variant
Dim ThisTest as cArrayClass
Set ThisTest = New cArrayClass

MyArray(0, 0) = 1
MyArray(0, 1) = 2
MyArray(1, 0) = 3
MyArray(1, 1) = 4

ThisTest.TestArray = MyArray
MyArray2 = ThisTest.TestArray
' !!! NOTE: MyArray can not accept ThisTest.TestArray !!!

' Swap the array back in element-by-element
For i = LBound(MyArray2) to UBound(MyArray2)
MyArray(i, 0) = MyArray2(i, 0)
MyArray(i, 1) = MyArray2(i, 1)
Next i

For i = LBound(MyArray) to UBound(MyArray)
Msgbox MyArray(i, 0) & ", " & MyArray(i, 1)
Next i

End Sub

(Please excuse any typos - I re-entered and edited this (to provide a
decent example) by hand while looking at another computer. I'm too
tired to plug into my network and map drives right now. I know - this
sounds silly :-))

So, if you have a better way to do this I'm all ears (or eyes as the
case may be).

Thanks Bob!!

Trip



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
ReDim, Preserve and Multidimensional arrays Andy Westlake[_2_] Excel Programming 3 October 19th 04 07:04 PM
Declare Multidimensional Arrays Alan Beban[_3_] Excel Programming 3 August 21st 03 02:40 AM
Declare Multidimensional Arrays Alan Beban[_3_] Excel Programming 0 August 20th 03 07:03 PM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 3 August 11th 03 09:01 AM
Multidimensional Arrays - VBA Brent McIntyre Excel Programming 14 August 8th 03 10:49 PM


All times are GMT +1. The time now is 12:21 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"