ooook!

a brief explanation, i am putting entries into the registry and they will only be kept there for the length of the $purgetime.

What I have been seeing is.... say i run the script against data that has been in place for a number of hours since I last ran this test script, it looks like enumval is not returning all of the entries. But, run the script 3 or 4 times in a row and it will eventually purge all of the old entries.

all of this action is taking place in the BUILDPD function.

code:
break on

;? serialtime("23:59")
;exit(0)
$database = "HKEY_CURRENT_USER\Software\OPDB"


buildpd

exit(0)

Function CheckOPDBEngine
dim $pilotQue, $i, $temp

$pilotQue = getdb($database,"status","onlinepilots")

while not @error
$temp = enumval($database + "\onlinepilots\inuse",$i)
$i = $i + 1

loop


endfunction


function BUILDPD
dim $pilots, $totalpilots, $groupsize,$i, $temp, $ts, $datedif, $timedif, $purgetime, $pilot,
$totalcount

$pilots = getonlinepilots

if not @error
$totalpilots = ubound($pilots)

for $i = 0 to $totalpilots
$temp = split($pilots[$i],",")
putdb($database,"OnlinePilots",$temp[2],@date+","+@time)
next
else
exit(@error)
endif
if not getdb($database,"settings","Purgetime")
$purgetime = "01:00:00"
putdb($database,"settings","Purgetime",$purgetime)
else
$purgetime = getdb($database,"settings","Purgetime")
endif

$i = 0
$Pilot = enumvalue($database + "\Onlinepilots",$i)
while not @error
? $i " " $pilot
$ts = split(getdb($database,"onlinepilots",$Pilot),",")
if ubound($ts) = 1
$dateDif = serialdate(@date) - serialdate($ts[0])
select
case $datedif = 1
$timedif = (val(serialtime("23:59:59")) - val(serialtime($ts[1]))) + val(serialtime("00:10:00"))
case $datedif > 1
$ = delvalue($database + "\onlinePilots",$pilot)
case 1
$timedif = (val(serialtime(@time)) - val(serialtime($ts[1])))
endselect

;? $ts[1] " " $timedif " " serialtime($purgetime) " " $pilot
if val($timedif) > val(serialtime($purgetime))
$ = delvalue($database + "\onlinePilots",$pilot)
else
$totalcount = $totalcount+1
endif
endif
$i = $i + 1
$Pilot = enumvalue($database + "\Onlinepilots",$i)
loop
putdb($database,"status","OnlinePilots",$totalcount)
$ = deltree($database + "\onlinepilots\inuse")
endfunction

function PutDB($database,$section,$key,$data)
dim $nul
$nul = writevalue($database + "\" + $section,$key,$data,"REG_SZ")
exit(@error)
endfunction

function GetDB($database,$section,$key)
$getdb = readvalue($database + "\" + $section,$key)
exit(@error)
endfunction



function GetonlinePilots()
dim $doc, $data, $octs, $sols, $quan, $count, $array, $delim, $pilot
$delim = ","

if not $josshdownload
$josshdownload = createobject("microsoft.xmlhttp")
if @Error <> 0
exit(@error)
endif
endif

$Josshdownload.open("GET", "http://www.jossh.com/jgeng/PilotViewer?list=onlinepilotsonly", not 1)
$josshdownload.send

while $josshdownload.readystate <> 4
;busyflash_event()
;$nul = execute($gui.DoEvents(1))
sleep(0.0625)
loop

if $josshdownload.responsetext

$data = $josshDownload.responsetext
$data = split($data,'VALIGN=')
if ubound($data) = 0
exit(1)
endif
$data = split($data[3],"<TD BGCOLOR=")

$sols = split($data[1],"<BR>")
$octs = split($data[2],"<BR>")
$quan = split($data[3],"<BR>")

$sols[0] = substr($sols[0],instr($sols[0],"<IMG"))
redim preserve $sols[ubound($sols)-1]

for $count = 0 to ubound($sols)
$pilot = $sols[$count]
$sols[$count] = "S" + $delim
if instr($pilot, "Honor Guard")
$sols[$count] = $sols[$count] + "hg" + $delim
else
$sols[$count] = $sols[$count] + "civ" + $delim
endif
$pilot = split($pilot,">")
$pilot = substr($pilot[ubound($pilot)-1],1,len($pilot[ubound($pilot)-1])-3)
$sols[$count] = $sols[$count] + $pilot
next

$octs[0] = substr($octs[0],instr($octs[0],"<IMG"))
redim preserve $octs[ubound($octs)-1]

for $count = 0 to ubound($octs)
$pilot = $octs[$count]
$octs[$count] = "O" + $delim
if instr($pilot, "Honor Guard")
$octs[$count] = $octs[$count] + "hg" + $delim
else
$octs[$count] = $octs[$count] + "civ" + $delim
endif
$pilot = split($pilot,">")
$pilot = substr($pilot[ubound($pilot)-1],1,len($pilot[ubound($pilot)-1])-3)
$octs[$count] = $octs[$count] + $pilot
next

$quan[0] = substr($quan[0],instr($quan[0],"<IMG"))
redim preserve $quan[ubound($quan)-2]

for $count = 0 to ubound($quan)
$pilot = $quan[$count]
$quan[$count] = "Q" + $delim
if instr($pilot, "Honor Guard")
$quan[$count] = $quan[$count] + "hg" + $delim
else
$quan[$count] = $quan[$count] + "civ" + $delim
endif
$pilot = split($pilot,">")
$pilot = substr($pilot[ubound($pilot)-1],1,len($pilot[ubound($pilot)-1])-3)
$quan[$count] = $quan[$count] + $pilot
next

dim $array[ubound($sols) + ubound($Octs) + ubound($quan)+2]


$count = 0
for each $pilot in $sols
$array[$count] = $pilot
$count = $count+1
next

for each $pilot in $octs
$array[$count] = $pilot
$count = $count+1
next

for each $pilot in $quan
$array[$count] = $pilot
$count = $count+1
next


$getonlinepilots = $array
else
exit(1)
endif

$josshdownload.abort

endfunction

function SerialTime($TorS)
; Syntax: SerialTime(Time | Serial)
; Where Time is a time string in HH:MM[:SS] format or
; Serial is a time serial number (seconds since midnight) 1 - 86399
; If Time is supplied, SerialTime will return the seconds since midnight.
; If seconds since midnight is supplied, SerialTime will return a time.
; DEPENDENCIES: word(), abs(), mod()
dim $Hours, $Minutes, $Seconds, $Serial, $Error
$Error = 0
if instr($TorS,":") ; Time supplied
$TorS = "" + $TorS ; Cast to string
if len($TorS) > 4 and len($TorS) < 9
$Hours = 0 + word($TorS,1,":") ; Hours as integer for calculation
if $Hours > 23 $Error = 1 endif
$Minutes = 0 + word($TorS,2,":") ; Minutes as integer for calculation
if $Minutes > 59 $Error = 1 endif
$Seconds = 0 + word($TorS,3,":") ; Seconds as integer for calculation
if $Seconds > 59 $Error = 1 endif
$Serial = ($Hours * 3600) + ($Minutes * 60) + $Seconds
if $SerialTime > 86399 $Error = 1 endif
if $Error
$SerialTime = "-1" ; Error
else
$SerialTime = "" + $Serial ; Return as string
endif
else
$SerialTime = "-1" ; Error
endif
else ; Seconds supplied
$TorS = 0 + $TorS ; Cast to integer for calculation
if $TorS <= 86399 and $TorS >= 0
$Hours = $TorS / 3600
$TorS = $TorS - ($Hours * 3600)
$Hours = "" + $Hours
$Hours = substr("00",1,2 - len($Hours)) + $Hours
$Minutes = $TorS / 60
$TorS = $TorS - ($Minutes * 60)
$Minutes = "" + $Minutes
$Minutes = substr("00",1,2 - len($Minutes)) + $Minutes
$Seconds = "" + $TorS
$Seconds = substr("00",1,2 - len($Seconds)) + $Seconds
$SerialTime = $Hours + ":" + $Minutes + ":" + $Seconds ; Return as string
else
$SerialTime = "-1" ; Error
endif
endif
endfunction

function abs($Expr)
;returns the absolute value of a number
$Expr=0+$Expr
if $Expr<0
$Expr=-1*$Expr
endif
$abs=$Expr
endfunction

FUNCTION Word($sStr, $iWrdNum, optional $strWS)
; Syntax: Word("string",number, ["white space characters"])
; Word number may be negative, in which case, words will be counted
; from the right of the string. I.e. -1 will return the last word in the string.
DIM $iWrdCtr, $iLen, $iStart, $iFinish, $iStep, $i
$Word='' $sStr=''+$sStr $strWS=''+$strWS
$iWrdNum=0+$iWrdNum $iLen=Len($sStr) $iWrdCtr=0
IF $strWS = '' $strWS = Chr(9) + Chr(32) + ',' ENDIF
IF $iWrdNum >= 0 ; Parse string forward
$iStart=1 $iFinish=$iLen $iStep=1
ELSE ; Parse string backward
$iStart=$iLen $iFinish=1 $iStep=-1
$iWrdNum=-1*$iWrdNum
ENDIF
IF $sStr <> '' AND $iWrdNum > 0
FOR $i = $iStart TO $iFinish STEP $iStep
IF InStr($strWS,SubStr($sStr,$i,1)) ; If whitespace
WHILE InStr($strWS,SubStr($sStr,$i,1)) AND ($i <= $iLen) ; skip it
$i=$i+$iStep
LOOP
ELSE ; If non-whitespace
$iWrdCtr = $iWrdCtr + 1 ; increment word counter
; If this is the correct word number, extract it
IF $iWrdCtr = $iWrdNum
WHILE NOT InStr($strWS,SubStr($sStr,$i,1)) AND ($i <= $iLen)
; Extract it in the right order!
IF $iStep = 1
$Word = $Word + SubStr($sStr,$i,1)
ELSE
$Word = SubStr($sStr,$i,1) + $Word
ENDIF
$i=$i+$iStep
LOOP
ELSE ;otherwise, skip the word
WHILE NOT InStr($strWS,SubStr($sStr,$i,1)) AND ($i <= $iLen)
$i=$i+$iStep
LOOP
ENDIF
ENDIF
$i=$i-$iStep
NEXT
ENDIF
ENDFUNCTION

function SerialDate($ExpD)
; Author: ScriptLogic Corporation
; parameter ($ExpD) must be a date (in the form of yyyy/mm/dd)
; or an integer previously derived by this function.
; if passed a date, it returns an integer.
; If passed an integer, it returns the date.
; Integers can be used for general-purpose math computations on dates
; and then converted back to dates by calling this function again.
; Algorithms were obtained from: http://www.capecod.net/~pbaum/date/date0.htm
dim $z,$h,$a,$b,$c,$y,$m,$d
if instr($ExpD,'/') ; date passed
$y=val(substr($ExpD,1,4))
$m=val(substr($ExpD,6,2))
$d=val(substr($ExpD,9,2))
if $m<3
$m=$m+12
$y=$y-1
endif
; return an integer
$SerialDate=$d+(153*$m-457)/5+365*$y+$y/4-$y/100+$y/400-306
else ; integer passed
$z=0+$ExpD+306 ; cast numeric
$h=100*$z-25
$a=$h/3652425
$b=$a-$a/4
$y=(100*$b+$h)/36525
$c=$b+$z-365*$y-$y/4
$m=(5*$c+456)/153
$d=$c-(153*$m-457)/5
if $m>12
$y=$y+1
$m=$m-12
endif
$m=right('0'+$m,2)
$d=right('0'+$d,2)
; return a string date
$SerialDate=''+$y+'/'+$m+'/'+$d
endif
endfunction



[ 28. November 2002, 07:05: Message edited by: Bryce ]