Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2012
    Posts
    24

    Unanswered: FoxPro: Looping through a table

    Hi

    I am using FoxPro 9.0 and have a table MyTable with very many records, new to this language I am struggling to understand the basic commands. MyTable looks like

    MyTable
    -----------------------------------------------------------------------
    Customer NbItem Item Total
    C01 3 shoes 3
    C04 2 socks 2
    K91 2 lace 2
    C01 1 statue 1

    What I want to do is make different calculations for each customer. So I need to gather all records with same customer name and take the other fields for calculations. I have used DISTINCT to find the number of unique customer, but I also have to do some sort of loop (I think) as I will be using customer name for identification in another table.

    Google havn't been my friend with this. I hope to find some answer here (fingers crossed)

  2. #2
    Join Date
    Nov 2002
    Posts
    128
    Provided Answers: 1
    You might want to spend some time with your VFP Help system

    In your Command window type: HELP
    Then in the Help - go to the Contents tab and scroll down to Language Reference
    In there you will find a list of all of the Commands and Functions in the VFP lanugage.

    For your specific question there you can use a variety of approaches

    Code:
    USE MyTable
    SELECT MyTable
    SCAN  && And you can add a criteria option (FOR <whatever>) to limit the records scanned
      * --- <do whatever> ---
    ENDSCAN  && will automatically advance to next record
    or

    Code:
    USE MyTable
    SELECT MyTable
    DO WHILE <whatever>
      * --- <do whatever> ---
       * --- Advance to the next record ---
       SKIP
    ENDDO
    or

    Code:
    USE MyTable
    SELECT MyTable
    FOR Counter = 1 to <some number>
      * --- <do whatever> ---
       * --- Advance to the next record ---
       SKIP
    ENDFOR
    More than likely you will be wanting to concurrently use multiple data tables in your application. This will be even more likely if you have normalized your data tables.

    To do so, you will need to understand how to move from table to table easily.

    Once again I recommend that you spend some time with the free on-line (or downloadable) VFP tutorial videos at: Free Visual FoxPro Videos

    Additionally you might want to look over the Visual Foxpro reference books at:
    Hentzenwerke Moving from Windows to Linux

    One of those books which might be of particular interest to you on a very basic level might be: The Fundamentals
    Hentzenwerke Moving from Windows to Linux
    Unfortunately: only available in ebook (PDF) form

    There is also a web page named: Which book is right for you?
    On it are some references for VFP tutorial books depending on your circumstances.

    Good Luck

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •