I'm looking for some simple code to do some text-mode windows with scrollable pick lists. I don't need anything fancy.
Does anyone have a favorite library they would recommend, or some code they would share?
small window/picklist routines?
- Codemss
- Veteran
- Posts: 124
- Joined: Sun Jun 24, 2007 6:49 am
- Location: Utrecht, The Netherlands
- Contact:
I don't believe it is that hard: if you stick 15 minutes in it, you will probably have a good one. If you really have no idea: You know the command "LOCATE row%, column%"? It will be usefull. Also you need to know about arrays(some kind of list)...
If you make an array with all options and define some variables ehm, :
-1 Where the list starts displaying(integer)
-2 What choice is selected(integer)
-3 The size of the display screen for the list(how many items are displayed)
-4 Maximum number for the 1st variable
Then you need to make it possible that the user scrolls, probably with some ASCII character. If scrolled down, increase the first variable, but if it's bigger then the 4th variable(this could be a constant too), set it to the 4th variable. Then, to display it, start at variable 1 and go down to variable 1 + variable 3. Use LOCATE, PRINT and maybe LEFT$ for it. Ow, and check if the choice is selected(if current number of choice = variable 2), then print it with special colors (use COLOR).
This may be very messy, if you still got problems, I can probably make some code. It aint that hard. Just try.
Greets,
Codemss
If you make an array with all options and define some variables ehm, :
-1 Where the list starts displaying(integer)
-2 What choice is selected(integer)
-3 The size of the display screen for the list(how many items are displayed)
-4 Maximum number for the 1st variable
Then you need to make it possible that the user scrolls, probably with some ASCII character. If scrolled down, increase the first variable, but if it's bigger then the 4th variable(this could be a constant too), set it to the 4th variable. Then, to display it, start at variable 1 and go down to variable 1 + variable 3. Use LOCATE, PRINT and maybe LEFT$ for it. Ow, and check if the choice is selected(if current number of choice = variable 2), then print it with special colors (use COLOR).
This may be very messy, if you still got problems, I can probably make some code. It aint that hard. Just try.
Greets,
Codemss
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
- Codemss
- Veteran
- Posts: 124
- Joined: Sun Jun 24, 2007 6:49 am
- Location: Utrecht, The Netherlands
- Contact:
Here is some code. Try to understand it. I tried to give the variables self-explaining names. I can add some comments if you want. BTW, you can change the variables, but the program will get an error if you make the values too large or small (for example if you tweak the list so that it becomes bigger then the screen).
Code: Select all
CLS
DEFINT A-Z
COLOR 15, 0
DIM items
items = 57
DIM item(items) AS STRING
DIM itemontop, selecteditem
DIM listrow, listcol
DIM listheight, listwidth
DIM maxontop
itemontop = 0' Start with first item
selecteditem = 0' First item selected
listrow = 5
listcol = 5
listheight = 8
listwidth = 14
maxontop = items - listheight
RANDOMIZE TIMER
char = 65
FOR c = 0 TO items
length = INT(RND * 15) + 1
FOR l = 1 TO length
item(c) = item(c) + CHR$(char)
NEXT
char = char + 1
NEXT
FOR x = listcol TO listcol + listwidth + 2
LOCATE listrow - 1, x: PRINT "?"
LOCATE listrow + listheight + 1, x: PRINT "?"
NEXT
FOR y = listrow TO listrow + listheight
LOCATE y, listcol - 1: PRINT "?"
LOCATE y, listcol + listwidth + 1: PRINT "?"
LOCATE y, listcol + listwidth + 2: PRINT "?"
LOCATE y, listcol + listwidth + 3: PRINT "?"
NEXT
LOCATE listrow - 1, listcol - 1: PRINT "?"
LOCATE listrow + listheight + 1, listcol - 1: PRINT "?"
LOCATE listrow + listheight + 1, listcol + listwidth + 1: PRINT "?"
LOCATE listrow + listheight + 1, listcol + listwidth + 3: PRINT "?"
LOCATE listrow - 1, listcol + listwidth + 1: PRINT "?"
LOCATE listrow - 1, listcol + listwidth + 3: PRINT "?"
curscroll = 0
LOCATE curscroll + listrow, listcol + listwidth + 2: PRINT "?"
DO
currow = listrow
FOR c = itemontop TO itemontop + listheight
LOCATE currow, listcol
IF c = selecteditem THEN COLOR 0, 15 ELSE COLOR 15, 0
length = LEN(item(c))
IF length <listwidth> items THEN selecteditem = items
IF key$ = CHR$(0) + "H" THEN selecteditem = selecteditem - 1: IF selecteditem < 0 THEN selecteditem = 0
IF key$ = CHR$(27) THEN COLOR 15, 0: END
IF key$ = CHR$(0) + "M" OR key$ = " " THEN COLOR 15, 0: LOCATE 1, 1: PRINT "You choose: " + item(selecteditem): SLEEP: END
IF (selecteditem * listheight) \ items <curscroll> itemontop + listheight THEN itemontop = itemontop + 1
IF selecteditem < itemontop THEN itemontop = itemontop - 1
LOOP
END
Check out my site: <a href="http://members.lycos.nl/rubynl">Click here</a>
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL
Hope you like it. Send some feedback if you want: <a href="mailto:basicallybest@live.nl">Mail me</a>
Codemss, before known as RubyNL