Welcome to WebmasterWorld Guest from 54.167.83.224

Forum Moderators: ocean10000

Message Too Old, No Replies

for each... statement

I know I've done this before?

     
11:42 pm on Jul 30, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 16, 2003
posts:897
votes: 0


I'm really drawing a blank right now. I know I have used a 'for' statement before to process a form, something like:

for each variable_name
...
next

what's the syntax if I have several check boxes named the same thing in a form, and I need to process however many that my user checks off.

Thanks! I'm having a real brain cloud!

12:08 am on July 31, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:July 3, 2002
posts:82
votes: 0


MyArray = Split(Request.Form("radioButtonName", ",")

For i=0 To Ubound(MyArray)

'test to see if checkbox selected

Next

12:20 pm on July 31, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 16, 2003
posts:897
votes: 0


that could work. Thanks for the help.

For some reason I was not able to find any code where I had done this before. I guess I have too much code now! ;)

1:02 pm on July 31, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Jan 19, 2003
posts:65
votes: 0


For Each MyCheckBox In MyArray
' Do whatever you need to do on MyCheckBox
Next

//ZS

1:10 pm on July 31, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 13, 2002
posts:2162
votes: 0


Never seen that method before. Does a for..each work with arrays?

Smokins way is the one i'd use for this.

The way to process form collections in a for..each is :

for each control in request.form

// name
response.write control

// value
response.write request(control)

next

6:15 pm on July 31, 2003 (gmt 0)

New User

10+ Year Member

joined:July 31, 2003
posts:3
votes: 0


This is slightly off-topic, but remember that when you look at the contents of the request object, order is unreliable. ie:

i = 0
For each Item In Request.Form
i = i + 1

'***DON'T DO THIS ***
Response.Write(Request.Form.Key(Item) & " " & Request.Form(Item) & "<br>")

'***DO THIS INSTEAD ***
Response.Write(Request.Form.Key(i) & " " & Request.Form(Request.Form.Key(i)) & "<br>")
Next

Or you'll get mismatched name/value pairs.

9:42 pm on July 31, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:July 18, 2003
posts:43
votes: 0


For...Each works with collections and the items that make up those collections. For instance:

'' oField will be an instance 

'' of the Fields collection

For Each oField In oRecordset.Fields

Response.Write oField.Name & "<br>"

Next

Hope that helps.

9:44 pm on July 31, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:July 18, 2003
posts:43
votes: 0


Oh...and no, I don't think this works with arrays because an array is not a collection.
2:48 am on Aug 1, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:June 16, 2003
posts:897
votes: 0


aspdaddy, that's exactly what I was looking for! You ROCK!

I knew I had seen that before I just couldn't find it in my piles of code. I guess I need to find a way to search my drive for statements and other cool things that my wife doesn't really want to know about! ;)

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members