User Tools

Site Tools


pslist - simple list select Sub routine

' MMBasic DOS 5-04-05 Beta 7 ' Program pslist.bas ' by Peter Svard 2017.09.23 '


' show how to use pslist
Colour 7,0

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 ---
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;"          "


Cursor 1,20


' --- 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
Read s
If s="" Then Exit Do
Cursor col,row+i
Print s
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
    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 ---
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<pslistmax-1 Then i=i+1 ' Down
  Colour bc,fc ' show list cursor
  Cursor col,row+i
  Print psmemlist(i);
End If

Colour 7,0 ' set default colour

End Sub

' Different samples of list (always ends lists with an empty string)
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",""
mmbasic/pslist_simple_list_select_sub_routine.txt · Last modified: 2024/02/08 13:03 by disco4now