Author Topic: File Navigator 1.0: a simple demo for an ASCII scroll-list of files in folder  (Read 3067 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Hi
in pure QBasic
here a simple demonstration about how to do a scroll-list with selection of some elements.
The input of list is from a file, but it can be changed at your need.
The input of user is keyboard, but it can be expanded at your need to mouse and joystick.
The output is an ASCII boxed scrollable list, but it can be changed in graphic primitive or graphic images at your need.
 
in this case I use this method to show the files of a folder.

Code: QB64: [Select]
  1. DECLARE SUB AllList (Max AS INTEGER)
  2. Const Max = 500
  3. Dim F(1 To Max) As String, S(1 To Max) As String * 2
  4. n = 0
  5. NameFile$ = "filedir.tmp"
  6. On Error GoTo Nofile
  7. Color 7, 0
  8. Shell "dir  /b> " + NameFile$
  9. Open NameFile$ For Input As #1
  10.     n = n + 1
  11.     Line Input #1, F(n)
  12.     S(n) = "  "
  13.     If wide < Len(F(n)) Then wide = Len(F(n))
  14.  
  15. Kill NameFile$
  16. Upper = n
  17.  
  18. 'AllList Upper
  19. ChoiceList Upper, wide
  20.  
  21.  
  22. Nofile:
  23. Print " Error "; FileName$ + " not found!"
  24.  
  25.  
  26. Sub ChoiceList (Umax As Integer, wid As Integer)
  27.     Shared F() As String, S() As String * 2
  28.     a = 0
  29.     k$ = ""
  30.     If i = 0 Then i = 1: n = i
  31.     ' 183 · 186º 189 ½ 196 Ä 211 Ó 214  Ö
  32.  
  33.     Do
  34.         ' here is the output of list
  35.         Color 7, 0
  36.         If i < n Or i > (n + 15) Then n = i
  37.         Locate 4, 23
  38.         Print "Ö" + String$(wid + 3, "Ä") + "·"
  39.         For a = n To n + 15 Step 1
  40.             If a > Umax Then M$ = Space$(wid + 3) Else M$ = " " + F(a) + S(a) + Space$(wid - Len(F(a)))
  41.             If a = i Then Color 15, 0
  42.             Locate , 23
  43.             Print "º" + M$ + "º"
  44.             If a = i Then Color 7, 0
  45.         Next a
  46.         Locate , 23
  47.         Print "Ó" + String$(wid + 3, "Ä") + "½"
  48.         Locate , 23
  49.         Print Chr$(24) + Chr$(25) + " move, S select, D done"
  50.  
  51.  
  52.  
  53.         ' here is the user input from keyboard
  54.         Do
  55.             k$ = UCase$(InKey$)
  56.             ' it switches the selector
  57.             If k$ = "S" Then If S(i) = "  " Then S(i) = "<-" Else S(i) = "  "
  58.             ' down
  59.             If k$ = Chr$(0) + "P" Then If i < Umax Then i = i + 1
  60.             'up
  61.             If k$ = Chr$(0) + "H" Then If i > 1 Then i = i - 1
  62.             If k$ = "D" Then Exit Sub 'Return ' all selection has been done
  63.         Loop Until k$ <> ""
  64.     Loop
  65.     'Return
  66.  
  67. Sub AllList (UMax As Integer)
  68.     Shared F() As String, S() As String * 2
  69.     ' debug SUB to show the whole list
  70.     For a = 1 To UMax Step 1
  71.         Print F(a) + S(a)
  72.         If a Mod 15 = 0 Then Sleep 2
  73.     Next a
  74.  

Happy Coding in the New Year!

PS: QB64 beats QBasic for NOT get back a QBasic Parser bug:
If you DIM a string array suffix, if you SHARED that string array from into the SUB, you cannot use the suffix for define datatype but you must use AS.
Doing so you fall in Parser error that alert you; SUB shared variable isn't declared at main module! LOL

Instead QB64 recognizes that the same name with or without suffix  are the same if declared as the same type of data.
Here the issue of Qbasic showed in code.
Code: QB64: [Select]
  1. DIM Me$ (1 to 10)
  2.  
  3. 'main
  4.  
  5. SUB foo
Programming isn't difficult, only it's  consuming time and coffee