Counting elements in array?

# Thread: Counting elements in array?

1. Senior Member
Join Date
Dec 1969
Posts
310

## Counting elements in array?

I have an ecards site. <BR><BR>Users can enter multiple email addresses when sending their ecards, I then load the value of the recipients_email into an array and loop through it to send the email to say they&#039;ve got an ecard:<BR><BR>myArray = Split(Request("Recipients_Email"),",")<BR>For iy = 0 To UBound(myArray)<BR>Recipient = myArray(iy)<BR> send email to Recipient<BR>Next<BR><BR>But what I was after was a way to count the elements in myArray so I can limit the multiple email addresses to say 5, so stop people adding in loads of email addresses. <BR><BR>So I could do something, to paraphrase: <BR><BR>DO WHILE no_email_addresses &#060; 5<BR>email loop etc. <BR><BR>Can this be done? <BR><BR>Thanks<BR><BR>Jim

2. Senior Member
Join Date
Dec 1969
Posts
946

## RE: Counting elements in array?

So you just want to limit 5 elements of your array to be sent? Yes, then just do a loop that allows 5 slots. So a loop from 0 to 4. Or like you wrote, &#060; 5<BR><BR>Did you try this? Did it work? So you would have 2 loops? I not 100% sure with the question I guess.<BR><BR>-Vadim C.

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

## Several ways...

...but the easiest one is surely this:<BR><BR>&#060;%<BR>...<BR>myArray = Split(Request("Recipients_Email"),",")<BR>emax = UBound(myArray)<BR>If emax &#062; 4 Then emax = 4<BR>For iy = 0 To emax<BR>&nbsp; &nbsp; Recipient = myArray(iy)<BR>&nbsp; &nbsp; ... send email to Recipient ...<BR>Next<BR>...<BR>%&#062;<BR><BR>Why work harder than that?<BR><BR><BR>

#### Posting Permissions

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