Solved

Ms. Visual FoxPro version 3.0

Posted on 1997-11-29
4
1,120 Views
Last Modified: 2008-03-04
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
0
Comment
Question by:pkimk
  • 2
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
faster earned 200 total points
Comment Utility
The program is not indented so it is very difficult to read.  There are two problems I can see at a glance:

1.  You use skip to go through the trans.dbf (I think you intend to), however, before the "skip", you open another dbf therefore the skip is on member.dbf instead of trans.dbf

2. Inside the loop you "use member.dbf", this is not correct, because you should open it only once.

Modify your code as such:

1. Move the "use ..."before the loop.  It should read:

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

2. before "locate for Member=cMember", add:
select members

After you finish using the members.dbf in the loop, add:
select trans

This is to ensure that for rest of the code, trans.dbf is always the current table.


0
 

Author Comment

by:pkimk
Comment Utility
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

0
 
LVL 7

Expert Comment

by:faster
Comment Utility
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.
0
 

Author Comment

by:pkimk
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In today’s complex data management environments, it is not unusual for UNIX servers to be dedicated to a particular department, purpose, or database.  As a result, a SAS® data analyst often works with multiple servers, each with its own data storage…
Read about achieving the basic levels of HRIS security in the workplace.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now