home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Today (BR) Volume 2 #6 / CDRTV2N6.iso / makers / random.dir / 00278_Script_Bsearch < prev    next >
Text File  |  1996-03-11  |  700b  |  35 lines

  1. on Bsearch str, txt
  2.   
  3.   set txt = the number of cast txt
  4.   set start = 1
  5.   set end = the number of lines of field txt  
  6.   set middle = (start + end) / 2  
  7.   
  8.   repeat while str <> item 1 of line middle of field txt
  9.     
  10.     if str = item 1 of line end of field txt then
  11.       return end
  12.     end if
  13.     
  14.     if start = middle then
  15.       return 0
  16.     end if 
  17.     
  18.     if str < item 1 of line middle of field txt then
  19.       set end = middle
  20.     else
  21.       set start = middle
  22.     end if
  23.     
  24.     
  25.     set middle = (start + end) / 2  
  26.     
  27.   end repeat
  28.   
  29.   if str = item 1 of line middle of field txt then
  30.       return middle
  31.   else
  32.     return 0
  33.   end if
  34.   
  35. end Bsearch