Page 1 of 1 1
Topic Options
#77529 - 2001-04-06 07:23 PM My First Function: BubbleUp()
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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).]

Top
#77530 - 2001-04-07 06:43 PM Re: My First Function: BubbleUp()
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
The good olde create shortcut function...

code:

break on


$shortcut = "%userprofile%\desktop\notepad.lnk"
$target = "notepad.exe"
$arguments = "c:\winnt\system32\config.nt"


$= shortcut("$shortcut","$target")


exit


;
; use wsh's shell object to create a shortcut...
;
function shortcut($path,$target,optional $arguments)
;
$shell = createobject("wscript.shell")
if $shell
$shortcut = $shell.createshortcut("$path")
if $shortcut
$shortcut.targetpath = "notepad.exe"
$shortcut.arguments = "$arguments"
$shortcut.save()
endif
endif
$shortcut=@error
;
endfunction


Shawn

[This message has been edited by Shawn (edited 07 April 2001).]

Top
Page 1 of 1 1


Moderator:  ShaneEP, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 509 anonymous users online.
Newest Members
min_seow, Audio, Hoschi, Comet, rrosell
17881 Registered Users

Generated in 0.05 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.