|
 |
asp_databases thread: Order of items in querystring do not match the order of items written via For Each...Next loop
Message #1 by jmuldoon@q... on Tue, 28 Aug 2001 20:40:44
|
|
Problem is I am sending a querystring to an ASPMail form. The order that
the String items are sent is not the same order that The items are written
using a For Each...Next Loop.
Here's the querystring that the form sends. I put a break before each
ampersand just to make the order of the items immediately clear:
http://www.nonicnow.net/MinnCS/LimoMailSend.asp?
FirstName=Joe&
LastName=Muldoon
&EmailSddress=jGreg@q...
&PhoneNumber=612-823-3435
&Address=4322+Pearson+Avenue
&City=Minneapolis
&DateOfPickup=8%2F30
&TimeOfPickup=3+pm
&NumberOfPeople=6
&GoingTo=St.+Paul+Airport
&ExtraStops=Hilton
&Submit=Make+Your+Reservation
Here's a respose.write of what gets produced:
FirstName:
NumberOfPeople:
LastName:
PhoneNumber:
EmailSddress:
TimeOfPickup:
Address:
City:
DateOfPickup:
ExtraStops:
Submit:
GoingTo:
Here's the code:
For Each Item in Request.querystring
msgTxt = msgTxt & Item & ": <br> " & vbCrLf
' If Request.querystring(Item) = "" Then
' msgTxt = msgTxt & " NOTHING LISTED" & vbCrLf & vbCrLf
' Else
' msgTxt = msgTxt & " " & Request.querystring(Item) & vbCrLf
& vbCrLf
' End If
Next
response.write msgTxt
The stuff commented out doesn't affect the order. I pulled that out just
to clarify the order issue. If the value for each item is left in, the For
Each...Next loop still gets it wrong.
Will sure appreciate some help.
Thanks
Joe
Message #2 by "Ken Schaefer" <ken@a...> on Wed, 29 Aug 2001 13:34:18 +1000
|
|
Request.QueryString is a collection, not an array.
AFAIK, the best way to get things out of a collection is by key, not by
ordinal.
Request.QueryString("FirstName")
not
Request.QueryString(1)
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: <jmuldoon@q...>
To: "ASP Databases" <asp_databases@p...>
Sent: Tuesday, August 28, 2001 8:40 PM
Subject: [asp_databases] Order of items in querystring do not match the
order of items written via For Each...Next loop
: Problem is I am sending a querystring to an ASPMail form. The order that
: the String items are sent is not the same order that The items are written
: using a For Each...Next Loop.
:
: Here's the querystring that the form sends. I put a break before each
: ampersand just to make the order of the items immediately clear:
:
: http://www.nonicnow.net/MinnCS/LimoMailSend.asp?
:
: FirstName=Joe&
:
: LastName=Muldoon
:
: &EmailSddress=jGreg@q...
:
: &PhoneNumber=612-823-3435
:
: &Address=4322+Pearson+Avenue
:
: &City=Minneapolis
:
: &DateOfPickup=8%2F30
:
: &TimeOfPickup=3+pm
:
: &NumberOfPeople=6
:
: &GoingTo=St.+Paul+Airport
:
: &ExtraStops=Hilton
:
: &Submit=Make+Your+Reservation
:
:
: Here's a respose.write of what gets produced:
:
:
: FirstName:
: NumberOfPeople:
: LastName:
: PhoneNumber:
: EmailSddress:
: TimeOfPickup:
: Address:
: City:
: DateOfPickup:
: ExtraStops:
: Submit:
: GoingTo:
:
:
: Here's the code:
:
:
: For Each Item in Request.querystring
: msgTxt = msgTxt & Item & ": <br> " & vbCrLf
:
: ' If Request.querystring(Item) = "" Then
: ' msgTxt = msgTxt & " NOTHING LISTED" & vbCrLf & vbCrLf
: ' Else
: ' msgTxt = msgTxt & " " & Request.querystring(Item) & vbCrLf
: & vbCrLf
: ' End If
: Next
: response.write msgTxt
:
: The stuff commented out doesn't affect the order. I pulled that out just
: to clarify the order issue. If the value for each item is left in, the For
: Each...Next loop still gets it wrong.
:
: Will sure appreciate some help.
:
: Thanks
:
: Joe
Message #3 by Steve Carter <Steve.Carter@t...> on Wed, 29 Aug 2001 09:48:36 +0100
|
|
Ken: But a for-each is a collection-style construct!
Joe: It's true, the collection does not necessarily preserve order.
Microsoft's Dictionary and various Collections are not very consistent
in
this matter either.
A construct I someitmes use if order is important is to name all the
fields
like this:
for each strField in split("FirstName LastName EmailAddress PhoneNumber
Address City DateOfPickup TimeOfPickup NumberOfPeople GoingTo
ExtraStops
Submit")
response.write mycollection(strField)
next
In this case, the split is an array and order is preserved.
HTH
Steve
> :
> : &EmailSddress=3DjGreg@q...
> :
> : &PhoneNumber=3D612-823-3435
> :
> : &Address=3D4322+Pearson+Avenue
> :
> : &City=3DMinneapolis
> :
> : &DateOfPickup=3D8%2F30
> :
> : &TimeOfPickup=3D3+pm
> :
> : &NumberOfPeople=3D6
> :
> : &GoingTo=3DSt.+Paul+Airport
> :
> : &ExtraStops=3DHilton
> :
> : &Submit=3DMake+Your+Reservation
To:
> -----Original Message-----
> From: Ken Schaefer [mailto:ken@a...]
> Sent: 29 August 2001 04:34
> To: ASP Databases
> Subject: [asp_databases] Re: Order of items in querystring do
> not match
> the order of items written via For Each...Next loop
>
>
> Request.QueryString is a collection, not an array.
> AFAIK, the best way to get things out of a collection is by
> key, not by
> ordinal.
>
> Request.QueryString("FirstName")
> not
> Request.QueryString(1)
>
> Cheers
> Ken
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> From: <jmuldoon@q...>
> To: "ASP Databases" <asp_databases@p...>
> Sent: Tuesday, August 28, 2001 8:40 PM
> Subject: [asp_databases] Order of items in querystring do not
> match the
> order of items written via For Each...Next loop
>
>
> : Problem is I am sending a querystring to an ASPMail form.
> The order that
> : the String items are sent is not the same order that The
> items are written
> : using a For Each...Next Loop.
> :
> : Here's the querystring that the form sends. I put a break
> before each
> : ampersand just to make the order of the items immediately clear:
> :
> : http://www.nonicnow.net/MinnCS/LimoMailSend.asp?
> :
> : FirstName=3DJoe&
> :
> : LastName=3DMuldoon
> :
> : &EmailSddress=3DjGreg@q...
> :
> : &PhoneNumber=3D612-823-3435
> :
> : &Address=3D4322+Pearson+Avenue
> :
> : &City=3DMinneapolis
> :
> : &DateOfPickup=3D8%2F30
> :
> : &TimeOfPickup=3D3+pm
> :
> : &NumberOfPeople=3D6
> :
> : &GoingTo=3DSt.+Paul+Airport
> :
> : &ExtraStops=3DHilton
> :
> : &Submit=3DMake+Your+Reservation
> :
> :
> : Here's a respose.write of what gets produced:
> :
> :
> : FirstName:
> : NumberOfPeople:
> : LastName:
> : PhoneNumber:
> : EmailSddress:
> : TimeOfPickup:
> : Address:
> : City:
> : DateOfPickup:
> : ExtraStops:
> : Submit:
> : GoingTo:
> :
> :
> : Here's the code:
> :
> :
> : For Each Item in Request.querystring
> : msgTxt =3D msgTxt & Item & ": <br> " & vbCrLf
> :
> : ' If Request.querystring(Item) =3D "" Then
> : ' msgTxt =3D msgTxt & " NOTHING LISTED" & vbCrLf &
vbCrLf
> : ' Else
> : ' msgTxt =3D msgTxt & " " &
> Request.querystring(Item) & vbCrLf
> : & vbCrLf
> : ' End If
> : Next
> : response.write msgTxt
> :
> : The stuff commented out doesn't affect the order. I pulled
> that out just
> : to clarify the order issue. If the value for each item is
> left in, the For
> : Each...Next loop still gets it wrong.
> :
> : Will sure appreciate some help.
> :
> : Thanks
> :
> : Joe
>
>
Message #4 by jmuldoon@q... on Wed, 29 Aug 2001 18:01:08
|
|
Ken and Steve:
First of all, thanks much. Just getting the info about the order of items
in the collection keeps me from searching for answers in the wrong places.
Perhaps it was obvious that I was looking for an easy solution: being able
to add items to a form without having to add them to the reponse file.
(This would have been especially nice, since I have two forms using this
ASPMail object).
However, I'll go with Steve's idea and see what happens. Steve, I looked
up the split function, which I really haven't used before but has come up
twice in examples I've used in the past week. I see that the space
character is the default delimiter.
Would I be able to do an alphabetical sort of the array items if I used
and a-, b-, c-, etc preface for each form item?
Well, that's just a detail. I'll proceed with the Steve method, using an
If statement to choose which split to use.
A big help you were.
Joe
> Ken: But a for-each is a collection-style construct!
>
> Joe: It's true, the collection does not necessarily preserve order.
> Microsoft's Dictionary and various Collections are not very consistent
> in
> this matter either.
>
> A construct I someitmes use if order is important is to name all the
> fields
> like this:
>
> for each strField in split("FirstName LastName EmailAddress PhoneNumber
> Address City DateOfPickup TimeOfPickup NumberOfPeople GoingTo
> ExtraStops
> Submit")
> response.write mycollection(strField)
> next
>
> In this case, the split is an array and order is preserved.
>
> HTH
>
> Steve
>
>
> > :
> > : &EmailSddress=3DjGreg@q...
> > :
> > : &PhoneNumber=3D612-823-3435
> > :
> > : &Address=3D4322+Pearson+Avenue
> > :
> > : &City=3DMinneapolis
> > :
> > : &DateOfPickup=3D8%2F30
> > :
> > : &TimeOfPickup=3D3+pm
> > :
> > : &NumberOfPeople=3D6
> > :
> > : &GoingTo=3DSt.+Paul+Airport
> > :
> > : &ExtraStops=3DHilton
> > :
> > : &Submit=3DMake+Your+Reservation
>
> To:
>
> > -----Original Message-----
> > From: Ken Schaefer [mailto:ken@a...]
> > Sent: 29 August 2001 04:34
> > To: ASP Databases
> > Subject: [asp_databases] Re: Order of items in querystring do
> > not match
> > the order of items written via For Each...Next loop
> >
> >
> > Request.QueryString is a collection, not an array.
> > AFAIK, the best way to get things out of a collection is by
> > key, not by
> > ordinal.
> >
> > Request.QueryString("FirstName")
> > not
> > Request.QueryString(1)
> >
> > Cheers
> > Ken
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > From: <jmuldoon@q...>
> > To: "ASP Databases" <asp_databases@p...>
> > Sent: Tuesday, August 28, 2001 8:40 PM
> > Subject: [asp_databases] Order of items in querystring do not
> > match the
> > order of items written via For Each...Next loop
> >
> >
> > : Problem is I am sending a querystring to an ASPMail form.
> > The order that
> > : the String items are sent is not the same order that The
> > items are written
> > : using a For Each...Next Loop.
> > :
> > : Here's the querystring that the form sends. I put a break
> > before each
> > : ampersand just to make the order of the items immediately clear:
> > :
> > : http://www.nonicnow.net/MinnCS/LimoMailSend.asp?
> > :
> > : FirstName=3DJoe&
> > :
> > : LastName=3DMuldoon
> > :
> > : &EmailSddress=3DjGreg@q...
> > :
> > : &PhoneNumber=3D612-823-3435
> > :
> > : &Address=3D4322+Pearson+Avenue
> > :
> > : &City=3DMinneapolis
> > :
> > : &DateOfPickup=3D8%2F30
> > :
> > : &TimeOfPickup=3D3+pm
> > :
> > : &NumberOfPeople=3D6
> > :
> > : &GoingTo=3DSt.+Paul+Airport
> > :
> > : &ExtraStops=3DHilton
> > :
> > : &Submit=3DMake+Your+Reservation
> > :
> > :
> > : Here's a respose.write of what gets produced:
> > :
> > :
> > : FirstName:
> > : NumberOfPeople:
> > : LastName:
> > : PhoneNumber:
> > : EmailSddress:
> > : TimeOfPickup:
> > : Address:
> > : City:
> > : DateOfPickup:
> > : ExtraStops:
> > : Submit:
> > : GoingTo:
> > :
> > :
> > : Here's the code:
> > :
> > :
> > : For Each Item in Request.querystring
> > : msgTxt =3D msgTxt & Item & ": <br> " & vbCrLf
> > :
> > : ' If Request.querystring(Item) =3D "" Then
> > : ' msgTxt =3D msgTxt & " NOTHING LISTED" & vbCrLf &
> vbCrLf
> > : ' Else
> > : ' msgTxt =3D msgTxt & " " &
> > Request.querystring(Item) & vbCrLf
> > : & vbCrLf
> > : ' End If
> > : Next
> > : response.write msgTxt
> > :
> > : The stuff commented out doesn't affect the order. I pulled
> > that out just
> > : to clarify the order issue. If the value for each item is
> > left in, the For
> > : Each...Next loop still gets it wrong.
> > :
> > : Will sure appreciate some help.
> > :
> > : Thanks
> > :
> > : Joe
> >
Message #5 by "Ken Schaefer" <ken@a...> on Thu, 30 Aug 2001 18:30:10 +1000
|
|
That's right - but the original poster is trying to impose some kind of
arbitrary order on the keys of the collection. My understanding of
collections (and I'm happy to be corrected) is that they are best accessed
by key name, and not by relying on the ordinal position of the keys...
Cheers
Ken
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----- Original Message -----
From: "Steve Carter" <Steve.Carter@t...>
To: "ASP Databases" <asp_databases@p...>
Sent: Wednesday, August 29, 2001 6:48 PM
Subject: [asp_databases] Re: Order of items in querystring do not matc h the
order of items written via For Each...Next loop
Ken: But a for-each is a collection-style construct!
Message #6 by "Hasenfratz, Philipp" <maillist@e...> on Thu, 30 Aug 2001 10:30:04 +0200
|
|
> That's right - but the original poster is trying to impose some kind of
> arbitrary order on the keys of the collection. My understanding of
> collections (and I'm happy to be corrected) is that they are best accessed
> by key name, and not by relying on the ordinal position of the keys...
The ordinal access to collections is just made to easier browse through a
whole collection (for - loop). But to get a spcified name-value of a
collection, as Ken said, is to access it by the key of the record!
---Philipp
Message #7 by Steve Carter <Steve.Carter@t...> on Thu, 30 Aug 2001 09:51:17 +0100
|
|
> Would I be able to do an alphabetical sort of the array items
> if I used
> and a-, b-, c-, etc preface for each form item?
Yes, I was going to suggest naming the fields on the form 01firstname
02lastname etc, but realised that you would then have to write your own sort
routine. May well be worth doing though to make it really easy to add new
form elements.
Another consideration is to start them all with a key couple of letters,
such as db (for database), and then in the foreach use
if instr(name,"db")=1 then ' do stuff
this means that when you later decide you want a hidden field that does not
get, e.g. stored in the db, then you can add it without the db preceding it.
Message #8 by Steve Carter <Steve.Carter@t...> on Thu, 30 Aug 2001 09:52:32 +0100
|
|
> That's right - but the original poster is trying to impose
> some kind of arbitrary order on the keys of the collection. My
understanding of
> collections (and I'm happy to be corrected)
Point taken :-)
No corrections offered :-))
Message #9 by jmuldoon@q... on Fri, 31 Aug 2001 02:32:43
|
|
Steve:
The sort routine sounds like something I should look into. Can you give
some ideas about the kinds of objects and scripting I should look into to
accomplish this? Thanks
Joe
> > Would I be able to do an alphabetical sort of the array items
> > if I used
> > and a-, b-, c-, etc preface for each form item?
>
> Yes, I was going to suggest naming the fields on the form 01firstname
> 02lastname etc, but realised that you would then have to write your own
sort
> routine. May well be worth doing though to make it really easy to add
new
> form elements.
>
> Another consideration is to start them all with a key couple of letters,
> such as db (for database), and then in the foreach use
>
> if instr(name,"db")=1 then ' do stuff
>
> this means that when you later decide you want a hidden field that does
not
> get, e.g. stored in the db, then you can add it without the db preceding
it.
>
|
|
 |