Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Loop w/ Variables

Status
Not open for further replies.

lahddah

Programmer
Jan 2, 2003
109
US
Hi, can someone tell my why the following code populates the 'EmailRecipient' field with only the content of 'i'?

-------------

for i=1 to 4
EmailRecipient = request("EmailRecipient")

EmailRecipient = EmailRecipient & i ' required

i = i + 1
'
'
'

next

--------------

This is a portion of an email a friend page with several entries for recipients and their email addresses. 'EmailRecipient' is supposed to contain the email address of each of the entries.

~ lahddah
 
Because request("EmailRecipient") is empty, I'd guess. Also, manipulating your for-next counter can mess you up if you're not careful... do you mean to increment it, even though the loop will increment it for you?

It's better to be more specific about what request item you're looking for, in your case either Request.Form("EmailRecipient") or Request.QueryString("EmailRecipient").

Note, too, that at the beginning of your loop you're destroying any previous value of the variable EmailRecipient (no concatenation there). That may be intentional, too, but I thought I'd point it out just in case.
 
Thanks Genimouse. I know that the fields are populated - so I knew that wasn't the case. I added the increment in there for testing only, just to see if that would work. I've removed that now.

What I've come up with is this, I need the EmailRecipient variable to = the field name 'EmailRecipient' with the number after it. In other words, the field names on the form that will contain the email addresses are named:
EmailRecipient1
EmailRecipient2
EmailRecipient3
EmailRecipient4

And I need the same email sent to all four people separately.

Here's the line in question -
EmailRecipient = request.Form("EmailRecipient")

I need the request.Form to look at "EmailRecipient1"
through the first loop, then "EmailRecipient2" in the second round...and so on...

Suggestions?

~ lahddah
 
I think you mean this?

Code:
For i = 1 To 4
  EmailRecipient = Request.Form("EmailRecipient" & CStr(i))

  If EmailRecipient <> "" Then
    'Send email to EmailRecipient here
  End If
Next

--James
 
Thanks, JamesLean! That worked perfectly.

Thanks for you help.



~ lahddah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top