Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
FAQ Addition?
#1
For a secret project of mine (hint, it has to do with yellow circles..), I needed to make myself a file opener and closer. After about three seconds in the FAQ/Wiki, I found Na_th_an's short and wonderful code for getting file names. I thought it would be useful to create a standalone and bare option selection program. (again... this is about the one billionth time I program the same thing. But this time it's stand-alone..)

Maybe someone could put the function in the FAQ? Feel free to add any descriptive comments, too.....

Code:
DECLARE FUNCTION option.select% (array1() AS STRING, start.x AS INTEGER, start.y AS INTEGER, unselected.color AS INTEGER, selected.color AS INTEGER, rollover AS INTEGER)
DIM option.list%(1 TO 1)
CLS
CHDIR "C:\qbasic\myprogs\pacman\"
SHELL "dir *.txt /b >list.dir"
f% = FREEFILE
option.amount% = 0
OPEN "list.dir" FOR INPUT AS #f%
DO
LINE INPUT #f%, file$
options$ = options$ + file$ + "|"
option.amount% = option.amount% + 1
LOOP UNTIL EOF(f%)
CLOSE #f%
KILL "list.dir"

REDIM option.list$(1 TO option.amount%)

FOR i% = 1 TO option.amount%
filename.break% = INSTR(options$, "|")
option.list$(i%) = MID$(options$, 1, filename.break% - 1)
options$ = MID$(options$, filename.break% + 1)
NEXT i%
a% = option.select(option.list$(), 4, 4, 2, 4, 1)
IF a% <> -1 THEN PRINT : PRINT : PRINT "Selected " + option.list$(a%)

FUNCTION option.select% (array1() AS STRING, start.x AS INTEGER, start.y AS INTEGER, unselected.color AS INTEGER, selected.color AS INTEGER, rollover AS INTEGER)
'If the result of the function is -1, then escape (cancel!) option has been used.
DIM start.option%, end.option%, current.choice%, i%, i$
start.option = LBOUND(array1)
end.option = UBOUND(array1)
i$ = CHR$(0) + "P"
DO
DO
IF i$ <> "" THEN EXIT DO
i$ = INKEY$
LOOP
'Query for key.
SELECT CASE i$
CASE CHR$(0) + "H": current.choice = current.choice - 1 'Up arrow key
IF current.choice < start.option THEN
IF rollover = 1 THEN
current.choice = end.option
ELSE
current.choice = start.option
END IF
END IF
CASE CHR$(0) + "P": current.choice = current.choice + 1 'Down arrow key
IF current.choice > end.option THEN
IF rollover = 1 THEN
current.choice = start.option
ELSE
current.choice = end.option
END IF
END IF
CASE CHR$(0) + "K": current.choice = current.choice - 1 'Left arrow key
IF current.choice < start.option THEN
IF rollover = 1 THEN
current.choice = end.option
ELSE
current.choice = start.option
END IF
END IF
CASE CHR$(0) + "M": current.choice = current.choice + 1 'Right arrow key
IF current.choice > end.option THEN
IF rollover = 1 THEN
current.choice = start.option
ELSE
current.choice = end.option
END IF
END IF
CASE CHR$(27): option.select% = -1: EXIT DO             'Escape key
CASE CHR$(13): option.select% = current.choice: EXIT DO 'Enter key
END SELECT
i$ = ""
'Print
FOR i% = start.option TO end.option
IF i% = current.choice THEN
COLOR selected.color
ELSE
COLOR unselected.color
END IF
LOCATE i% + start.y, start.x: PRINT array1$(i%);
NEXT i%

LOOP

'by Agamemnus --http://www.geocities.com/pisforpi/flyingsoft/
END FUNCTION
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."

Visit www.neobasic.net to see rubbish in all its finest.
Reply
#2
Just PM me or HD and you'll get access to the FAQ. You have interesting things to add, so ... Big Grin become one of the "elite QBers" Big Grin!!
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#3
*laughs*

Good.
img]http://usuarios.vtr.net/~disaster/sigs/annoyizer.php[/img]
Reply
#4
Tongue Jejeje - tío, tener acceso al FAQ nos hace importantes... ¿o no? Big Grin
SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
Reply
#5
Quote:Just PM me or HD and you'll get access to the FAQ. You have interesting things to add, so ... Big Grin become one of the "elite QBers" Big Grin!!

Now I understand!!!!

[shout] ONLY ESPAÑOL speaking ppl get to post there[/shout]

/jk
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)