Build array from Loop

NickJPhillips
NickJPhillips used Ask the Experts™
on
In another post (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/ASP/Q_22522448.html) I was looking for a method to choose 5 (at random) sections/units/groups, etc.. from my company for every day specified between two dates.  In simplest terms this could be thought of as creating a "chore list" ... Choose 5 groups for MOnday, Tuesday, Wednesday, etc... each group is responsible for doing something..

I solved it by creating a nested loop...
FOR start date TO end date                  <-------------LOOP 1, for each day
     For 1 to 5                                         <-------------LOOP 2, Get a group a random and then e-mail them
          Call randomizer Function
          Now e-mail Group Leader    <---------Build array here(see question below)
     NEXT
NEXT

However, sending out an e-mail every time the loop cycles is NOT the best method for doing this..I just needed to get a "workable" solution up and running to keep the boss happy. What I would like to do is to build a list/array of e-mail addresses and then send them all out at once...

Thoughts on how I can do this... build the array, and then when the loops are complete...use it in my e-mail function and then dump it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Something like:
FOR start date TO end date                 ' <-------------LOOP 1, for each day
     For 1 to 5                                        ' <-------------LOOP 2, Get a group a random and then e-mail them
          Call randomizer Function
          addresses = addresses & groupleaderaddress & "," ' <---------Build array here(see question below)
     NEXT
NEXT
addresses=left(addresses,len(addresses)-1)

Then just send to addresses.
Top Expert 2007
Commented:
For 1 to 5                                         <-------------LOOP 2, Get a group a random and then e-mail them
          Call randomizer Function
          sendto = sento & somemailaddress & ";"  'build string of emails with semicolon
     NEXT
         Now e-mail Group Leader  as BCC  <---------SEND HERE

Author

Commented:
Thanks, but I cant build the list inside the loop, because the loop will only return ONE address...so each time the loop hits, I need to add the e-mail address to the bottom of an array, and then use the array to send... BUT I have a large kryptonite type weakness called "arrays".... I have a really hard time "seeing" what I am doing and thinking 2/3 dimensionally....

I can assume that I can create the array BEFORE the loop(s) start, and then each time the inner loop fires, redim the array and add a new e-mail address to it...

I am looking for thoughts on whether this will work, and maybe some pointers on how I can code it...
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

Top Expert 2007

Commented:
"because the loop will only return ONE address"

So why are you looping 5 times then (For 1 to 5) if only have ONE email.

This doesn't make sense.  Both ddrudik and I provided essentially the same answer, because that is what works.

You DON'T even need arrays for this.
ThinkPaperIT Consultant

Commented:
the experts are correct.. you don't have to use an array
to clarify.. if you're still confused.. you can create 1 string that is initially blank and loop thru the for loop and append email addresses to it (separated by a comma) and then at the end send an email to the string.

Author

Commented:
YEs, I was still confused! But I couldnt see the forrest for the trees.... LOL, sometimes I overthink things. I have split the points between ddrudik and golfDoctor... I gave more points to ddrudik for answering first. Thank you to all... I am going to go bank my head on a wall for turning something so simple into a real pain-in-the-rear!!

Thanks!
Thanks for the question and the points.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial