Search code examples
visual-foxpro

Visual FoxPro 9 Assign Query to Variable List


I am a C# programmer who is working on a legacy FoxPro (Point of Sale) system, and I would like to know how to assign the results of a dbf query to a variable so I can do something useful with the selected data. In C#, the flow would be to create a model reflecting the database table, run the query, assign results to a List of myModel, and perform subsequent operations on the List of myModel. I get the feeling that FoxPro is different paradigmatically, and I'm having a heck of a time finding information about it online. While my supervisor is way more experienced than me, there is a no-fault communication barrier because we are from different programming eras. Can anybody teach a new dog a trick?

What I would like to do:

myVar = SELECT NETINTERACTIVITY.Status;
        FROM NETINTERACTIVITY.DBF NETINTERACTIVITY;
        WHERE ID=myID

Solution

  • FoxPro doesn't let you do a direct assignment from a query that way. You have two options:

    1) Store the query result to an array and then use the appropriate array element.

    SELECT NETINTERACTIVITY.Status;
            FROM NETINTERACTIVITY.DBF NETINTERACTIVITY;
            WHERE ID=myID ;
            INTO ARRAY aStatus
    * Now aStatus[1] contains the value you selected
    

    Store the query result into a cursor and then use the appropriate field.

    SELECT NETINTERACTIVITY.Status;
            FROM NETINTERACTIVITY.DBF NETINTERACTIVITY;
            WHERE ID=myID ;
            INTO CURSOR csrStatus
    * Now csrStatus.Status contains the value you selected