Array Issues!

TKnight

Registered User.
Local time
Today, 09:37
Joined
Jan 28, 2003
Messages
181
Hi, I've written some VB to automate the sending of reports from a DB using GroupWise. The actual class module that creates the mail is over 1000 lines which I got off the net somwhere and managed to intergrate into my Db. It is then called and defined in another module. It worked fine for a while but a problem with the array that contains the recipients has appeared. I've never worked with arrays before and have a pretty limited knowledge of them.

In the class module is:

Private mastrRecTo() As String
'mastrRecTo(0, i)=address; mastrRecTo(1, i)=display name

In the modlue that calls the class is

Dim strRecTo(1, 0) As String

If I add addresses like this:

strRecTo(0, 0) = "tknight@hillingdon.gov.uk"
strRecTo(1, 0) = "tknighttest@hillingdon.gov.uk"

it works fine. The thing is that I need the reports go to different amounts of people (from 1 to 7 addresses). For this reason I decided to set up a loop to run through a recipient recordset and add each recipient one at a time.

While Not ToRecRst.EOF
strRecTo(n, 0) = ToRecRst.[E-Mail]
n = n + 1
ToRecRst.MoveNext
Wend

This also works but in order to accommodate the maximum number of recipients I need to set the array to 7. When the amount of recipients is less than 7 I get an error and the e-mails won't be sent. I tried defining the array with a variable for each set of reports:
Dim strRecTo(n, 0) As String
but i get an error message saying that the array value has to be constant. Can anyone help me get round the problem? Thanks, Tom.
 
You need to ReDim your array (not too sure on this myself, but I'll give it a try...)

First, when you declare your array you musn't put in any bounds:

Dim strRecTo()

Then if you ever want to redimension your array you use the redim statement:

Redim strRecTo(n,1)

Note: I thought I read somewhere that you could only redim the last value in an array [i.e Redim strRecTo(1,n)] but I've just tried it and it seemed to work fine when resizing the first value.

When you use the ReDim function the existing values in the array are cleared. If you want to keep these values (i.e if you are redimensioning in a loop) you will need to use the preserve function:

ReDim Preserve strRecTo(n,1)


Hope this helps....

Jordan
 

Users who are viewing this thread

Back
Top Bottom