Welcome to WebmasterWorld Guest from 23.23.53.177

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)

WebmasterWorld Senior Member 10+ Year Member



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 Jul 31, 2003 (gmt 0)

10+ Year Member



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

For i=0 To Ubound(MyArray)

'test to see if checkbox selected

Next

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

WebmasterWorld Senior Member 10+ Year Member



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 Jul 31, 2003 (gmt 0)

10+ Year Member



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

//ZS

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

WebmasterWorld Senior Member 10+ Year Member



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 Jul 31, 2003 (gmt 0)

10+ Year Member



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 Jul 31, 2003 (gmt 0)

10+ Year Member



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 Jul 31, 2003 (gmt 0)

10+ Year Member



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)

WebmasterWorld Senior Member 10+ Year Member



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! ;)