>I am using a quite simple and very usefull routine for years that works great if the table is in the same directory as the program but refuse to work if the table is in a different directory.
>
>Well.. I could probably figure it out if I take the time to do it but there are probably many of you that has the routine already made and working perfectly. So why reinvent the weel?
>
>The procedure check the following: if the table is not opened, it opens it and select it. If it is opened it onky select it. The second parameter is to select the order tag.
>
>* FICHIER.PRG (Foxpro 2.5b)
>*-----------------------------
>PARAMETERS _DBF,ORDRE
>IF USED(_DBF)=.F.
> USE (_DBF) IN 0
>ENDIF
>SELECT (ALIAS(_DBF))
>IF PARAMETERS()=2
> SET ORDER TO (ORDRE)
>ENDIF
>
>So... how can it also work with tables in different directories than the program.
>
>Thanks in advance.
There are many ways to do :) As I understand you use either fullpath or just filename as _DBF. Used() checks for alias not fullpath so if it's in another dir (fullpath supplied) it fails. If you don't need a very robust version (e.g. taking into consideration that a table could be opened multipl times all with different alias names other than filename, filenames are not LFN etc) then this one works :
function myUse
parameters tcTable, tcOrder
lcAlias = strtran( ;
iif(at("\",tcTable)>0, ;
substr(tcTable,rat("\",tcTable)+1), ;
tcTable), ;
".dbf","")
if !used(lcAlias)
use (tcTable) in 0
endif
select (lcAlias)
if parameters()=2
set order to tag ;
(iif(type("tcOrder") = "N", ;
tag(tcOrder), tcOrder))
endif
Cetin