Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: John Weller
  Where is John Weller?
 Devizes
 United Kingdom
 John Weller
 To: Chandan Chakraborty
  Where is Chandan Chakraborty?
 Raiganj
 India
 Chandan Chakraborty
 Tags
Subject: RE: performance issue
Thread ID: 78583 Message ID: 78584 # Views: 1 # Ratings: 0
Version: Unknown Category: General VFP Topics
Date: Wednesday, October 05, 2005 9:03:20 PM         
   


> I have developed a rg. for calcualting interest on Savngs bank A/C.It is running well but very slow. I like to inform the experts that I am not a professional and not a regular student of developing prg. just one and half year ago. While working in my office I have been inspired by the outcome of the software,which we are using in our office. I think to learn just as a beginner and came to your world. So if any one think, my quench is baseless then please don't reply. But please not take it other wise to criticize me and my efforts. I am ameture and want to be lying as an ameture. My office is paying me much and I h no intention to professionally use my code or have the capacity to do so.
>
> Now let me come to the point. My prg. is very slow. My code is given below :
>
> ** THE PURPOSE OF THE PRG. IS TO CALCULATE INTEREST ON SAVINGS BANK A/C
> ** THE SPECIALITY IS TO FIND MINIMUM BALANCE
> ** THE FOLLOWING A/C DETAILS WILL BE HELPFUL TO UNDERSTAND THE SYSTEM OF
> ** FINDING MINIMUM BALANCE
>
> * A/C DATE DEBIT CREDIT BALANCE
> * 1 07/08/2004 2000.00
> * 1 12/12/2004 1000.00 1000.00
> * 1 09/01/2005 2000.00 3000.00
> * 1 10/01/2005 5000.00 8000.00
> * 1 25/01/2005 3000.00 5000.00
>
> *MINIMUM BALANCE FOR AUG=2000;SEP=2000;OCT=2000;NOV=2000;DEC=1000;
> * JAN=5000. I.E. FROM 10TH TO LAST DATE MINIMUM BALANCE IS TO BE CONSEDERED.
> * ANY DEPOSIT(CREDIT) AFTER 10TH WILL BE IGNORED FOR THAT MONTH
> CLOSE ALL database
> clea
> MDATE=CTOD(" ")
> CMONTH=CTOD("MDATE")
> lnInt=0
>
> @13,50 SAY "DATE:" FONT "ARIAL",12 COLO RB+
> @13,63 GET MDATE FONT "ARIAL",12 COLO RB+
> @16,38 SAY "ENTER ANY DATE OF THE MONTH" FONT "ARIAL",12 STYLE 'B' COLO GR+
> @18,42 SAY "PRESS ENTER TO CONTINUE " FONT "ARIAL",12 COLO W+/B+
>
> READ
> CLEA
> CP=0
> W=SPACE(1)
> sele a
> use dep && MASTER TABLE
>
> sele B
> USE GH && FIELDS ARE MONTH;YEAR,ACNO,MIN_BAL;
>
> SELE C
> USE MBAL && ACNO UNIQUE
>
>
> SELE GH
>
> INDEX ON STR(YEAR)+MONTH TO SS
> GOTO TOP
> DO WHILE .NOT. EOF()
> IF MONTH=CMONTH(MDATE) .AND. YEAR=YEAR(MDATE)
> CP=1
> ENDIF
> SKIP
> ENDDO
>
> SELE MBAL
> INDEX ON ACNO TO SRE
>
>
> sele GH
> index on acno to sst
>
> sele DEP
> index on date to ss
> STORE 0 TO lnB,lnMb,lnLb,lnAc_no,lnK,lnP,lnS
> a=0
> MM=SPACE(2)
>
> AAAA=0
> SELE mbal
> GOTO TOP
> DO WHILE .NOT. EOF()
> SELE mbal
> AAAA=ACNO
> SELE A
> lnB=0
> lnMb=0
> lnLb=0
> lnAc_no=AAAA
> goto top
> do while .not. eof()
> if month(date)> lnLb=balance
> ENDIF
> skip
> enddo
>
>
> if lnLlb=0
> goto bottom
> do while .not. bof()
> if a=acno AND year(Mdate)>year(date) and lnLb=0 and month(date)> lnLb=balance
> endif
> skip -1
> enddo
> endif
>
> *********
>
>
> goto bottom
> do while .not. bof()
>
> if lnAc_no=acno and MONTH(date)=MONTH(Mdate) and day(date)<=10 and year(Mdate)=year(date)
> lnB=balance
> exit do
> endif
> skip -1
> enddo
> ****
> if lnB<=0
> lnS=lnLb
> else
> lnS=lnB
> endif
> if lnB=>0 OR lnLb>0
> goto top
> do while .not. eof()
>
> if lnAc_no=acno and MONTH(date)=MONTH(Mdate) and day(date)>10 and year(Mdate)=year(date) and lnS>balance
> lnB=balance
> exit do
> endif
> skip
> enddo
>
> goto top
> do while .not. eof()
> if lnAc_no=acno .and. MONTH(date)=MONTH(Mdate) .and. day(date)>10 .and. year(Mdate)=year(date) .and. lnB>balance
> lnMb=balance
> lnB=lnMb
> else
> lnMb=lnB
> endif
> skip
> enddo
>
> sele b
>
> if lnMb=0
> if lnLb>0
> INSERT INTO GH(DATE,MONTH,ACNO,MINBAL,YEAR);
> VALUES(MDATE,CMONTH(MDATE),A,LB,YEAR(MDATE))
>
>
> else
>
> if lnMb>0
> INSERT INTO GH(DATE,MONTH,ACNO,MINBAL,YEAR);
> VALUES(MDATE,CMONTH(MDATE),A,LB,YEAR(MDATE))
> ENDIF
> ********** ENTERED BY ME ****************
>
> ENDIF
> ENDIF
>
>
>
> sele dep
> K=K+1
> IF K=P
> EXIT FOR
> ENDIF
> ENDIF
> SELE mbal
> SKIP
> ENDDO
>
>
> CLOSE ALL
>
>
> May any one help me to rectify the code as it can run speedily.
>
> Chandan Chakraborty
> gutiput


What version of Fox are you using?

Some suggestions:

Do not use

sele B
USE GH && FIELDS ARE MONTH;YEAR,ACNO,MIN_BAL;

instead use

USE GH IN 0 as it is quicker, then , instead of SELECT B use SELECT GH, it is easier to read.

Do not use

SELE GH
INDEX ON STR(YEAR)+MONTH TO SS

GOTO TOP
DO WHILE .NOT. EOF()
IF MONTH=CMONTH(MDATE) .AND. YEAR=YEAR(MDATE)
CP=1
ENDIF
SKIP
ENDDO

instead index the table outside the program, once it is indexed it will stay indexed. Then use:

SELECT GH
SCAN
IF MONTH=CMONTH(MDATE) .AND. YEAR=YEAR(MDATE)
CP=1
ENDIF
ENDSCAN

it is much quicker. Replace all your DO WHILE .NOT. EOF() loops with SCAN/ENDSCAN.

Try and get into the habit of indenting.

I have not gone into much more detail but if you try those changes then send me your code I will have another look.

HTH

John Weller

ENTIRE THREAD

performance issue Posted by Chandan Chakraborty @ 10/5/2005 8:18:00 PM
RE: performance issue Posted by John Weller @ 10/5/2005 9:03:20 PM