1 Reply Latest reply on Aug 11, 2017 5:02 AM by Mike_Mitchell

# Scrolling in list view

In list view is it possible to scroll to a certain record?

I have records listed by date, and would like to scroll to the record nearest to the current date (there isn't a record for every day). Obviously I could just do a found set of records from the current date onwards, but it would sometimes be useful for the user to be able to check back on past dates.

• ###### 1. Re: Scrolling in list view

Hello, Matthew. Yes, you can do this. I suggest using a binary search algorithm, which is a very fast way to locate a particular value in a sorted list. (There's actually a mathematical proof that says it takes no more than X iterations, no matter how long the list, but I'm too lazy to look up X right now.) It works something like this:

Go to the middle of the list

Is the desired value before, or after, the current value?

If before, go halfway from your current point to the beginning of the list

If after, go halfway from your current point to the end of the list

Repeat until desired value found

In other words, you continuously go to a narrower and narrower halfway point until the value is found. Here's some pseudo code for a script:

Set Variable [ \$firstRecordNo ; Value: 1 ]

Set Variable [ \$lastRecordNo ; Value: Get ( FoundCount ) ]

Set Variable [ \$desiredValue ; Value: {desired value goes here} ]

Loop

Go to Record / Request / Page [ \$firstRecordNo + Floor (( \$lastRecordNo - \$firstRecordNo ) / 2 ) ]

If [ \$lastDestinationRecordNo = Get ( RecordNumber )

Go to Record Request / Page [ Next ]

End If

Exit Loop If [ tableName::field = \$desiredValue or \$firstRecordNo = \$lastRecordNo ]

Set Variable [ \$lastDestinationRecordNo ; Value: Get ( RecordNumber ) ]

If [ table::value < \$desiredValue

Set Variable [ \$firstRecordNo ; Value: Get ( RecordNumber )]

Else

Set Variable [ \$lastRecordNo ; Value: Get ( RecordNumber )]

End If

End Loop

HTH

Mike