This is my first UDF: BubbleUp()
It's just the olde standard bubble sort routine. But it does tanslates into k2k rather nicely.
code:
break on
; sort some strings...
$array = Peach,Pumpkin,Orange,Grape,Lime,Apple,Rasberry,Cherry,Lemon
$array = bubbleup($array)
for each $element in $array
? $element
next
; sort some integers...
$array = 109,75,200,25,38,19,150,11,20
$array = bubbleup($array)
for each $element in $array
? $element
next
exit
;============================================
; Bubble sort argv(0)...argv(n) increasing...
;============================================
function bubbleup($argv)
;
if ubound($argv)
$i=0
while $i < ubound($argv)
$m = $argv[$i]
$j = $i + 1
while $j < ubound($argv)+1
if $argv[$j] < $m
$m = $argv[$j]
$argv[$j] = $argv[$i]
$argv[$i] = $m
endif
$j=$j+1
loop
$i=$i+1
loop
endif
$bubbleup = $argv
;
endfunction
I was once asked if it was possible to sort the NT Eventlog system sources string after one appended a new source...
manupilate Reg_multi_sz key
My answer was that it was basically a pain in the a$$ because one would have to write a routine to parse the "string|string|string" REG_MULTI_SZ thingy, then sort it, then rebuild the "string|string|string" thingy (phew!)...
Well, now that k2k has the SPLIT() function, and with a bubble sort UDF, at least 2/3rd's of the job is covered-off!
code:
break on
$system = "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\EventLog\System"
; read the eventlog string, append a new source just before the
; workstation service (whazzup?), sort it and display it !
$sources = bubbleup(split(readvalue("$system", "sources")+"whazzup?","|"))
for each $source in $sources
? $source
next
exit
function bubbleup($argv)
;
if ubound($argv)
$i=0
while $i < ubound($argv)
$m = $argv[$i]
$j = $i + 1
while $j < ubound($argv)+1
if $argv[$j] < $m
$m = $argv[$j]
$argv[$j] = $argv[$i]
$argv[$i] = $m
endif
$j=$j+1
loop
$i=$i+1
loop
endif
$bubbleup = $argv
;
endfunction
Shawn.
[This message has been edited by Shawn (edited 07 April 2001).]