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

J

jason

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
 
R

Ray at

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
 
J

jason

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
 
R

Ray at

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
 
A

Aaron Bertrand - MVP

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.
 
J

jason

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
 
R

Ray at

jason said:
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
 
J

jason

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
 
J

jason

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

- Jason
 
R

Ray at

You're welcome!

Ray at work

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

- Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top