Need help with algorithm

# Thread: Need help with algorithm

1. Senior Member
Join Date
Dec 1969
Posts
2,092

## Need help with algorithm

I have this array that can hold any numbers of records(for example: 29 or 129 or 150 or 2347 or 5896 or ...)<BR><BR>Now I need to send an email each time the loop of my array is a factor of 50.<BR><BR>The thing is if the array contains less records then 50 I need to send an email according to that number.<BR><BR>On the other hand if the array is larger then 50(for example 129) I need to send 3 times 50 emails and one time 29 emails<BR><BR>What would be my algorithm<BR><BR>Sincerely<BR>Vlince

2. Member
Join Date
Dec 1969
Posts
61

## Is this a test?

Simple math:<BR>numofelts = UBound(yourarray)<BR>If numofelts &#060; 50 Then<BR> numofemails = 1<BR>Else<BR> numofemails = numofelts/50<BR> remainder = numofelts Mod 50<BR> If remainder &#060;&#062; 0 Then<BR> numofemails = numofemails + 1<BR> End If<BR>End If<BR><BR>I think that&#039;ll work for you.

3. Senior Member
Join Date
Dec 1969
Posts
96,118

## 1...2...3...1...2...3...1...2...3...

That&#039;s a nice waltz all-go rhythm.<BR><BR>Oh, okay...<BR><BR>MOD. Look up the MOD operator in the VBScript reference.<BR><BR>And I sure *HOPE* you don&#039;t mean what you wrote:<BR> if the array is larger then 50(for example 129) <BR> I need to send 3 times 50 emails and one time 29 emails<BR><BR>Ummm...50 + 50 + 50 + 29 is 179 on my fingers and toes (I have lots of toes).<BR><BR>Anyway:<BR><BR>I presume the point of this is to send email to no more than 50 addresses at a time?<BR><BR>&#060;%<BR>addresses = ... an array of unknown size ...<BR><BR>For i = 0 To UBound( addresses )<BR> If (i MOD 50) = 0 Then &#039; every 50 addresses<BR> If i &#060;&#062; 0 Then &#039; (don&#039;t send if no addresses yet)<BR> objMail.to = Mid( ccs, 2 )<BR> objMail.Send &#039; send last mail<BR> End If<BR> Set objMail = ... &#039; create another email object<BR> &#039; (Note: May be able to reuse same one; depends on object)<BR> ccs = "" &#039; start with no addresses<BR> End If<BR> ccs = ccs & ";" & addresses(i) &#039; tack on an address<BR>Next<BR>&#039; clean up last group, if any...<BR>If ccs &#060;&#062; "" Then<BR> objMail.to = Mid( ccs, 2 )<BR> objMail.Send &#039; send last mail<BR>End If<BR>%&#062;<BR><BR>The Mid( ccs, 2 ) is so that you chop off the semicolon before the first name.<BR><BR><BR><BR><BR><BR>

4. Senior Member
Join Date
Dec 1969
Posts
96,118

## Extra code in that...and bug

numofelts = UBound(yourarray)<BR>numofemails = numofelts[hl="yellow"] [/hl]50 &#039; needs INTEGER division<BR>remainder = numofelts Mod 50<BR>If remainder &#060;&#062; 0 Then<BR> numofemails = numofemails + 1<BR>End If<BR><BR>YOu did ordinary division, so if there were 129 addresses, your numofelts would end up being 3.58 ... say oops.<BR><BR>The backslash operator in VBScript does integer division and tosses the remainder away.<BR><BR>And why bother for a test for less than 50? The code works fine, without that test.<BR><BR>

5. Member
Join Date
Dec 1969
Posts
61

## that popping sound is my foot coming out of my mou

You&#039;re absolutely right. I keep trying, and you keep teaching me how to do it better. Maybe I should stick to asking questions...

6. Senior Member
Join Date
Dec 1969
Posts
2,092

## Thank you thank you

I knew I could count on you Bill<BR><BR>I owe you one :)<BR><BR>Sincerely Thanks<BR>Vlince

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## Nonsense! Yours was better!

8. Senior Member
Join Date
Dec 1969
Posts
96,118

## Yeah, but look at Neophyte's...

...start on the code and how clean the final solution from that is. Simpler than this sub-thread, by far.<BR><BR>

9. Member
Join Date
Dec 1969
Posts
61

## nice code, slick stuff

thanks for the vote of confidence

10. Senior Member
Join Date
Dec 1969
Posts
2,092

## Sorry neophyte

I did forget to thank you for your input<BR><BR>It is not like me to forget :(<BR><BR>I&#039;ll remember!<BR><BR>Many thanks neophyte <BR>Sincerely<BR><BR>Vlince

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•