I have these ninety numbers
For each number I must calculate the frequency
that is, how many times this number is repeated in the archive and in the same position, compared to the number of records where I have positioned myself
- Code: Select all Expand view
- EstrattoFrequenza(nNumber,nWheel,npos,nrecord)
with this function I pass the following parameters
nNumber the number to search
nWheel a number (from 1 to 11)
npos the position ( from 1 to 5)
nrecord the number of record where I have positioned myself
Of course I am using tdatabase
the function
- Code: Select all Expand view
- Function EstrattoFrequenza(nNumber,nWheel,nPos,nRecord)
local oFreq,primo
local frequency:=0
local r1,r2,r3,r4,r5
local cDir := ".\data\"
local lFound:=.f.
//take the field I need
do case
case nWheel = 1
r1:= "BA1"
r2:= "BA2"
r3:= "BA3"
r4:= "BA4"
r5:= "BA5"
case nWheel = 2
r1:= "CA1"
r2:= "CA2"
r3:= "CA3"
r4:= "CA4"
r5:= "CA5"
case nWheel = 3
r1:= "FI1"
r2:= "FI2"
r3:= "FI3"
r4:= "FI4"
r5:= "FI5"
case nWheel = 4
r1:= "GE1"
r2:= "GE2"
r3:= "GE3"
r4:= "GE4"
r5:= "GE5"
case nWheel = 5
r1:= "MI1"
r2:= "MI2"
r3:= "MI3"
r4:= "MI4"
r5:= "MI5"
case nWheel = 6
r1:= "NA1"
r2:= "NA2"
r3:= "NA3"
r4:= "NA4"
r5:= "NA5"
case nWheel = 7
r1:= "PA1"
r2:= "PA2"
r3:= "PA3"
r4:= "PA4"
r5:= "PA5"
case nWheel = 8
r1:= "RM1"
r2:= "RM2"
r3:= "RM3"
r4:= "RM4"
r5:= "RM5"
case nWheel = 9
r1:= "TO1"
r2:= "TO2"
r3:= "TO3"
r4:= "TO4"
r5:= "TO5"
case nWheel = 10
r1:= "VE1"
r2:= "VE2"
r3:= "VE3"
r4:= "VE4"
r5:= "VE5"
case nWheel = 11
r1:= "NZ1"
r2:= "NZ2"
r3:= "NZ3"
r4:= "NZ4"
r5:= "NZ5"
endcase
oFreq:=TDatabase():Open( , cDir+"demo", "DBFCDX", .T. )
oFreq:setorder(0)
oFreq:goTop()
do while (oFreq:RecNo() != nRecord .AND. !lFound)
//position
Do case
case nPos=1
If oFreq:&r1 = nNumber
lFound:=.t.
Endif
case nPos=2
If oFreq:&r2 = nNumber
lFound:=.t.
Endif
case nPos=3
If oFreq:&r3 = nNumber
lFound:=.t.
Endif
case nPos=4
If oFreq:&r4 = nNumber
lFound:=.t.
Endif
case nPos=5
If oFreq:&r5 = nNumber
lFound:=.t.
Endif
Endcase
IF lFound
frequency:= frequency+1
Endif
oFreq:skip(1)
Enddo
oFreq:close()
return frequency
I tried to make a function but the calculation slows down the display a lot and I really don't know how to solve to speed up the calculation
Any suggestion ? Any Help pls !!!