punkie -

Okay, here is my first attempt. Hopefully I have eradicated all the bugs. I have included a sample of how you would use the function. Have fun!

Shawn (or anyone else), I would appreciate any helpful suggestions you would have for improving this function.

code:
$menu = "Dir %systemdrive%", "Dir %windir%", "Type c:\autoexec.bat", "Type c:\config.sys", 
"Dir %userprofile%", "Dir %Temp%"
$pick = kixmenu ($menu,5,"Menu")

select case $pick = 0
shell "%comspec% /c dir %systemdrive%"
case $pick = 1
shell "%comspec% /c dir %windir%"
case $pick = 2
shell "%comspec% /c type c:\autoexec.bat"
case $pick = 3
shell "%comspec% /c type c:\config.sys"
case $pick = 4
shell '%comspec% /c dir "%userprofile%"'
case $pick = 5
shell '%comspec% /c dir "%temp%"'
endselect

; KixMenu.kix
; version 1.0 for Kix2001
; written by Dean E. Behrman
; created 06.25.2002

function kixmenu ($_array,$_maxrows,optional $_title)
;$_array: Items to display in tabular format
;$_maxrows: Specify the maximum number of rows in the table
;$_title: Optional title for the window

cls
if val(@kix) <> 4
? "Requires Kixtart 2001"
$kixmenu = -1
exit 1
endif

dim $_width,$_acount,$_cols,$_rows,$_currow,$_curcol,$_curitem,$_colitems[1],$_rowitems[1],$_x,$_key
$_rc = setoption("HideCursor","ON")
$_width = 0 $_currow = 0 $_curcol = 0 $_curitem = 0
if $_maxrows <= 0
$_maxrows = 24
endif

$_acount = ubound($_array)
for $_x = 0 to $_acount
$_item = $_array[$_x]
if len($_item) > $_width
$_width = len($_item)
endif
next

$_maxcols = 78 / ($_width + 1)
if $_maxcols < 1 or $_acount > ($_maxcols * $_maxrows)
$kixmenu = -1
goto end
endif
if $_acount / $_cols > $_maxrows
$kixmenu = -1
goto end
endif
$_cols = ($_acount / $_maxrows) + 1
$_rows = ($_acount + 1) / $_cols
gosub drawscreen
gosub buildmenu
gosub pickitem
:end
$rc = setoption("HideCursor","OFF")
cls
return

:drawscreen
Color w+/b
Box (0,0,$_maxrows+1,79,"SINGLE")
if $_title <> "" and $_title <> 0
at (0,1) $_title
endif
return

:buildmenu
$_curitem = 0
redim $_colitems[$_cols], $_rowitems[$_rows]
for $_curcol = 0 to $_cols
for $_currow = 0 to $_rows - 1
if $_curitem <= $_acount
at ($_currow + 1,$_curcol * ($_width + 1) + 1) $_array[$_curitem]
$_colitems[$_curcol] = $_currow
$_rowitems[$_currow] = $_curcol
endif
$_curitem = $_curitem + 1

next
next
return

:pickitem
$_currow = 0 $_curcol = 0 $_curitem = 0
gosub showcursor
at (0,0)
do
get $_key
if asc($_key) = 224 ; Extended Key
get $_key
if asc($_key) = 80 ; Down Arrow
gosub hidecursor
$_currow = $_currow + 1
$_curitem = $_curitem + 1
if $_currow > $_colitems[$_curcol]
$_currow = 0
$_curitem = $_curitem - $_colitems[$_curcol] - 1
endif
gosub showcursor
endif
if asc($_key) = 72 ; Up Arrow
gosub hidecursor
$_currow = $_currow - 1
$_curitem = $_curitem - 1
if $_currow < 0
$_currow = $_colitems[$_curcol]
$_curitem = $_curitem + $_colitems[$_curcol] + 1
endif
gosub showcursor
endif
if asc($_key) = 75 ; Left Arrow
gosub hidecursor
$_curcol = $_curcol - 1
if $_curcol < 0
$_curcol = $_rowitems[$_currow]
$_curitem = $_curitem + $_rowitems[$_currow] * $_rows
else
$_curitem = $_curitem - $_colitems[$_curcol] - 1
endif
gosub showcursor
endif
if asc($_key) = 77 ; Right Arrow
gosub hidecursor
$_prev = $_curcol
$_curcol = $_curcol + 1
if $_curcol > $_rowitems[$_currow]
$_curcol = 0
$_curitem = $_curitem - $_rowitems[$_currow] * $_rows
else
$_curitem = $_curitem + $_colitems[$_prev] + 1
endif
gosub showcursor
endif
endif
until asc($_key) = 13 or asc($_key) = 27 ; ENTER or ESC

if asc($_key) = 13
$kixmenu = $_curitem
else
$kixmenu = -2
endif
return

:showcursor
color b/w+
at ($_currow + 1,$_curcol * ($_width + 1) + 1) $_array[$_curitem]
color w/n
at (0,0)
return

:hidecursor
color w+/b
at ($_currow + 1,$_curcol * ($_width + 1) + 1) $_array[$_curitem]
color w/n
at (0,0)
return

endfunction


Estimated scripting time: 2 hours
_________________________
Dean