Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Strange calculation
Message
 
To
05/11/2008 09:03:14
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows XP
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01359766
Message ID:
01359830
Views:
30
>Current Values in field
>
>24900
>70200
>71500
>=====
>166600
>
>
>Supposed variable named Balance is=157360
>
>
>I want to get following values to equilize balance value
>
>15660
>70200
>71500
>=====
>157360
CREATE CURSOR crsTest (Fld1 I, Fld2 I)
INSERT INTO crsTest VALUES(24900,0)
INSERT INTO crsTest VALUES(70200,0)
INSERT INTO crsTest VALUES(71500,0)

newBalance = 157360
SELECT SUM(Fld1) FROM crsTest INTO ARRAY laOldBalance
koef = newBalance/laOldBalance[1]
lcAllSum = 0
SCAN
   REPLACE Fld2 WITH ROUND(Fld1*koef,0)
   lcAllSum = lcAllSum + Fld2
   IF RECNO() == RECCOUNT()
      REPLACE Fld2 WITH Fld2 + newBalance - lcAllSum 
   ENDIF
ENDSCAN
BROWSE NORMAL
SELECT SUM(Fld1), SUM(Fld2) FROM crsTest
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform