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

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

Post by jaso » Thu, 11 Dec 2003 00:05:46


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
 
 
 

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

Post by Ray at <%s » Thu, 11 Dec 2003 00:37:59

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




In
values

 
 
 

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

Post by jaso » Thu, 11 Dec 2003 00:50:24

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






$162,000.
the
 
 
 

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

Post by Ray at <%s » Thu, 11 Dec 2003 03:03:08

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



longwinded
into
I
you


to


final
10
first
value.
 
 
 

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

Post by Aaron Bert » Thu, 11 Dec 2003 03:23:40

> 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.yqcomputer.com/ ). I don't believe this will obey optioanl
TABINDEX settings, however.

--
Aaron Bertrand
SQL Server MVP
http://www.yqcomputer.com/
 
 
 

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

Post by jaso » Thu, 11 Dec 2003 04:13:31

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




$162,000.
the
 
 
 

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

Post by Ray at <%s » Thu, 11 Dec 2003 05:00:47


page.
submit


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
 
 
 

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

Post by jaso » Thu, 11 Dec 2003 23:52:27

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




find
last,
 
 
 

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

Post by jaso » Fri, 12 Dec 2003 05:05:49

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

- Jason




find
last,
 
 
 

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

Post by Ray at <%s » Fri, 12 Dec 2003 05:19:02

You're welcome!

Ray at work