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

Discussion in 'ASP General' started by jason, Dec 9, 2003.

  1. jason

    jason Guest

    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
     
    jason, Dec 9, 2003
    #1
    1. Advertising

  2. jason

    Ray at Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
    >
    >
    >
    >
    >
     
    Ray at, Dec 9, 2003
    #2
    1. Advertising

  3. jason

    jason Guest

    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:#...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    jason, Dec 9, 2003
    #3
  4. jason

    Ray at Guest

    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" <> wrote in message
    news:...
    > 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:#...
    > > 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" <> wrote in message
    > > news:...
    > > > 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
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >
    > > >

    > >
    > >

    >
    >
     
    Ray at, Dec 9, 2003
    #4
  5. > 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/
     
    Aaron Bertrand - MVP, Dec 9, 2003
    #5
  6. jason

    jason Guest

    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:#...
    > 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" <> wrote in message
    > news:...
    > > 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
    > >
    > >
    > >
    > >
    > >
    > >
    > >

    >
    >
     
    jason, Dec 9, 2003
    #6
  7. jason

    Ray at Guest

    "jason" <> wrote in message
    news:...
    > 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
     
    Ray at, Dec 9, 2003
    #7
  8. jason

    jason Guest

    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:#...
    >
    > "jason" <> wrote in message
    > news:...
    > > 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
    >
    >
     
    jason, Dec 10, 2003
    #8
  9. jason

    jason Guest

    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:#...
    >
    > "jason" <> wrote in message
    > news:...
    > > 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
    >
    >
     
    jason, Dec 10, 2003
    #9
  10. jason

    Ray at Guest

    You're welcome!

    Ray at work

    "jason" <> wrote in message
    news:O%...
    > 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:#...
    > >
    > > "jason" <> wrote in message
     
    Ray at, Dec 10, 2003
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. 6e
    Replies:
    1
    Views:
    423
    Wendy S
    Apr 19, 2005
  2. pompair
    Replies:
    0
    Views:
    754
    pompair
    Jan 27, 2008
  3. Chuck
    Replies:
    0
    Views:
    270
    Chuck
    Nov 10, 2003
  4. VUNETdotUS
    Replies:
    25
    Views:
    460
    Thomas 'PointedEars' Lahn
    Nov 10, 2007
  5. jr
    Replies:
    3
    Views:
    426
Loading...

Share This Page