'
' MMBasic DOS 5-04-05 Beta 7
' Program pslist.bas
' by Peter Svard 2017.09.23
'
Cls
' show how to use pslist
Colour 7,0
Cls
Dim eKey As integer
Dim index As integer
Dim text As string
Cursor 10,1:Print "pslist - test: Use cusor key Up / Down "
Cursor 10,2:Print "use Enter-key to select, ESC-key for exit"
'
- main test loop -
Do
Restore pslist1
pslist 3,4,14,0,eKey,index,text
If eKey=27 Then Exit Do
' use index value to set a colour box to screen
Colour 7,index
Cursor 40,5:Print Space$(6)
Cursor 40,6:Print Space$(6)
Cursor 40,7:Print Space$(6)
' show return data from pslist
Colour 7,0
Cursor 40,10: Print " Return data from pslist Sub "
Cursor 40,11: Print " eKey = ";eKey;" "
Cursor 40,12: Print " index = ";index;" "
Cursor 40,13: Print " text = ";text;" "
Loop
Cursor 1,20
End
'
'
- pslist -
' col, row = list position
' fc, bc = colour foreground, background
' eKey = return key ( 13=Enter, 27=ESC key )
' index = return and start index position
' text = return text
'
Sub pslist(col As integer,row As integer,fc As integer,bc As integer, eKey As integer, index As integer, text As string)
Local i As integer
Local t As integer
Local s As string
Local psmemlist(25) As string
Local pslistmax As integer
Colour fc,bc
' Print out list to screen and read in list to psmemlist
' and finally set pslistmax
i=0
Do
Read s
If s="" Then Exit Do
Cursor col,row+i
Print s
psmemlist(i)=s
i=i+1
Loop
pslistmax=i ' save last list index position
' now time to setup for list loop routine
If index>-1 And index<=pslistmax Then
i=index ' use last index position
Else
i = 0 ' start at first list item (0=first item)
End If
Colour bc,fc ' show list cursor
Cursor col,row+i
Print psmemlist(i);
'
- main list loop start -
Do
t=Asc(Inkey$) ' wait for a Key
If t=13 Then ' Enter -key
eKey=t ' return eKey-code
index=i ' return list index
text=psmemlist(i) ' return text from list
Exit Do
End If
If t=27 Then ' ESC -key (only return eKey)
eKey=t ' return eKey-code
index=-1 ' return -1 index
text="" ' return empty text from list
Exit Do
End If
If t=128 Or t=129 Then ' cursor Up or Down
Colour fc,bc ' clear list cursor
Cursor col,row+i
Print psmemlist(i)
If t=128 And i>0 Then i=i-1 ' Up
If t=129 And i
Colour bc,fc ' show list cursor
Cursor col,row+i
Print psmemlist(i);
End If
Loop
Colour 7,0 ' set default colour
End Sub
'
' Different samples of list (always ends lists with an empty string)
'
pslist1:
Data "Black","Blue","Green","Cyan","Red","Purple","Yellow","White"
Data "Gray","Bright Blue","Bright Green","Bright Cyan","Bright Red"
Data "Bright Purple","Bright Yellow","Bright White",""