Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What should be faster?
Message
 
 
To
06/12/2000 12:45:52
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00449313
Message ID:
00450053
Views:
30
>So do I. And probably easier to maintain.
>
>I will send you my wrapper for USE as soon as I finish it (hopefully next weekend).
>
>Daniel

Daniel,

Ok, seems to work all right. And very fast! :)
********************************************************************
*  Description.......: Run5YearsRpt - special program for 5 Years Report
*  Calling Samples...:
*  Parameter List....: tnStartYear
*  Created by........: Nadya Nosonovsky 12/06/2000 11:52:55 AM
*  Modified by.......: Nadya Nosonovsky 12/06/2000 01:48:04 PM
********************************************************************
lparameters tnYear
local lcEndYear, lcStartYear, lcState, lcCounty, lcCity, lcOldSetTalk, lnTally
if empty(tnYear) or vartype(tnYear)<>'N'
     tnYear=year(date()) && Current year
endif
lcEndYear=transform(tnYear)
lcStartYear=transform(tnYear-4)
if vartype(oJC)='O' && oJC was instantiated properly
     lcState=oJC.CurState
else
     lcState=upper(left(juststem(dbf('InputTable')),2))
endif
lcCounty=replicate('Z',15)
lcCity=replicate('Z',20)
* First of all, prepare working cursor
lcOldSetTalk=set('talk')
set talk window
set talk on && To visualize thermometr
select nvl(State,lcState) as State, ;
       nvl(County,lcCounty) as County, ;
       nvl(fullname,lcCity) as City, ;
     InputTable.ccode, InputTable.town, UseGrp, cYear, ;
     VolSales, MedSale, NumSales ;
     from InputTable ;
     left join Lookups!Towns on InputTable.ccode=Towns.ccode and ;
               InputTable.town=Towns.town and Towns.Town<>'ZZZZ'; && LEFT JOIN, because ZZZZ towns are there
    where Period='YR' and between(cYear,lcStartYear,lcEndYear) ;
     order by 4,5,6,7 ;
     into cursor curWork  && This cursor would contain all necessary records in the ascending order (Since the stats table was prepopulated)
lnTally=_tally
if  lcOldSetTalk='OFF'
     set talk off && Restore set talk settings
endif
local PrevOnEsc, PrevEscape, lnCount, ;
     halt, lnUpdateNumber, msgTail, loTherm, loTemp, i, m.UseDesc
for i=1 to 5
     local ('m.Yr'+transform(i)+'Med'), ('m.Yr'+transform(i)+'Num'), ;
           ('m.Yr'+transform(i)+'Vol')
next
* support user Escapes for interrupting the main loop
PrevOnEsc = on('escape')                  && save previous Escape handler
PrevEscape = set('escape')                && previous Escape enablement state
set escape on                             && enable escape handling
halt = .f.                                && allow loop to run until this flag is toggled
on escape halt = .t.                      && force immediate termination if user escapes
store 0 to lnCount
set message to 'Calculating statistics for '+transform(lnTally)+' records'
do case
case lnTally<100 && Very rare case
     lnUpdateNumber=1
case between(lnTally,100,100000)
     lnUpdateNumber=100
case lnTally>100000
     lnUpdateNumber=val('1'+replicate('0',len(transform(lnTally))-3))
endcase
* assemble fixed portion of status bar message outside of loop, for speed
msgTail = "/" + transform(lnTally) + ".  Wait or press Esc to cancel ..."

*--- instantiate thermometer bar class....
loTherm = newobject("thermometer", "wg.vcx","","Calculation Progress for: "+dbf('OutTable'),lnTally)
loTherm.show()
do while !eof()
     scatter memvar
     for i=1 to 5
          lnCount=lnCount+1
* check for user Escape
          if m.halt                                   && user escaped
               exit                                   && fall out of loop
          endif

** Update status message
          if mod(lnCount,100) = 0
               set message to 'Record # '+transform(lnCount)+m.msgTail
          endif

** Update thermometr
          if mod(lnCount,lnUpdateNumber) = 0
               loTherm.update(lnCount)
          endif
          store MedSale to ('m.Yr'+transform(i)+'Med')
          store NumSales to ('m.Yr'+transform(i)+'Num')
          store VolSales to ('m.Yr'+transform(i)+'Vol')
          if !eof()
               skip && Goto next record
          endif
          if i=5 && Last
               do case
               case m.UseGrp='ALL'
                    m.UseDesc='All Sales'
               case m.UseGrp='CND'
                    m.UseDesc='Condo'
               case m.UseGrp='1FA'
                    if lcState='CT'
                         m.UseDesc='1-4 Family'
                    else
                         m.UseDesc='1 Family'
                    endif
               endcase
               if m.ccode<>'ZZ' and m.County=replicate('Z',15)
                    m.County=GetDescription(m.ccode,'Towns','CCode','County')
               endif
               insert into OutTable from memvar
          endif
     next
enddo
release loTherm
** Restore previous settings
on escape &PrevOnEsc
set escape &PrevEscape
set message to ' '
use in curWork
return !m.halt
If it's not broken, fix it until it is.


My Blog
Previous
Reply
Map
View

Click here to load this message in the networking platform