Link to home
Start Free TrialLog in
Avatar of pkimk
pkimk

asked on

Ms. Visual FoxPro version 3.0

This is Ms. Visual FroPro version 3.0 program coding.
There is a bug - looping fail to continue retrieve overdue data after first one displayed. Infinite loop occur.
Pls debug and give comment. Should you need more information, pls email me.
TQ

Regards,
pkk


clear
set date to dmy
set heading off
cont=.Y.
print=.Y.
date_due=date()
 
      clear
       cCatalog=space[6]
       set device to screen
 
       use trans.dbf
       locate for DATE_DUE < DATE()
       IF found()
             c=11
             page=1
             clear
             @0,1say'Print Book List Report' STYLE 'BU'
             @2,1say'Print now [Y/N] ? 'get print PICT Y'
             read
             IF print
                   @2,1say'Printing in process...'
             ELSE
                   EXIT
             ENDIF
             
            set device to printer
             DO HeadPROC
 
             use trans.dbf                        
             DO WHILE NOT EOF()
 
                   IF DATE_DUE < DATE()
                         
                         @c,87say+Book_no
                         fine= (DATE()-DATE_DUE)*0.10            &&Fine 10¢ per day for the overdue encountered
                         @c,98say+fine PICT '$999.99'
                   
                         cMember=Member
 
                         use MEMBERS.DBF
                         locate for Member=cMember
                         IF found()
                               @c,14say+Member
                               @c,27say+Name
                               @c,71say+Tel
                         ENDIF
 
                         c = c + 2
                         IF c = 31
                               
                                @c,15say'To be continue...' STYLE 'I'
                         @c,92say'Page ' STYLE 'I'      

            && Print page number
                         @c,98say+page STYLE 'I'
                         page = page + 1                                    && Increase page number for the following page
                               clear
                               DO HeadPROC
                               c=11
                         ELSE
                               SKIP
                         ENDIF
                         
                   ELSE
                         IF EOF()
                               EXIT
                         ELSE
                               SKIP
                         ENDIF
                   ENDIF
             ENDDO
 
             @c+2,92say'Page ' STYLE 'I'                  && Print page number at end of report
            @c+2,98say+page STYLE 'I'

             @c+2,19say'End Of Report' STYLE 'I'
             set printer to LPT1
 
       ELSE
             @4,1say'Sorry, No book for this catalog.'
             @6,1say'Try other (Y/N)? :'get cont PICT 'Y'
             read
             IF cont
                   LOOP
             ENDIF
       ENDIF
 
PROCEDURE HeadPROC                                          

      && Set Heading of Report
             @5,12say'National Library, Kuala Lumpur'
             @5,90say'Date : '
             @5,97say DATE()
             @6,48say'OVERDUE LIST REPORT' STYLE 'B'
             
             

@7,12say'=======================================================================

'
             @8,12say'MEMBERSHIP'      STYLE 'B'      

                && First line title heading
             @8,27say'MEMBER' STYLE 'B'
             @8,71say'TELEPHONE' STYLE 'B'
             @8,87say'BOOK' STYLE 'B'
             @8,97say'OVERDUE' STYLE 'B'
             
             @9,12say'NUMBER' STYLE 'B'                          && Second line title heading
             @9,27say'NAME' STYLE 'B'
             @9,71say'NUMBER' STYLE 'B'
             @9,87say'NUMBER' STYLE 'B'
             @9,97say'AMOUNT' STYLE 'B'
@10,12say'======================================================================

='            
RETURN
 
close all
ASKER CERTIFIED SOLUTION
Avatar of faster
faster

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pkimk
pkimk

ASKER

I modify the code as below, it give the same output.
Pls comment further.

Regards,
pkk    e-mail: pkkiang@hotmail.com


clear
print=.Y.
set date to dmy
set heading off

select 0
use members.dbf
select 0
use trans.dbf

select trans
locate for DATE_DUE < DATE()

IF found()
      c=11
      page=1
      clear
      @0,1say'Print Overdue List Report' STYLE 'BU'
      @2,1say'Print Now [Y/N] ? 'get print PICT 'Y'
      read
      IF print
            @2,1say'Printing in process...'
      ELSE
            cancel
      ENDIF

*      set printer to LPT1            
*      set device to printer
      clear
      DO HeadPROC
      
      DO WHILE NOT EOF()
            locate for DATE_DUE < DATE()
            IF found()
                  @c,87say+Book_no
                  fine = (DATE() - DATE_DUE)*0.10                        &&Fine 10¢ per day for the overdue encountered
                  @c,98say+fine PICT '$999.99'
                  
                  cMember=Member
            
                  select members
                  locate for Member=cMember
                  IF found()
                        @c,14say+Member
                        @c,27say+Name
                        @c,71say+Tel
                  ENDIF
                  select trans
                              
                  c = c + 2                                                      && Set double-spaced
            
                  IF c = 31
                        @c,13say'To be continue...' STYLE 'I'
                        @c,92say'Page ' STYLE 'I'                        && Print page number
                        @c,98say+page STYLE 'I'
                        page = page + 1                                          && Increase page number for the following page
                        clear
                        DO HeadPROC
                        c=11
                  ELSE
                        SKIP
                  ENDIF
            ENDIF
      ENDDO

      @c+2,92say'Page ' STYLE 'I'                        && Print page number at end of report
      @c+2,98say+page STYLE 'I'
      @c+2,19say'End Of Report' STYLE 'I'


ELSE
      ??'No Overdue Book.'
      ?
      WAIT 'Press any key to quit......time out in 3" ' TIMEOUT 3
ENDIF

set device to screen      
close all
*clear

PROCEDURE HeadPROC                                                      && Set Heading of Report
            @5,12say'National Library, Kuala Lumpur'
            @5,90say'Date : '
            @5,97say DATE()
            @6,48say'OVERDUE LIST REPORT' STYLE 'B'
            
            @7,12say'======================================================================='
            @8,12say'MEMBERSHIP'      STYLE 'B'                        && First line title heading
            @8,27say'MEMBER' STYLE 'B'
            @8,71say'TELEPHONE' STYLE 'B'
            @8,87say'BOOK' STYLE 'B'
            @8,97say'OVERDUE' STYLE 'B'
            
            @9,12say'NUMBER' STYLE 'B'                              && Second line title heading
            @9,27say'NAME' STYLE 'B'
            @9,71say'NUMBER' STYLE 'B'
            @9,87say'NUMBER' STYLE 'B'
            @9,97say'AMOUNT' STYLE 'B'
            @10,12say'======================================================================='            
RETURN

As I said, you'd better indent your code otherwise it is very difficult for someone like me to understand what your code.

One obvious error is that in the loop, you have:

locate for DATE_DUE < DATE()

This is normally incorrect, because everytime you do such a locate, it will goes to the same record.  There are two ways to navigate the records:

1.  If the database in sorted on data_due, then you should put the locate outside the loop and simply use skip.  (you seem to already have a skip, and one skip is enough for every loop)

2.  If the database is not ordered, you should put locate outside the loop and use continue instead of skip, you should have only one continue in the loop also.
Avatar of pkimk

ASKER

My original code is indent, but after I post it turn WYS.
That is expert-exchange weakness.
Anyway, thank you very much for your helping hand.