SELECT wrkArea statement

Please consider this piece of code. It is a bit weird as far as DO loop goes but it is the way I frequently do things. The problem I run into is the  SELECT statement.

USE
HistData!myTable IN 0
wrkArea = 0
DO WHILE ! EMPTY(wrkArea+1)
  wrkArea = wrkArea + 1
  wrkArea
  cTableAlias =
ALIAS(wrkArea)  
  IF cTableAlias = "MYTABLE"
    SELECT wrkArea    && here the program breaks down
    EXIT
  ENDIF
ENDDO

I get an error message that alias "wrkarea" not found. It is an integer! If I modify the statement like this: SELECT &wrkArea I get another error.

What is a legitimate way to do something like this I want my program to find out where my table ended up in terms of the workarea number.

In the code above the program goes through all areas and finds the alias I need and is ready to exit BUT....

Thank you.




Answer this question

SELECT wrkArea statement

  • Darla

    Alex,

    For the most part in VFP we don't care what actual workarea numbers end up being.

    SELECT wrkArea && this is expecting to have a table or cursor aliased as wrkArea already open in the current data session.

    more typically your code would be written in VFP like this:

    USE HistData!myTable in 0
    * other stuff goes on
    select myTable && make this the current workarea
    * table manipulation goes on here
    scan
       myTable.myField
    endscan

    If you want to handle multiple tables under a "static" name:

    use xyz in 0 alias genericname
    ...
    select genericname
    ... && process it


    With the IN clauses of the Xbase table manipulation commands you don't necessarily have to be sitting on that workarea at the time.


  • dbreggin

    SELECT (wrkArea)
  • Garon Line

    Thank you, David and everyone else who replied.

  • d3v310p3r

    select 0
    select(0)
    USE HistData!myTable

  • Midet

    We are glad to help.

    One other thing you'll see a lot is the USED() function to first see if the table is open and open it if it's not. Ususally this gets wrapped into a little UDF:

    function OpenFile( pcTable )

    if ( ! used( pcTable ) )
       select 0
       use (pcTable)
    else
       select (pcTable)
    endif
    return


  • SELECT wrkArea statement