>Hi
>
>I encountered inconsistence in using the (USE IN file) command,
>First, I tried to use SQL Select command to output my result to a dbf file, then tried to close both open file show below by using (USE IN) command. Then tried to reopen one of the file again. Vfp will report that the file is in used. Didn't I had close both open files in the first place by using (USE IN) command.
>
>Next, after using the command (USE (loutputfile+'cas') in 0 EXCLUSIVE) command, (SELECT cas) command will give me Alias cas not found. The use command in th first place didn't give any error.
>
>Please advise or comment, did I miss out any thing. Thank you.
>
>Below is my code
>
>SELECT * FROM cas a INTO DBF ;
>(loutputfile+'cas');
>WHERE YEAR(closing) = lYear
Unless you need to explcitly create an alias for joing purposes, the statement above is needlessly complicated; the following is functionally equivalent:
SELECT * FROM CAS INTO TABLE (lOutputfile + 'cas') WHERE YEAR(Closing) = lYear
At this point, you can get the alias the SELECT statement results are in with the ALIAS() function, ie:
cMyAlias = ALIAS()
If you aren't certain of the name and path created by the SELECT, you can use the DBF() function to retrieve it:
cMyTableName = FULLPATH(DBF())
If lOutputfile isn't terminated with a backslash (\), the file name will not be what you're expecting. In VFPO 6, you can clarify the situation by using the ADDBS() function to add a backslash as needed (ADDBS() existed in earlier versions, was a part of FoxTools.)
TO close the tables down:
USE && closes the result of the SELECT
USE IN CAS && closes the table you selected from originally
>USE in cas ---------- cas in outputfile folder close ?
>USE IN a -- cas in current folder close ?
>
>USE (loutputfile+'cas') IN 0 EXCLUSIVE ----no error given
>SELECT cas ----cannot select alias
The odds are that the file name created was not what you expected. You can assign an alias explicitly by:
IF USED('CAS')
USE IN CAS
ENDIF
USE (loutputfile+'cas') IN 0 EXCLUSIVE <i>ALIAS CAS</i>
>INDEX ON DTOS(closing)+outlet_id TAG outlet_id OF (loutputfile+'cas')
>INDEX ON DTOS(closing)+outlet_id+cascode TAG cascode
>USE IN CAS
If this is really your intention, you can avoid all this by simply doing the indexing immediately after the SELECT statement, and omitting the OF clause, or you could, after reopening as shown above:
SELECT CAS
INDEX ON DTOS(closing) + outlet_id TAG outlet_id
INDEX ON DTOS(closing) + outlet_id + cascode TAG cascode ADDITIVE
USE
BTW, if your ordering in the outlet_id TAG doesn't care what the cascode order is, you can function with just the casecode tag, since you can SEEK and locate on a partial key expression.
>
>
>USE (lFolder+'cas') IN 0 exclusive
Again, you'd be better off using ALIAS explicitly, and checking if the alias is open if you intend reference by an alias.
>SELECT cas
>DELETE ALL FOR YEAR(closing) = lYear
>PACK
If you've SELECTed the area, the IN clause belowq is unnecessary:
>USE IN cas