Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Seeking a Record in a List Box
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00737383
Message ID:
00737415
Views:
22
>I have found that the following code is slow, as the listbox I have is quite large.
>Instead of doing the FOR...NEXT loop, is there another way to select and highlight the record in the listbox ? I know the value of mPolicy.
>
>
>
>FOR nCnt = 1 to o.listcount
> if trim(o.list(nCnt,x))+o.list(nCnt,x+2)=mPolicy
> o.selectedID(nCnt)=.t.
> Exit
> endif
>NEXT nCnt
>
>o.click
>o.setfocus

If it's ordered, the answer is yes, otherwise no. In the former case something like this will be the fastest possible search
LOCAL lnfirst, lnlast, lnmid, llfound, lnoffset
* m.Policy is the value to search for.
lnoffset = 0
lnfirst = 1
lnlast = o.ListCount
lnmid = INT((lnfirst + lnlast) / 2)
llfound = (ALLTRIM(o.List(lnmid, x)) + ALLTRIM(o.List(lnmid, x + 2) = m.Policy)
DO WHILE NOT llfound AND lnfirst < lnlast
  IF (ALLTRIM(o.List(lnmid, x)) + ALLTRIM(o.List(lnmid, x + 2) > m.Policy)
    lnfirst = lnmid + 1
  ELSE
    lnlast = lnmid - 1
  ENDIF
  lnmid = INT((lnfirst + lnlast) / 2)
  llfound = (ALLTRIM(o.List(lnmid, x)) + ALLTRIM(o.List(lnmid, x + 2) = m.Policy)
ENDDO
IF llfound
  lnoffset = lnmid
ENDIF
RETURN lnoffset
George

Ubi caritas et amor, deus ibi est
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform