homepage Welcome to WebmasterWorld Guest from 54.198.130.203
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

    
for each... statement
I know I've done this before?
too much information




msg:941238
 11:42 pm on Jul 30, 2003 (gmt 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!

 

smokin




msg:941239
 12:08 am on Jul 31, 2003 (gmt 0)

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

For i=0 To Ubound(MyArray)

'test to see if checkbox selected

Next

too much information




msg:941240
 12:20 pm on Jul 31, 2003 (gmt 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! ;)

ziggystardust




msg:941241
 1:02 pm on Jul 31, 2003 (gmt 0)

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

//ZS

aspdaddy




msg:941242
 1:10 pm on Jul 31, 2003 (gmt 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

thomis




msg:941243
 6:15 pm on Jul 31, 2003 (gmt 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.

gangstah




msg:941244
 9:42 pm on Jul 31, 2003 (gmt 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.

gangstah




msg:941245
 9:44 pm on Jul 31, 2003 (gmt 0)

Oh...and no, I don't think this works with arrays because an array is not a collection.

too much information




msg:941246
 2:48 am on Aug 1, 2003 (gmt 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! ;)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved