LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Problem with 2-dimensional array

Public Function Addresses()
Dim ol As Object
Dim olns As Object
Dim objFolder As Object
Dim objAllContacts As Object
Dim Contact As Object
Dim MyAddressAs String
Dim ContactArray as Variant

Set ol = New Outlook.Application


Set olns = ol.GetNamespace("MAPI")


Set MyFolder1 = olns.Folders("Public Folders")
Set MyFolder2 = MyFolder1.Folders("All Public Folders")
Set MyFolder3 = MyFolder2.Folders("MyPublicFolder")


Set objAllContacts = MyFolder3.Items


Dim TotalCount, Counter As Long
TotalCount = MyFolder3.Items.Count


Counter = 1
ReDim ContactArray(0 to 1, 0 to counter)


For Each Contact In objAllContacts


ReDim Preserve ContactArray(0 to 1, 0 to Contact)


MyAddress= Contact.BusinessAddressStreet + ", " +
Contact.BusinessAddressPostalCode + " " + Contact.BusinessAddressCity
ContactArray(0, Counter) = Contact.CompanyName
ContactArray(1, Counter) = MyAddress


Counter = Counter + 1
Next Contact


CForm.MyListBox.ColumnCount = 2
CForm.MyListBox.Column = ContactArray


End Function

--
Regards,
Tom Ogilvy


" wrote:


Somehow I don't get it to work.
I want to use an array because I also want to be able to sort the list.


NickHK schreef:

You can only "Preserve" something that you have previously ReDimmed
So
ReDim ContactArray(1, 1) As Variant
ReDim Preserve ContactArray(1, 1) As Variant

But as Tom says, why not populate the list box directly and forget the array
?

NickHK


egroups.com...
This gives me the same error.
Am I missing something here?

NickHK schreef:

Because using Preserve you can only resize the last dimension. (Missed
that
in the post.)
So you would have to rotate your array and use:
ReDim Preserve ContactArray(1,Counter) As Variant

NickHK


groups.com...
If I use:
ReDim Preserve ContactArray(Counter, 1) As Variant

It'll give me an error about non-matching types.


Martin Brader schreef:

You need to add Preserve to your REDIM statement otherwise the array
is
reinitialised everytime you do a REDIM




 
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
3 dimensional array gti_jobert[_7_] Excel Programming 2 February 2nd 06 03:00 PM
Mutli-dimensional Array to Single-Dimension Array Blue Aardvark Excel Programming 3 October 15th 05 09:22 AM
Create One-Dimensional Array from Two-Dimensional Array Stratuser Excel Programming 1 February 23rd 05 08:46 PM
Problem with Multi-Dimensional Array Kirk[_2_] Excel Programming 2 August 26th 03 03:31 PM
2 Dimensional Array Tom Ogilvy Excel Programming 0 August 18th 03 08:04 PM


All times are GMT +1. The time now is 01:41 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"