Beta 5.0.1.3 dcl_ListBox_FindString suggest discription update

Started by Jim Short, November 28, 2008, 06:48:36 AM

Previous topic - Next topic

Jim Short

(dcl_ListBox_FindString Utility_Messages_Stack Search [as String] {StartIndex [as Long]})

Proposed:
List box has zero based index. dcl_ListBox_FindString performs a case insensitive search of the entire list and returns index of the string found or -1. Optional start index perform the search from that point to the end, then starting starting again from the top.

Is:
This method performs a case insensitive search for an item in the list that begins with Search. The search starts with the item at StartIndex and continues past the last item back to the first item until the entire list has been searched. If StartIndex is not specified, the search begins with the first item in the list. The return value is the index (zero based) of the first matching item, or -1 if no item is found.
Jim Short

Jim Short

Better to do both.

(dcl_ListBox_FindString Utility_Messages_Stack Search [as String] {StartIndex [as Long]})

List box has zero based index. dcl_ListBox_FindString performs a case insensitive search of the entire list and returns the index of the item containing characters that match the search string, or -1. Optional start index perform the search from that point to the end, then starting starting again from the top.

(dcl_ListBox_FindStringExact Utility_Messages_Stack Search [as String] {StartIndex [as Long]})

List box has zero based index. dcl_ListBox_FindStringExact performs a case insensitive search of the entire list and returns the index of the item who's string is a exact match to the search string, or -1. Optional start index perform the search from that point to the end, then starting starting again from the top.
Jim Short

owenwengerd

Jim, what is it about the original description that you think is incorrect? Did you just want to make it more clear that the first item index is zero? In your proposed description for FindString there is no mention about the search being for an item that begins with the search string, so IMO it is less complete than the original.
Owen Wengerd (Outside The Box) / ManuSoft

Jim Short

Owen, At first i did not understand the following sentence:
"This method performs a case insensitive search for an item in the list that begins with Search."

Here is my present understanding:
dcl_ListBox_FindString performs a case insensitive search of the entire list and returns the index of the last item containing the search string as its first characters, or -1 if it fails. The optional start index performs the search from that point through the end of the list, then starting at the top, down to the item directly above it. If the search string matches the beginning of the string at the starting index it will be ignored if at the end of its search above the start index there is also a match.

The bottom line.
Beginning characters are found first.
The last instance found is returned .
The last instance can be above the start index even if the start index is a match.

I am really confused about how one would use the start index.

Please say something good that gets this across.
Cheers,
Jim




Jim Short

owenwengerd

Ah, I see. I thought the "StartIndex" argument was where the search started, but I see now that the search starts with the item *after* the specified index. I've renamed the argument "StartAfter" and changed the text as follows (for FindString -- FindStringExact is slightly different):

This method performs a case insensitive search for an item in the list. The search matches any item that begins with Search. The search starts with the item after StartAfter and continues past the last item back to the first item until the entire list has been searched. If StartAfter is not specified, the search begins with the first item in the list. The return value is the index (zero based) of the first matching item, or -1 if no match is found.
Owen Wengerd (Outside The Box) / ManuSoft

Jim Short

Owen,

I think we are making progress. As I was testing this method I thought as you that the search began after the index supplied. That was until I found that that staying consistent with returning the last match in the list meant the search started with the index and ignored it the same way it does when starting from the top. Please re- read my last post. I am out of energy to work this one any more. In the end all will be revealed.

Also what could be the use of starting search in the middle?

Thanks,
Jim
Jim Short

owenwengerd

Jim, in my testing it always returns the *first* item starting the search with the item after the specified item index. The purpose of the argument is to make it possible to search for multiple matches. Imagine the StartAfter argument being the index of the last successful match.
Owen Wengerd (Outside The Box) / ManuSoft

Jim Short

That makes sense!

Why not just have one method that returns a list of strings built from all matches?
The lisp way would be to return list of (index . string) conses . Of course each programmer
can build something similar from the controls existing methods.

Did you determine the methods function from source or from testing the method? I will do my test again.
Do you expect Test1 to return EditOne and Test2 to return EditFour?

Test1 starting without idx:
EditOne
EditTwo
EditThree
EditFour
EditFive

Test2 with starting idx=2:
EditOne
EditTwo
EditThree
EditFour
EditFive
Jim Short

owenwengerd

Quote from: Jim Short on November 29, 2008, 06:33:00 AM
Why not just have one method that returns a list of strings built from all matches?

This is a typical way to add additional capability without requiring any additional work for the times when the simple case is sufficient, and more importantly, not wasting processor cycles searching for matches they may be irrelevant.

Quote from: Jim Short on November 29, 2008, 06:33:00 AM
Do you expect Test1 to return EditOne and Test2 to return EditFour?

Assuming you're searching for "Edit", yes.
Owen Wengerd (Outside The Box) / ManuSoft

Jim Short

My results:
Command: (dcl_ListBox_AddList Utility_Messages_Stack
(_> (list
((_> "EditOne"
((_> "EditTwo"
((_> "EditThree"
((_> "EditFour"
((_> "EditFive"
((_> )
(_> )
4

Command: (dcl_ListBox_GetItemText Utility_Messages_Stack
(_> (dcl_ListBox_FindString Utility_Messages_Stack "Edit")
(_> )
"EditTwo"

Command: (dcl_ListBox_GetItemText Utility_Messages_Stack
(_> (dcl_ListBox_FindString Utility_Messages_Stack "Edit" 2)
(_> )
"EditFour"

Description presently doesn't explain the above. How about this?

This method performs a case insensitive search for a match between the search term and the starting characters of each item's string.  If StartAfter index is not specified, the search starts on index 1, otherwise it starts on the index after the one provided and continues past the last item back to the first item until the entire list has been searched. The return value is the index (zero based) of the first matching item, or -1 if no match is found.

The above describes how it presently works for me. Without providing a StartAfter index, I think the search should be rewritten to begin with index 0 rather than one.
Cheers,
Jim
Jim Short

owenwengerd

Jim, after looking at the code again, I see that omitting the StartAfter argument causes it to use the currently selected item as the StartAfter argument. I don't see any point in that, so I'm changing it to start from the beginning of the list when the argument is omitted. This should cause the behavior to match the (revised) description.
Owen Wengerd (Outside The Box) / ManuSoft

Jim Short

Owen,
FindString without optional index will not match index 0 unless there are no further matches below it.
Jim
Jim Short

owenwengerd

What you describe would be the case when item 0 is selected. Beta 4 will fix that.
Owen Wengerd (Outside The Box) / ManuSoft