From: durai@ortta.umn.edu (Durai Venkatasubramanian)
Newsgroups: comp.databases
Subject: Re: Foxpro 2.0 Index Searches
Date: 7 Jan 93 15:21:37 GMT
Organization: U of Mn

In article <thomasd.62.726343853@tps.COM> thomasd@tps.COM (Thomas W. Day) writes:

>1) How do you do a multiple field indexed SEEK?  Meaning, I have an index 
>that was created using three (3) fields, now I want to seek data on those 
>fields.  Everything I try seems to bring back EOF without locating any 
>related data.  A single field search (the first field of the index) works 
>OK, but that's all I've managed.  Until I get this right, I'm doing all my 
>data searches with LOCATE and they are slow.

Make sure the seek expression and the index expression are of the same type.
For example, if you indexed character+date+number, 
             you should seek char+dtoc(date)+str(num,xx).

>2) If I create several indexes, how do I keep them all current?  Are they 
>all automatically updated if they are opened with SELECTs?  Or do I have to 
>REINDEX after a change is made in the database with one index and then a 
>search is required on a different index?

If you created compact index files (.cdx), the index files are automatically 
opened (updated) whenever you open the database file.  I have found this 
very useful.  All I have to do is to remember the order.

>3) Can you recommend an after-market book that details data search methods?

1. Using Foxpro2: Slater & Arnold, Que   <good>
2. Foxpro Handbook: Tom Rettig, Bantam  <old, but lots of good tips>
3. Foxpro Programming: Olympia & Cathy, Addison Wesley  <okay>
4. Foxpro Code Book: Griver, Business One, <so so>
5. Exploring Foxpro: Martin Fox, Future Communications <stay away>
6. Foxpro2 Developers Guide: Winchell et al, M&T, <okay>

<..xxx...> my opinion 
 
>4) Is there a reasonable way to perform math functions on 4-digit time 
>data?  The data is derived by the TIME() function but is stored 
>in a character field as 99:99 (hour:minute) character data.  What I want to 
>do is subtract two fields stored this way in each record and obtain the 
>average time between each of these fields.  Obviously, 15:01-14.58 should 
>equal something other than 00:43.  Is there a convert-text-to-time (CTOT?) 
>function?

You can find out the numeric equivalent of hrs, mts, secs (from data out of 
the time() function).
hrs =  val(substr(time(), 1, 2)
mts =  val(substr(time(), 4, 2)
secs = val(substr(time(), 7, 2)

The following udfs, are from Tom Rettig's Foxpro Handbook (page 779):

function stots
* syntax: stots(N seconds);
  action: convert numeric seconds into time string;
  return: time string in the format hh:mm:ss
parameters seconds
if seconds <= 0
 return "00:00:00"
else
 return strtran(str(int(mod(seconds/3600,24)),2)+":"+;
                str(int(mod(seconds/60,60)),2)+":"+;
                str(int(mod(seconds,60)),2)," ","0")
endif
*eof

function tstos
* syntax: tstos(time string);
  action: convert time string to numeric seconds;
  return: N seconds
parameters timestring
if not (between(substr(timestring,1,2),"00","23") and ;
        between(substr(timestring,4,2),"00","59") and ;
        between(substr(timestring,7,2),"00","59") and ;
        substr(timestring,3,1) == ":" ;
        substr(timestring,6,1) == ":" ;
   return 0  && invalid time string
else
   return val(substr(timestring,1,2))*3600 + ;
          val(substr(timestring,4,2))*60 + ;
          val(substr(timestring,7,2))
endif
*eof
Newsgroups: comp.databases