Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ASCII scrollable list with mouse
#2
I've had scrollable lists for ages now, and this is basically the simple concept that they're built upon. (This example is just keyboard driven, without mouse support, though it'd be easy enough to add to navigate the scrollable list. Wink )

Code: (Select All)
Dim options(20) As String
For i = 0 To 20
    options(i) = "Option #" + _Trim$(Str$(i))
Next

Do
    Cls
    Print "Hit #1 to 9 to choose an option, or up/down arrow to scroll choices."
    DisplayList 10, 10, 20, 9, e, options(), -1
    k = _KeyHit
    Select Case k
        Case 18432: e = e - 1: If e < 0 Then e = 0
        Case 20480: e = e + 1: If e > 20 Then e = 20
        Case 49 To 57: chose = k + e - 49: Exit Do
        Case 27: System
    End Select
    _Limit 30
    _Display
Loop
Print
Print "You chose option #"; chose

Sub DisplayList (x As Integer, y As Integer, w As Integer, l As Integer, s As Integer, choices() As String, numbered As _Byte)
    'x/y location to place the start of our list
    'w is the width of our list on the screen
    'l is the length of the list items we want to display at a time
    's is the starting element that we want to display on the screen
    'choices() is the array that holds the actual list for us
    'numbered is the toggle for if we want to autonumber our list or not.  0 is false, any other number is true.

    'Some basic error checking is in need here
    If s < LBound(choices) Then s = LBound(choices)
    If s + l - 1 > UBound(choices) Then l = UBound(choices) - s + 1

    Locate x
    start = s: finish = s + l - 1
    For i = start To finish
        counter = counter + 1
        If numbered Then counter$ = LTrim$(Str$(counter)) + ") "
        Locate , y: Print counter$ + Left$(choices(i), w - Len(counter$))
    Next
End Sub

Less than 10 actual lines for the code which actually displays the list for us. Hard to get much more barebone than that! Wink
Reply


Messages In This Thread
RE: ASCII scrollable list with mouse - by SMcNeill - 10-23-2022, 08:55 AM
RE: ASCII scrollable list with mouse - by bplus - 10-23-2022, 11:50 AM
RE: ASCII scrollable list with mouse - by Pete - 10-23-2022, 02:54 PM



Users browsing this thread: 2 Guest(s)