DEACTIVATE MENU

AUsed()

With 32,767 work areas per data session, knowing what table is open in which work area is a significant task. AUSED() makes it simple by filling an array with a list of aliases and work areas for the current (or a specified) data session.

Usage

nUsedCount = AUSED( ArrayName [, nDataSession ] )

Parameter

Value

Meaning

ArrayName

Name

The array to be filled with alias and work area information.

nDataSession

Omitted

Get aliases and work areas for the current data session.

Positive Number

Get aliases and work areas for the specified data session.

nUsedCount

Positive Number

The number of rows in the array, equal to the number of work areas in use in the data session or the number of open databases.

0

No work areas in use.


The aliases appear in the array in the same order as they're displayed in the View window. It appears to be the reverse of the order in which they were opened. The array has two columns. The first column contains the alias, while the second contains the work area number.

Example

? AUSED(aAliases)     && create an array with aliases for the                        && current data session ? AUSED(aAliases, 3)  && create an array with aliases for data                       && data session 3
SELECT-SQL has a nasty habit of leaving open any tables it opens to perform a query. (If it finds a table open, it reopens it in another work area, like an internal USE AGAIN, but it cleans up after itself in that case.) In FoxPro 2.x, cleaning up after a query meant being sure to always use work areas in sequence (with SELECT 0), then making a note of the next available work area before the query, then looping through from that work area out to the end (225), closing whatever had been opened, while of course being sure not to close the cursor or table created by the query. All in all, a real pain and totally out of the question with 32K work areas to deal with.

AUSED() makes this job much simpler. We can simply get the list of open tables before and after the query and close the ones that were opened. We do still have to watch out for the newly created cursor or table. The code can be structured like this:

* get "Before" listing nBeforeCnt = AUSED(aBefore) * do the query here   * hold work area for result nResultArea = SELECT() * get "After" listing nAfterCnt = AUSED(aAfter)   * now loop through changes, if any IF nAfterCnt > nBeforeCnt   FOR nPointer = 1 TO nAfterCnt-nBeforeCnt      * Start from 1 because most recently opened      * come first      IF aAfter[nPointer,2] <> nResultArea         USE IN aAfter[nPointer,2]      ENDIF   ENDFOR ENDIF

See Also

ADatabases(), Array Manipulation, Select-SQL, Set DataSession, Use, Used()


 

View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net