By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,633 Members | 1,394 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,633 IT Pros & Developers. It's quick & easy.

Extract final field in row which has a value - an array issue perhaps?

P: n/a
Access 2000

I need some help interogatting a table and extracting via ASP the final
field in a row which has a value. In other words, I have a maximum of 10
fields but, at the user level he may he only enter values into the first
four. I need to ALWAYS extract the final or last field that has a value. In
the example below this would be PriceField5 which has a value of $162,000.

The user stopped at this field and left the rest blank.

I considered cycling through the row and checking for null or empty values
but I suspect this may be very messy and have not had much success in the
past. Is there a better more elegant way to achieve my goal?

--PRICE TABLE--
PriceField1 (eg 100,000)
PriceField2 (eg 130,000)
PriceField3 (eg 142,000)
PriceField4 (eg 152,000)
PriceField5 (eg 162,000)
PriceField6 (empty)
PriceField7 (empty)
PriceField8 (empty)
PriceField9 (empty)
PriceField10 (empty)

Many thanks in advance

Jason



Jul 19 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
I would think that looping would be okay for this. What are you trying to
do or why haven't you had luck with that?

Ray at work
"jason" <ja***@catamaranco.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
Access 2000

I need some help interogatting a table and extracting via ASP the final
field in a row which has a value. In other words, I have a maximum of 10
fields but, at the user level he may he only enter values into the first
four. I need to ALWAYS extract the final or last field that has a value. In the example below this would be PriceField5 which has a value of $162,000.

The user stopped at this field and left the rest blank.

I considered cycling through the row and checking for null or empty values but I suspect this may be very messy and have not had much success in the
past. Is there a better more elegant way to achieve my goal?

--PRICE TABLE--
PriceField1 (eg 100,000)
PriceField2 (eg 130,000)
PriceField3 (eg 142,000)
PriceField4 (eg 152,000)
PriceField5 (eg 162,000)
PriceField6 (empty)
PriceField7 (empty)
PriceField8 (empty)
PriceField9 (empty)
PriceField10 (empty)

Many thanks in advance

Jason


Jul 19 '05 #2

P: n/a
Well in the past I would try checking for null values and empty values eg
len(request.form.item("PriceField1"). But, I usually end up with longwinded
code. I thought perhaps there might be away to put the entire 10 fields into
an array and they cycle through them.......when you say loop through them I
am not even sure which convention to use or

rs.getrows ?
Do until rs.eof?

I am also not sure whether I should cycle all the form elements: eg:
request.form.item(i) or just do them individually?

At the risk of sounding lazy could you possibly submit an example of how you
would do it?

Many thanks
Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#F*************@TK2MSFTNGP10.phx.gbl...
I would think that looping would be okay for this. What are you trying to
do or why haven't you had luck with that?

Ray at work
"jason" <ja***@catamaranco.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
Access 2000

I need some help interogatting a table and extracting via ASP the final
field in a row which has a value. In other words, I have a maximum of 10
fields but, at the user level he may he only enter values into the first
four. I need to ALWAYS extract the final or last field that has a value.

In
the example below this would be PriceField5 which has a value of $162,000.
The user stopped at this field and left the rest blank.

I considered cycling through the row and checking for null or empty

values
but I suspect this may be very messy and have not had much success in the past. Is there a better more elegant way to achieve my goal?

--PRICE TABLE--
PriceField1 (eg 100,000)
PriceField2 (eg 130,000)
PriceField3 (eg 142,000)
PriceField4 (eg 152,000)
PriceField5 (eg 162,000)
PriceField6 (empty)
PriceField7 (empty)
PriceField8 (empty)
PriceField9 (empty)
PriceField10 (empty)

Many thanks in advance

Jason



Jul 19 '05 #3

P: n/a
Wait, are you talking about a recordset here or a form collection?

If form collection, there is no first and last. (Some would say the same
about columns in a database table as well, but that's all in how you
interpret things.)

Ray at work

"jason" <ja***@catamaranco.com> wrote in message
news:uD**************@TK2MSFTNGP10.phx.gbl...
Well in the past I would try checking for null values and empty values eg
len(request.form.item("PriceField1"). But, I usually end up with longwinded code. I thought perhaps there might be away to put the entire 10 fields into an array and they cycle through them.......when you say loop through them I am not even sure which convention to use or

rs.getrows ?
Do until rs.eof?

I am also not sure whether I should cycle all the form elements: eg:
request.form.item(i) or just do them individually?

At the risk of sounding lazy could you possibly submit an example of how you would do it?

Many thanks
Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#F*************@TK2MSFTNGP10.phx.gbl...
I would think that looping would be okay for this. What are you trying to
do or why haven't you had luck with that?

Ray at work
"jason" <ja***@catamaranco.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
Access 2000

I need some help interogatting a table and extracting via ASP the final field in a row which has a value. In other words, I have a maximum of 10 fields but, at the user level he may he only enter values into the first four. I need to ALWAYS extract the final or last field that has a
value. In
the example below this would be PriceField5 which has a value of

$162,000.
The user stopped at this field and left the rest blank.

I considered cycling through the row and checking for null or empty

values
but I suspect this may be very messy and have not had much success in the past. Is there a better more elegant way to achieve my goal?

--PRICE TABLE--
PriceField1 (eg 100,000)
PriceField2 (eg 130,000)
PriceField3 (eg 142,000)
PriceField4 (eg 152,000)
PriceField5 (eg 162,000)
PriceField6 (empty)
PriceField7 (empty)
PriceField8 (empty)
PriceField9 (empty)
PriceField10 (empty)

Many thanks in advance

Jason




Jul 19 '05 #4

P: n/a
> If form collection, there is no first and last.

That depends. You can certainly iterate through a form collection in the
same order as the form elements appeared on the page (see
http://www.aspfaq.com/2036). I don't believe this will obey optioanl
TABINDEX settings, however.

--
Aaron Bertrand
SQL Server MVP
http://www.aspfaq.com/
Jul 19 '05 #5

P: n/a
I'm sorry - I would be iterating the form collection on the collecting page.

But, my main problem is initially interoggating the row or record to find
the last non-empty field in a row containng a maximu of 10 fields.

Thus, fields 1-5 might containt data (ie price).

I would need to determine that field five has data and then display the
first five field values in INPUT boxes for the user to edit and then submit
to the next page.

This is the challenge for me...I am not exactly sure how to do this.

Does this make sense?

Thanks
Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#F*************@TK2MSFTNGP10.phx.gbl...
I would think that looping would be okay for this. What are you trying to
do or why haven't you had luck with that?

Ray at work
"jason" <ja***@catamaranco.com> wrote in message
news:uF**************@tk2msftngp13.phx.gbl...
Access 2000

I need some help interogatting a table and extracting via ASP the final
field in a row which has a value. In other words, I have a maximum of 10
fields but, at the user level he may he only enter values into the first
four. I need to ALWAYS extract the final or last field that has a value.

In
the example below this would be PriceField5 which has a value of $162,000.
The user stopped at this field and left the rest blank.

I considered cycling through the row and checking for null or empty

values
but I suspect this may be very messy and have not had much success in the past. Is there a better more elegant way to achieve my goal?

--PRICE TABLE--
PriceField1 (eg 100,000)
PriceField2 (eg 130,000)
PriceField3 (eg 142,000)
PriceField4 (eg 152,000)
PriceField5 (eg 162,000)
PriceField6 (empty)
PriceField7 (empty)
PriceField8 (empty)
PriceField9 (empty)
PriceField10 (empty)

Many thanks in advance

Jason



Jul 19 '05 #6

P: n/a

"jason" <ja***@catamaranco.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I'm sorry - I would be iterating the form collection on the collecting page.
But, my main problem is initially interoggating the row or record to find
the last non-empty field in a row containng a maximu of 10 fields.

Thus, fields 1-5 might containt data (ie price).

I would need to determine that field five has data and then display the
first five field values in INPUT boxes for the user to edit and then submit to the next page.

This is the challenge for me...I am not exactly sure how to do this.

Does this make sense?

Using what Aaron posted, you can do:

Dim i
For i = Request.Form.Count To 1 Step -1
If Request.Form.Item(i) <> "" Then
Response.Write "The last item with data is " & Request.Form.Key(i)
Exit For
End If
Next

That should get you started, anyway. That will loop through the form
collection backwards and look for the ~first~ value, which will be the last,
since it's going in reverse. Note it doesn't trim values or discriminate
form field names or anything.

Ray at work
Jul 19 '05 #7

P: n/a
Thank you - I did not know you could actually go in reverse.....I will take
a closer look at the aspfaq and build furhter from it...

Cheers
Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#E**************@TK2MSFTNGP12.phx.gbl...

"jason" <ja***@catamaranco.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I'm sorry - I would be iterating the form collection on the collecting page.

But, my main problem is initially interoggating the row or record to find the last non-empty field in a row containng a maximu of 10 fields.

Thus, fields 1-5 might containt data (ie price).

I would need to determine that field five has data and then display the
first five field values in INPUT boxes for the user to edit and then

submit
to the next page.

This is the challenge for me...I am not exactly sure how to do this.

Does this make sense?

Using what Aaron posted, you can do:

Dim i
For i = Request.Form.Count To 1 Step -1
If Request.Form.Item(i) <> "" Then
Response.Write "The last item with data is " & Request.Form.Key(i)
Exit For
End If
Next

That should get you started, anyway. That will loop through the form
collection backwards and look for the ~first~ value, which will be the

last, since it's going in reverse. Note it doesn't trim values or discriminate
form field names or anything.

Ray at work

Jul 19 '05 #8

P: n/a
ps: This reverse form script works absolutely great....I can find so many
applications for it...thanks again to Ray and Aaron.

- Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#E**************@TK2MSFTNGP12.phx.gbl...

"jason" <ja***@catamaranco.com> wrote in message
news:el**************@TK2MSFTNGP10.phx.gbl...
I'm sorry - I would be iterating the form collection on the collecting page.

But, my main problem is initially interoggating the row or record to find the last non-empty field in a row containng a maximu of 10 fields.

Thus, fields 1-5 might containt data (ie price).

I would need to determine that field five has data and then display the
first five field values in INPUT boxes for the user to edit and then

submit
to the next page.

This is the challenge for me...I am not exactly sure how to do this.

Does this make sense?

Using what Aaron posted, you can do:

Dim i
For i = Request.Form.Count To 1 Step -1
If Request.Form.Item(i) <> "" Then
Response.Write "The last item with data is " & Request.Form.Key(i)
Exit For
End If
Next

That should get you started, anyway. That will loop through the form
collection backwards and look for the ~first~ value, which will be the

last, since it's going in reverse. Note it doesn't trim values or discriminate
form field names or anything.

Ray at work

Jul 19 '05 #9

P: n/a
You're welcome!

Ray at work

"jason" <ja***@catamaranco.com> wrote in message
news:O%****************@TK2MSFTNGP12.phx.gbl...
ps: This reverse form script works absolutely great....I can find so many
applications for it...thanks again to Ray and Aaron.

- Jason
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:#E**************@TK2MSFTNGP12.phx.gbl...

"jason" <ja***@catamaranco.com> wrote in message

Jul 19 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.