QB64.org Forum

Active Forums => Programs => Topic started by: bplus on August 23, 2019, 01:39:04 pm

Title: Tiny Navigator
Post by: bplus on August 23, 2019, 01:39:04 pm
Tiny Navigator fixed and can now go anywhere you are allowed on C:

Code: QB64: [Select]
  1. _TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  2. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  3. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  4. ' For some reason Windows won't write to a fully pathed file in my user folder???
  5. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  6. ' and now I can chDir anywhere!
  7.  
  8. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  9.  
  10. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  11.  
  12. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  13.  
  14.  
  15. SCREEN _NEWIMAGE(1200, 600, 32)
  16. _SCREENMOVE 100, 50
  17.  
  18.  
  19. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  20.  
  21. DIM mySelection&, done$
  22.  
  23.     PRINT "Current Directory: " + _CWD$
  24.     REDIM myFiles(0) AS STRING
  25.     loadFA "*.*", myFiles()
  26.     mySelection& = getArrayItemNumber&(5, 5, 90, 30, myFiles())
  27.     CLS
  28.     IF mySelection& <> -1719 THEN
  29.         CHDIR myFiles(mySelection&)
  30.     ELSE
  31.         PRINT "No Directory selected."
  32.         INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  33.     END IF
  34.     _LIMIT 60
  35. LOOP UNTIL done$ <> ""
  36.  
  37. SUB loadFA (spec$, fa() AS STRING)
  38.     DIM tmpFile$, Index%, fline$, d$
  39.     tmpFile$ = "C:\temp\DIR$INF0.INF"
  40.     'PRINT tmpFile$
  41.     'END
  42.     SHELL _HIDE "DIR /a:d >" + tmpFile$ 'get directories  but have to do a little pruning
  43.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  44.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  45.     OPEN tmpFile$ FOR INPUT AS #1
  46.     Index% = -1
  47.     DO WHILE NOT EOF(1)
  48.         LINE INPUT #1, fline$
  49.         IF INSTR(fline$, "<DIR>") THEN
  50.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  51.             Index% = Index% + 1
  52.             REDIM _PRESERVE fa(Index%)
  53.             fa(Index%) = d$
  54.         END IF
  55.     LOOP
  56.     CLOSE #1
  57.     KILL tmpFile$
  58.  
  59. FUNCTION rightOf$ (source$, of$)
  60.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  61.  
  62. 'attempting use this 4 things (2018-12-30)
  63. ' 1. expects HELP sub that uses message and message box but easy to comment out
  64. ' 2. expects to be in graphics mode
  65. ' 3. chages color of screen
  66. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  67. '
  68. ' Future Help Message Box for the function.
  69. ' "*** Mouse and Key Instructions ***"
  70. '
  71. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  72. ' "Press spacebar to select a highlighted item or just click it."
  73. ' "Use number(s) + enter to select an array item by it's index number,"
  74. ' "backspace will remove last number pressed, c will clear a number started."
  75. ' "Numbers started are shown in bottom right PgDn bar."
  76. ' "Enter will also select the highlighted item, if no number has been started."
  77. ' "Home starts you at lowest array index, End highlights then highest index."
  78. ' "Use PgUp and PgDn keys to flip through pages of array items."
  79. '
  80. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  81. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  82.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  83.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  84.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  85.  
  86.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  87.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  88.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  89.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  90.     DIM clrStr AS STRING, b AS STRING
  91.  
  92.     'save old settings to restore at end ofsub
  93.     curRow = CSRLIN
  94.     curCol = POS(0)
  95.     fg = _DEFAULTCOLOR
  96.     bg = _BACKGROUNDCOLOR
  97.     _KEYCLEAR
  98.  
  99.     maxWidth = boxWidth '       number of characters in box
  100.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  101.     lba = LBOUND(arr)
  102.     uba = UBOUND(arr)
  103.     page = 0
  104.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  105.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  106.  
  107.     GOSUB update '              show the beginning of the array items for selection
  108.  
  109.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  110.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  111.  
  112.     DO 'until get a selection or demand exit
  113.  
  114.         'handle the key stuff
  115.         kh& = _KEYHIT
  116.         IF kh& THEN
  117.             IF kh& > 0 AND kh& < 255 THEN
  118.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  119.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  120.  
  121.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  122.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  123.                     IF LEN(b$) THEN
  124.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  125.                             choice = VAL(b$): EXIT DO
  126.                         ELSE 'clear b$ to show some response to enter
  127.                             b$ = "": GOSUB update 'clear the value that doesn't work
  128.                         END IF
  129.                     ELSE
  130.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  131.                     END IF
  132.                 END IF
  133.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  134.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  135.                 IF kh& = 8 THEN 'backspace to edit number
  136.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  137.                 END IF
  138.             ELSE
  139.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  140.                     CASE 20736 'pg dn
  141.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  142.                     CASE 18688 'pg up
  143.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  144.                     CASE 18432 'up
  145.                         IF hlite - 1 < 0 THEN
  146.                             IF page > 0 THEN
  147.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  148.                             END IF
  149.                         ELSE
  150.                             hlite = hlite - 1: GOSUB update
  151.                         END IF
  152.                     CASE 20480 'down
  153.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  154.                             IF hlite + 1 > maxHeight - 1 THEN
  155.                                 page = page + 1: hlite = 0: GOSUB update
  156.                             ELSE
  157.                                 hlite = hlite + 1: GOSUB update
  158.                             END IF
  159.                         END IF
  160.                     CASE 18176 'home
  161.                         page = 0: hlite = 0: GOSUB update
  162.                     CASE 20224 ' end
  163.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  164.                 END SELECT
  165.             END IF
  166.         END IF
  167.  
  168.         'handle the mouse stuff
  169.         WHILE _MOUSEINPUT
  170.             IF _MOUSEWHEEL = -1 THEN 'up?
  171.                 IF hlite - 1 < 0 THEN
  172.                     IF page > 0 THEN
  173.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  174.                     END IF
  175.                 ELSE
  176.                     hlite = hlite - 1: GOSUB update
  177.                 END IF
  178.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  179.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  180.                     IF hlite + 1 > maxHeight - 1 THEN
  181.                         page = page + 1: hlite = 0: GOSUB update
  182.                     ELSE
  183.                         hlite = hlite + 1: GOSUB update
  184.                     END IF
  185.                 END IF
  186.             END IF
  187.         WEND
  188.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  189.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  190.             'clear mouse clicks
  191.             mb = _MOUSEBUTTON(1)
  192.             IF mb THEN 'clear it
  193.                 WHILE mb 'OK!
  194.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  195.                     _LIMIT 100
  196.                 WEND
  197.             END IF
  198.  
  199.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  200.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  201.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  202.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  203.                     EXIT DO 'escape plan for mouse click top right corner of display box
  204.                 ELSE 'PgUp bar clicked
  205.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  206.                 END IF
  207.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  208.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  209.             END IF
  210.         ELSE '   mouse over highlighting, only if mouse has moved!
  211.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  212.                 IF mx <> lastMX OR my <> lastMY THEN
  213.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  214.                         hlite = my - 1
  215.                         lastMX = mx: lastMY = my
  216.                         GOSUB update
  217.                     END IF
  218.                 END IF
  219.             END IF
  220.         END IF
  221.         _LIMIT 200
  222.     LOOP UNTIL choice >= lba AND choice <= uba
  223.     getArrayItemNumber& = choice
  224.     COLOR fg, bg
  225.     'clear key presses
  226.     _KEYCLEAR
  227.     LOCATE curRow, curCol
  228.     'clear mouse clicks
  229.     mb = _MOUSEBUTTON(1)
  230.     IF mb THEN 'clear it
  231.         WHILE mb 'OK!
  232.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  233.             _LIMIT 100
  234.         WEND
  235.     END IF
  236.     EXIT SUB
  237.  
  238.     'display of array sections and controls on screen
  239.     update:
  240.  
  241.     'fix hlite if it has dropped below last array item
  242.     WHILE hlite + page * maxHeight + lba > uba
  243.         hlite = hlite - 1
  244.     WEND
  245.  
  246.     'main display of array items at page * maxHeight (lines high)
  247.     FOR row = 0 TO maxHeight - 1
  248.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  249.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  250.         index = row + page * maxHeight + lba
  251.         IF index >= lba AND index <= uba THEN
  252.             LOCATE locateRow + row, locateColumn
  253.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  254.         END IF
  255.     NEXT
  256.  
  257.     'make page up and down bars to click, print PgUp / PgDn if available
  258.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  259.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  260.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  261.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  262.     IF page <> INT(uba / maxHeight) THEN
  263.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  264.     END IF
  265.     'make exit sign for mouse click
  266.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  267.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  268.     PRINT " X "
  269.  
  270.     'if a number selection has been started show it's build = b$
  271.     IF LEN(b$) THEN
  272.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  273.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  274.         PRINT b$;
  275.     END IF
  276.     _DISPLAY
  277.     _LIMIT 100
  278.     RETURN
  279.  

The code is still quite messy and I hope to add a select files box.
Title: Re: Tiny Navigator
Post by: SMcNeill on August 23, 2019, 01:55:50 pm
Try this little two-line demo out:
Code: QB64: [Select]

It should be safe to get the users temp directory, without having to make one of your own.
Title: Re: Tiny Navigator
Post by: bplus on August 23, 2019, 02:36:35 pm
Thanks Steve, looks to be working well.
Title: Re: Tiny Navigator
Post by: SierraKen on August 23, 2019, 07:33:07 pm
This is awesome B+! Thank you! But I did run into 1 big problem, it starts playing the music of that folder but it won't go to the music info screen, until you press Esc for some reason. Esc ends the program but it also shows that music info screen. There's also a Warning saying 1 variable is unused on line 186, which is in your code. Here is the music player so far, maybe you or someone can help me fix this. I added another SCREEN command right before the songs play and music info comes up, but that doesn't seem to help. It must have to do with a conflict between your SCREEN and my SCREEN. Another problem is that there's a Subscript Out of Range in line 176, sometimes. I think when I got too deep in the folders, about 3 in. But this is nice so far. The area where it plays the folder is line 95 at playdir: The area where it changes directory, I just GOSUB to it from line 45. Your code is the last part of this program, which starts at line 146. I commented out your OPTION _EXPLICIT so I wouldn't have to dig through the entire program to make DIM commands for every variable. I'm not sure what that command does myself.
The Subscript Out Of Range on line 176 happens when I click X to shut your window off to go back to my main menu. Maybe we need to DIM myFiles ?

Code: QB64: [Select]
  1. 'This program was made on August 21, 2019 by Ken G. with some help by Petr from the QB64.org forum.
  2. 'This program will make a temporary file called MyMusicFiles-Temp000.temp
  3. 'which is just a text file and can be opened by Notepad. It shows a list of
  4. 'the mp3 songs in that directory. The file is deleted once the music starts.
  5.  
  6. DECLARE LIBRARY 'Directory Information using KERNEL32 provided by Dav
  7.     FUNCTION CURDirectory ALIAS GetCurrentDirectoryA (BYVAL nBufferLen AS LONG, lpBuffer AS STRING)
  8.  
  9.  
  10. _TITLE "Mini MP3 Player"
  11. SCREEN _NEWIMAGE(400, 400, 32)
  12. begin:
  13. DIM f$(100000)
  14. record = 0
  15. rec = 0
  16. oldp = 0
  17. p = 0
  18. PRINT "                Mini MP3 Player"
  19. PRINT "                  By Ken G."
  20. '=== SHOW CURRENT DIRECTORY
  21. CurDir$ = SPACE$(255)
  22. Result = CURDirectory(LEN(CurDir$), CurDir$)
  23. IF Result THEN LOCATE 11, 1: PRINT "Directory: "; LEFT$(CurDir$, Result)
  24. PRINT "            (1) Change Directory"
  25. PRINT "            (2) Play Song"
  26. PRINT "            (3) Play Directory"
  27. PRINT "            (4) Quit"
  28. INPUT "      ->", a
  29. IF a = 1 THEN GOTO directory:
  30. IF a = 2 THEN GOTO song:
  31. IF a = 3 THEN GOTO playdir:
  32. IF a = 4 THEN END
  33. IF a > 4 OR a < 1 OR a <> INT(a) THEN GOTO begin:
  34. directory:
  35.  
  36. 'Here is B+'s File Navigator
  37.  
  38. GOSUB changedirectory:
  39.  
  40. 'again:
  41. 'PRINT: PRINT: PRINT
  42. 'INPUT "Directory: ", d$
  43. 'IF d$ = "" THEN GOTO begin:
  44. 'r% = _DIREXISTS(d$)
  45. 'IF r% <> -1 THEN
  46. 'PRINT "Directory doesn't exist."
  47. 'PRINT "Try again, or Enter for Menu."
  48. 'GOTO again:
  49. 'END IF
  50. 'CHDIR d$
  51. GOTO begin:
  52. song:
  53. FILES "*.mp3"
  54. again2:
  55. INPUT "Song: ", song$
  56. IF song$ = "" THEN GOTO begin:
  57. fe% = _FILEEXISTS(song$)
  58. IF fe% <> -1 THEN
  59.     PRINT "Filename doesn't exist."
  60.     PRINT "Try again, or Enter for Menu."
  61.     GOTO again2:
  62. s& = _SNDOPEN(song$)
  63. LOCATE 1, 1: PRINT song$
  64. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  65. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  66. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  67.  
  68.     a$ = INKEY$
  69.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  70.     IF a$ = " " THEN _SNDPAUSE s&
  71.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  72.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  73.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: GOTO begin:
  74.     oldp = p
  75.     p = _SNDGETPOS(s&)
  76.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  77.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO begin:
  78. GOTO begin:
  79. playdir:
  80. SCREEN _NEWIMAGE(400, 400, 32)
  81. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  82. SHELL _HIDE "dir *.mp3 /B > MyMusicFiles-Temp000.temp" 'create mp3 files list.
  83. OPEN "MyMusicFiles-Temp000.temp" FOR INPUT AS #1
  84.     CLOSE #1
  85.     SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  86.     CLS
  87.     PRINT "No mp3 songs on this folder."
  88.     PRINT
  89.     INPUT "Press Enter to go back to Menu.", menu$
  90.     GOTO begin:
  91.     LINE INPUT #1, file$
  92.     file(record) = file$
  93.     f$(record) = file$
  94.     PRINT f$(record)
  95.     record = record + 1 'for next loop we needed array higher up to one
  96.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  97. SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  98. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  99. ready:
  100. s& = _SNDOPEN(file(rec))
  101. LOCATE 1, 1: PRINT f$(rec)
  102. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  103. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  104. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  105.  
  106.     a$ = INKEY$
  107.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  108.     IF a$ = " " THEN _SNDPAUSE s&
  109.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  110.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  111.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: GOTO begin:
  112.     oldp = p
  113.     p = _SNDGETPOS(s&)
  114.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  115.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more:
  116. more:
  117. IF rec = record - 1 THEN GOTO begin:
  118. rec = rec + 1
  119. GOTO ready:
  120. 'OPTION _EXPLICIT
  121. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  122. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  123. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  124. ' For some reason Windows won't write to a fully pathed file in my user folder???
  125. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  126. ' and now I can chDir anywhere!
  127.  
  128. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  129.  
  130. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  131.  
  132. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  133.  
  134. changedirectory:
  135. SCREEN _NEWIMAGE(1200, 600, 32)
  136. _SCREENMOVE 100, 50
  137.  
  138.  
  139. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  140.  
  141. DIM mySelection&, done$
  142.  
  143.     PRINT "Current Directory: " + _CWD$
  144.     REDIM myFiles(0) AS STRING
  145.     loadFA "*.*", myFiles()
  146.     mySelection& = getArrayItemNumber&(5, 5, 90, 30, myFiles())
  147.     CLS
  148.     IF mySelection& <> -1719 THEN
  149.         CHDIR myFiles(mySelection&)
  150.     ELSE
  151.         PRINT "No Directory selected."
  152.         INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  153.     END IF
  154.     _LIMIT 60
  155. LOOP UNTIL done$ <> ""
  156.  
  157.  
  158. SUB loadFA (spec$, fa() AS STRING)
  159.     DIM tmpFile$, Index%, fline$, d$
  160.     tmpFile$ = "C:\temp\DIR$INF0.INF"
  161.     'PRINT tmpFile$
  162.     'END
  163.     SHELL _HIDE "DIR /a:d >" + tmpFile$ 'get directories  but have to do a little pruning
  164.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  165.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  166.     OPEN tmpFile$ FOR INPUT AS #1
  167.     Index% = -1
  168.     DO WHILE NOT EOF(1)
  169.         LINE INPUT #1, fline$
  170.         IF INSTR(fline$, "<DIR>") THEN
  171.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  172.             Index% = Index% + 1
  173.             REDIM _PRESERVE fa(Index%)
  174.             fa(Index%) = d$
  175.         END IF
  176.     LOOP
  177.     CLOSE #1
  178.     KILL tmpFile$
  179.  
  180. FUNCTION rightOf$ (source$, of$)
  181.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  182.  
  183. 'attempting use this 4 things (2018-12-30)
  184. ' 1. expects HELP sub that uses message and message box but easy to comment out
  185. ' 2. expects to be in graphics mode
  186. ' 3. chages color of screen
  187. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  188. '
  189. ' Future Help Message Box for the function.
  190. ' "*** Mouse and Key Instructions ***"
  191. '
  192. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  193. ' "Press spacebar to select a highlighted item or just click it."
  194. ' "Use number(s) + enter to select an array item by it's index number,"
  195. ' "backspace will remove last number pressed, c will clear a number started."
  196. ' "Numbers started are shown in bottom right PgDn bar."
  197. ' "Enter will also select the highlighted item, if no number has been started."
  198. ' "Home starts you at lowest array index, End highlights then highest index."
  199. ' "Use PgUp and PgDn keys to flip through pages of array items."
  200. '
  201. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  202. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  203.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  204.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  205.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  206.  
  207.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  208.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  209.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  210.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  211.     DIM clrStr AS STRING, b AS STRING
  212.  
  213.     'save old settings to restore at end ofsub
  214.     curRow = CSRLIN
  215.     curCol = POS(0)
  216.     fg = _DEFAULTCOLOR
  217.     bg = _BACKGROUNDCOLOR
  218.     _KEYCLEAR
  219.  
  220.     maxWidth = boxWidth '       number of characters in box
  221.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  222.     lba = LBOUND(arr)
  223.     uba = UBOUND(arr)
  224.     page = 0
  225.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  226.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  227.  
  228.     GOSUB update '              show the beginning of the array items for selection
  229.  
  230.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  231.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  232.  
  233.     DO 'until get a selection or demand exit
  234.  
  235.         'handle the key stuff
  236.         kh& = _KEYHIT
  237.         IF kh& THEN
  238.             IF kh& > 0 AND kh& < 255 THEN
  239.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  240.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  241.  
  242.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  243.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  244.                     IF LEN(b$) THEN
  245.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  246.                             choice = VAL(b$): EXIT DO
  247.                         ELSE 'clear b$ to show some response to enter
  248.                             b$ = "": GOSUB update 'clear the value that doesn't work
  249.                         END IF
  250.                     ELSE
  251.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  252.                     END IF
  253.                 END IF
  254.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  255.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  256.                 IF kh& = 8 THEN 'backspace to edit number
  257.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  258.                 END IF
  259.             ELSE
  260.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  261.                     CASE 20736 'pg dn
  262.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  263.                     CASE 18688 'pg up
  264.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  265.                     CASE 18432 'up
  266.                         IF hlite - 1 < 0 THEN
  267.                             IF page > 0 THEN
  268.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  269.                             END IF
  270.                         ELSE
  271.                             hlite = hlite - 1: GOSUB update
  272.                         END IF
  273.                     CASE 20480 'down
  274.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  275.                             IF hlite + 1 > maxHeight - 1 THEN
  276.                                 page = page + 1: hlite = 0: GOSUB update
  277.                             ELSE
  278.                                 hlite = hlite + 1: GOSUB update
  279.                             END IF
  280.                         END IF
  281.                     CASE 18176 'home
  282.                         page = 0: hlite = 0: GOSUB update
  283.                     CASE 20224 ' end
  284.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  285.                 END SELECT
  286.             END IF
  287.         END IF
  288.  
  289.         'handle the mouse stuff
  290.         WHILE _MOUSEINPUT
  291.             IF _MOUSEWHEEL = -1 THEN 'up?
  292.                 IF hlite - 1 < 0 THEN
  293.                     IF page > 0 THEN
  294.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  295.                     END IF
  296.                 ELSE
  297.                     hlite = hlite - 1: GOSUB update
  298.                 END IF
  299.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  300.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  301.                     IF hlite + 1 > maxHeight - 1 THEN
  302.                         page = page + 1: hlite = 0: GOSUB update
  303.                     ELSE
  304.                         hlite = hlite + 1: GOSUB update
  305.                     END IF
  306.                 END IF
  307.             END IF
  308.         WEND
  309.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  310.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  311.             'clear mouse clicks
  312.             mb = _MOUSEBUTTON(1)
  313.             IF mb THEN 'clear it
  314.                 WHILE mb 'OK!
  315.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  316.                     _LIMIT 100
  317.                 WEND
  318.             END IF
  319.  
  320.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  321.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  322.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  323.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  324.                     EXIT DO 'escape plan for mouse click top right corner of display box
  325.                 ELSE 'PgUp bar clicked
  326.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  327.                 END IF
  328.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  329.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  330.             END IF
  331.         ELSE '   mouse over highlighting, only if mouse has moved!
  332.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  333.                 IF mx <> lastMX OR my <> lastMY THEN
  334.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  335.                         hlite = my - 1
  336.                         lastMX = mx: lastMY = my
  337.                         GOSUB update
  338.                     END IF
  339.                 END IF
  340.             END IF
  341.         END IF
  342.         _LIMIT 200
  343.     LOOP UNTIL choice >= lba AND choice <= uba
  344.     getArrayItemNumber& = choice
  345.     COLOR fg, bg
  346.     'clear key presses
  347.     _KEYCLEAR
  348.     LOCATE curRow, curCol
  349.     'clear mouse clicks
  350.     mb = _MOUSEBUTTON(1)
  351.     IF mb THEN 'clear it
  352.         WHILE mb 'OK!
  353.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  354.             _LIMIT 100
  355.         WEND
  356.     END IF
  357.     EXIT SUB
  358.  
  359.     'display of array sections and controls on screen
  360.     update:
  361.  
  362.     'fix hlite if it has dropped below last array item
  363.     WHILE hlite + page * maxHeight + lba > uba
  364.         hlite = hlite - 1
  365.     WEND
  366.  
  367.     'main display of array items at page * maxHeight (lines high)
  368.     FOR row = 0 TO maxHeight - 1
  369.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  370.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  371.         index = row + page * maxHeight + lba
  372.         IF index >= lba AND index <= uba THEN
  373.             LOCATE locateRow + row, locateColumn
  374.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  375.         END IF
  376.     NEXT
  377.  
  378.     'make page up and down bars to click, print PgUp / PgDn if available
  379.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  380.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  381.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  382.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  383.     IF page <> INT(uba / maxHeight) THEN
  384.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  385.     END IF
  386.     'make exit sign for mouse click
  387.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  388.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  389.     PRINT " X "
  390.  
  391.     'if a number selection has been started show it's build = b$
  392.     IF LEN(b$) THEN
  393.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  394.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  395.         PRINT b$;
  396.     END IF
  397.     _DISPLAY
  398.     _LIMIT 100
  399.     RETURN
  400.  
  401.  
Title: Re: Tiny Navigator
Post by: bplus on August 23, 2019, 09:39:14 pm
RE: Navigator in Ken's application

I changed the navigator part to fit your screen, when you click X or escape you are done with navigator so I send you to return to where ever it was called. I used _KEYCLEAR in case that was interfering with other code.

You loose me with all your goto's so that's on to you to get straight.

Here navigator part reworked to fit your screen:
Code: QB64: [Select]
  1. changedirectory:
  2. 'SCREEN _NEWIMAGE(1200, 600, 32)
  3. '_SCREENMOVE 100, 50
  4.  
  5.  
  6. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  7.  
  8. DIM mySelection&, done$
  9.  
  10.     PRINT "Current Directory: " + _CWD$
  11.     REDIM myFiles(0) AS STRING
  12.     loadFA "*.*", myFiles()
  13.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  14.     CLS
  15.     IF mySelection& <> -1719 THEN
  16.         CHDIR myFiles(mySelection&)
  17.     ELSE
  18.         _KEYCLEAR
  19.         EXIT DO
  20.         'PRINT "No Directory selected."
  21.         'INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  22.     END IF
  23.     _LIMIT 60
  24. LOOP 'UNTIL done$ <> ""
  25.  
  26.  
  27.  

The warning just says we didn't use the variable passed to the sub, it's old leftovers code that hasn't been cleaned out yet, not to worry.

QB64 has _CWD$ that will give you the current directory without the library code at the start of your program.

CurrentWorkingDirectory$ = _CWD$

OPTION _EXPLICIT makes you dimension all your variables, it catches typo's, not needed when code is working OK.
Title: Re: Tiny Navigator
Post by: SierraKen on August 23, 2019, 10:58:26 pm
Thanks B+, we are getting closer! But half of it still freezes up after I choose "(3) Play Directory". It still plays the music of the directory, but the screen doesn't CLS to the next page, it just sits there as it plays the music. And it doesn't do this when I don't change the directory first with your directory code. Something really bizarre is going on. Another strange thing is, just to test it, I added an INPUT a$ after it was supposed to do CLS just to see if it got to that point, and it does! So the only logical reasoning would be that the program flies through the rest of the code and goes straight back to the front menu. The only problem is, I also removed all the GOTO's that make it go back to it, and it still does the same thing. LOL But I know it plays the music, which makes some of that area work, just not the CLS or the PRINT or LOCATE statements. I know this sounds almost like a newbie, but I've looked into this a lot and cannot find anything. But I know it has something to do with your code because like I said, if I don't change a directory, it displays everything normally. Here is the code again if you want to take a crack at it. No pressure though, this is just something I do in my spare time so if you want to move on, I understand. I'll just remove your code if you want me to and go with the original. I really wish this would work though. :) Hmm, maybe a SUB is still running in the background on a LOOP even after your menu is X'ed out?

Here is what I have:

Code: QB64: [Select]
  1. 'This program was made on August 21, 2019 by Ken G. with some help by Petr from the QB64.org forum.
  2. 'This program will make a temporary file called MyMusicFiles-Temp000.temp
  3. 'which is just a text file and can be opened by Notepad. It shows a list of
  4. 'the mp3 songs in that directory. The file is deleted once the music starts.
  5.  
  6. DECLARE LIBRARY 'Directory Information using KERNEL32 provided by Dav
  7.     FUNCTION CURDirectory ALIAS GetCurrentDirectoryA (BYVAL nBufferLen AS LONG, lpBuffer AS STRING)
  8.  
  9.  
  10. _TITLE "Mini MP3 Player"
  11. SCREEN _NEWIMAGE(400, 400, 32)
  12. begin:
  13. DIM f$(100000)
  14. record = 0
  15. rec = 0
  16. oldp = 0
  17. p = 0
  18. PRINT "                Mini MP3 Player"
  19. PRINT "                  By Ken G."
  20. '=== SHOW CURRENT DIRECTORY
  21. LOCATE 11, 1: PRINT "Directory: "; _CWD$
  22. PRINT "            (1) Change Directory"
  23. PRINT "            (2) Play Song"
  24. PRINT "            (3) Play Directory"
  25. PRINT "            (4) Quit"
  26. INPUT "      ->", a
  27. IF a = 1 THEN GOTO directory:
  28. IF a = 2 THEN GOTO song:
  29. IF a = 3 THEN GOTO playdir:
  30. IF a = 4 THEN END
  31. IF a > 4 OR a < 1 OR a <> INT(a) THEN GOTO begin:
  32. directory:
  33.  
  34. 'Here is B+'s File Navigator
  35.  
  36. GOSUB changedirectory:
  37.  
  38. 'again:
  39. 'PRINT: PRINT: PRINT
  40. 'INPUT "Directory: ", d$
  41. 'IF d$ = "" THEN GOTO begin:
  42. 'r% = _DIREXISTS(d$)
  43. 'IF r% <> -1 THEN
  44. 'PRINT "Directory doesn't exist."
  45. 'PRINT "Try again, or Enter for Menu."
  46. 'GOTO again:
  47. 'END IF
  48. 'CHDIR d$
  49.  
  50. GOTO begin:
  51. song:
  52. FILES "*.mp3"
  53. again2:
  54. INPUT "Song: ", song$
  55. IF song$ = "" THEN GOTO begin:
  56. fe% = _FILEEXISTS(song$)
  57. IF fe% <> -1 THEN
  58.     PRINT "Filename doesn't exist."
  59.     PRINT "Try again, or Enter for Menu."
  60.     GOTO again2:
  61. s& = _SNDOPEN(song$)
  62. LOCATE 1, 1: PRINT song$
  63. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  64. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  65. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  66.  
  67.     a$ = INKEY$
  68.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  69.     IF a$ = " " THEN _SNDPAUSE s&
  70.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  71.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  72.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: GOTO begin:
  73.     oldp = p
  74.     p = _SNDGETPOS(s&)
  75.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  76.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO begin:
  77. GOTO begin:
  78.  
  79. playdir:
  80. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  81. SHELL _HIDE "dir *.mp3 /B > MyMusicFiles-Temp000.temp" 'create mp3 files list.
  82. OPEN "MyMusicFiles-Temp000.temp" FOR INPUT AS #1
  83.     CLOSE #1
  84.     SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  85.     CLS
  86.     PRINT "No mp3 songs on this folder."
  87.     PRINT
  88.     INPUT "Press Enter to go back to Menu.", menu$
  89.     GOTO begin:
  90.     LINE INPUT #1, file$
  91.     file(record) = file$
  92.     f$(record) = file$
  93.     PRINT f$(record)
  94.     record = record + 1 'for next loop we needed array higher up to one
  95.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  96. SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  97. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  98. ready:
  99. a$ = ""
  100. p = 0
  101. oldp = 0
  102. s& = _SNDOPEN(file(rec))
  103. LOCATE 1, 1: PRINT f$(rec)
  104. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  105. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  106. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  107.     a$ = INKEY$
  108.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  109.     IF a$ = " " THEN _SNDPAUSE s&
  110.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  111.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  112.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: GOTO begin:
  113.     oldp = p
  114.     p = _SNDGETPOS(s&)
  115.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  116.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more:
  117. more:
  118. IF rec = record - 1 THEN GOTO begin:
  119. rec = rec + 1
  120. GOTO ready:
  121. 'OPTION _EXPLICIT
  122. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  123. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  124. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  125. ' For some reason Windows won't write to a fully pathed file in my user folder???
  126. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  127. ' and now I can chDir anywhere!
  128.  
  129. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  130.  
  131. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  132.  
  133. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  134.  
  135. changedirectory:
  136. 'SCREEN _NEWIMAGE(1200, 600, 32)
  137. '_SCREENMOVE 100, 50
  138.  
  139.  
  140. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  141.  
  142. DIM mySelection&, done$
  143.  
  144.     PRINT "Current Directory: " + _CWD$
  145.     REDIM myFiles(0) AS STRING
  146.     loadFA "*.*", myFiles()
  147.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  148.     CLS
  149.     IF mySelection& <> -1719 THEN
  150.         CHDIR myFiles(mySelection&)
  151.     ELSE
  152.         _KEYCLEAR
  153.         EXIT DO
  154.     END IF
  155.     _LIMIT 60
  156. LOOP 'UNTIL done$ <> ""
  157.  
  158.  
  159. SUB loadFA (spec$, fa() AS STRING)
  160.     DIM tmpFile$, Index%, fline$, d$
  161.     tmpFile$ = "C:\temp\DIR$INF0.INF"
  162.     'PRINT tmpFile$
  163.     'END
  164.     SHELL _HIDE "DIR /a:d >" + tmpFile$ 'get directories  but have to do a little pruning
  165.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  166.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  167.     OPEN tmpFile$ FOR INPUT AS #1
  168.     Index% = -1
  169.     DO WHILE NOT EOF(1)
  170.         LINE INPUT #1, fline$
  171.         IF INSTR(fline$, "<DIR>") THEN
  172.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  173.             Index% = Index% + 1
  174.             REDIM _PRESERVE fa(Index%)
  175.             fa(Index%) = d$
  176.         END IF
  177.     LOOP
  178.     CLOSE #1
  179.     KILL tmpFile$
  180.  
  181. FUNCTION rightOf$ (source$, of$)
  182.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  183.  
  184. 'attempting use this 4 things (2018-12-30)
  185. ' 1. expects HELP sub that uses message and message box but easy to comment out
  186. ' 2. expects to be in graphics mode
  187. ' 3. chages color of screen
  188. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  189. '
  190. ' Future Help Message Box for the function.
  191. ' "*** Mouse and Key Instructions ***"
  192. '
  193. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  194. ' "Press spacebar to select a highlighted item or just click it."
  195. ' "Use number(s) + enter to select an array item by it's index number,"
  196. ' "backspace will remove last number pressed, c will clear a number started."
  197. ' "Numbers started are shown in bottom right PgDn bar."
  198. ' "Enter will also select the highlighted item, if no number has been started."
  199. ' "Home starts you at lowest array index, End highlights then highest index."
  200. ' "Use PgUp and PgDn keys to flip through pages of array items."
  201. '
  202. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  203. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  204.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  205.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  206.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  207.  
  208.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  209.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  210.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  211.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  212.     DIM clrStr AS STRING, b AS STRING
  213.  
  214.     'save old settings to restore at end ofsub
  215.     curRow = CSRLIN
  216.     curCol = POS(0)
  217.     fg = _DEFAULTCOLOR
  218.     bg = _BACKGROUNDCOLOR
  219.     _KEYCLEAR
  220.  
  221.     maxWidth = boxWidth '       number of characters in box
  222.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  223.     lba = LBOUND(arr)
  224.     uba = UBOUND(arr)
  225.     page = 0
  226.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  227.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  228.  
  229.     GOSUB update '              show the beginning of the array items for selection
  230.  
  231.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  232.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  233.  
  234.     DO 'until get a selection or demand exit
  235.  
  236.         'handle the key stuff
  237.         kh& = _KEYHIT
  238.         IF kh& THEN
  239.             IF kh& > 0 AND kh& < 255 THEN
  240.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  241.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  242.  
  243.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  244.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  245.                     IF LEN(b$) THEN
  246.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  247.                             choice = VAL(b$): EXIT DO
  248.                         ELSE 'clear b$ to show some response to enter
  249.                             b$ = "": GOSUB update 'clear the value that doesn't work
  250.                         END IF
  251.                     ELSE
  252.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  253.                     END IF
  254.                 END IF
  255.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  256.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  257.                 IF kh& = 8 THEN 'backspace to edit number
  258.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  259.                 END IF
  260.             ELSE
  261.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  262.                     CASE 20736 'pg dn
  263.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  264.                     CASE 18688 'pg up
  265.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  266.                     CASE 18432 'up
  267.                         IF hlite - 1 < 0 THEN
  268.                             IF page > 0 THEN
  269.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  270.                             END IF
  271.                         ELSE
  272.                             hlite = hlite - 1: GOSUB update
  273.                         END IF
  274.                     CASE 20480 'down
  275.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  276.                             IF hlite + 1 > maxHeight - 1 THEN
  277.                                 page = page + 1: hlite = 0: GOSUB update
  278.                             ELSE
  279.                                 hlite = hlite + 1: GOSUB update
  280.                             END IF
  281.                         END IF
  282.                     CASE 18176 'home
  283.                         page = 0: hlite = 0: GOSUB update
  284.                     CASE 20224 ' end
  285.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  286.                 END SELECT
  287.             END IF
  288.         END IF
  289.  
  290.         'handle the mouse stuff
  291.         WHILE _MOUSEINPUT
  292.             IF _MOUSEWHEEL = -1 THEN 'up?
  293.                 IF hlite - 1 < 0 THEN
  294.                     IF page > 0 THEN
  295.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  296.                     END IF
  297.                 ELSE
  298.                     hlite = hlite - 1: GOSUB update
  299.                 END IF
  300.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  301.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  302.                     IF hlite + 1 > maxHeight - 1 THEN
  303.                         page = page + 1: hlite = 0: GOSUB update
  304.                     ELSE
  305.                         hlite = hlite + 1: GOSUB update
  306.                     END IF
  307.                 END IF
  308.             END IF
  309.         WEND
  310.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  311.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  312.             'clear mouse clicks
  313.             mb = _MOUSEBUTTON(1)
  314.             IF mb THEN 'clear it
  315.                 WHILE mb 'OK!
  316.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  317.                     _LIMIT 100
  318.                 WEND
  319.             END IF
  320.  
  321.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  322.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  323.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  324.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  325.                     EXIT DO 'escape plan for mouse click top right corner of display box
  326.                 ELSE 'PgUp bar clicked
  327.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  328.                 END IF
  329.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  330.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  331.             END IF
  332.         ELSE '   mouse over highlighting, only if mouse has moved!
  333.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  334.                 IF mx <> lastMX OR my <> lastMY THEN
  335.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  336.                         hlite = my - 1
  337.                         lastMX = mx: lastMY = my
  338.                         GOSUB update
  339.                     END IF
  340.                 END IF
  341.             END IF
  342.         END IF
  343.         _LIMIT 200
  344.     LOOP UNTIL choice >= lba AND choice <= uba
  345.     getArrayItemNumber& = choice
  346.     COLOR fg, bg
  347.     'clear key presses
  348.     _KEYCLEAR
  349.     LOCATE curRow, curCol
  350.     'clear mouse clicks
  351.     mb = _MOUSEBUTTON(1)
  352.     IF mb THEN 'clear it
  353.         WHILE mb 'OK!
  354.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  355.             _LIMIT 100
  356.         WEND
  357.     END IF
  358.     EXIT SUB
  359.  
  360.     'display of array sections and controls on screen
  361.     update:
  362.  
  363.     'fix hlite if it has dropped below last array item
  364.     WHILE hlite + page * maxHeight + lba > uba
  365.         hlite = hlite - 1
  366.     WEND
  367.  
  368.     'main display of array items at page * maxHeight (lines high)
  369.     FOR row = 0 TO maxHeight - 1
  370.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  371.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  372.         index = row + page * maxHeight + lba
  373.         IF index >= lba AND index <= uba THEN
  374.             LOCATE locateRow + row, locateColumn
  375.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  376.         END IF
  377.     NEXT
  378.  
  379.     'make page up and down bars to click, print PgUp / PgDn if available
  380.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  381.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  382.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  383.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  384.     IF page <> INT(uba / maxHeight) THEN
  385.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  386.     END IF
  387.     'make exit sign for mouse click
  388.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  389.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  390.     PRINT " X "
  391.  
  392.     'if a number selection has been started show it's build = b$
  393.     IF LEN(b$) THEN
  394.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  395.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  396.         PRINT b$;
  397.     END IF
  398.     _DISPLAY
  399.     _LIMIT 100
  400.     RETURN
  401.  
  402.  
Title: Re: Tiny Navigator
Post by: bplus on August 23, 2019, 11:33:09 pm
Hi Ken,

For simplicity sake, why not make each menu item that does something a gosub you select a menu item do the sub and you cycle back to the menu which should be in a loop:

Do
    cls
    print menu
    get a choice
    gosub the choice '<<< it returns here to loop back around to show menu again
loop

if the choice is not on menu, it would cycle back automatic.

Now all you have to do is make sure all your GOSUBs are tight and not leaking goto's to goodness knows where...

I will look at code again tomorrow when fresh but right now I suspect one of your goto's is leaking, I am pretty sure the navigator sub does not leak, but I've certainly been wrong before! I have to say, I don't like that library sub routine when you already have _CWD$.

PS when I say leak I mean the execution falls through down to the last code in program, namely my Navigator. Oh say, try putting an END statement before the Gosub label of Navigator, that will catch anything falling through and end program. Oh and put an end before the silly goto that tells execution to gosub the navigator too.

Update: Yes put an end between 39 and 40, because the execution could fall through there but it does look like all bases covered??
Title: Re: Tiny Navigator
Post by: bplus on August 23, 2019, 11:46:12 pm
I have Tiny Navigator working with 2nd Files window for selecting files, just press f when you are in the desired directory, f will also get you the full files report for the directory you can scroll through and browse.

Code: QB64: [Select]
  1. _TITLE "Tiny Navigator: press f to window and select a file" 'B+ started 2019-08-22
  2. SCREEN _NEWIMAGE(1000, 600, 32)
  3. _SCREENMOVE 100, 50
  4. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  5. ' 2019-08-23_13-25 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  6. ' For some reason Windows won't write to a fully pathed file in my user folder???from a SHELL command
  7. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  8. ' and now I can chDir anywhere!!!!
  9. ' 2019-08-23_14-25 Take Steve's Advice to use users tmp directory for temp files
  10. ' 2019-08-23_23+ Have files window working for file selection
  11.  
  12. DIM SHARED selectedFile AS STRING
  13. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  14. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  15.     tmpDir = ENVIRON$("TEMP")
  16. ELSEIF ENVIRON$("TMP") <> "" THEN
  17.     tmpDir = ENVIRON$("TMP")
  18. ELSE 'Thanks to Steve McNeill this should be very unlikely
  19.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  20.     tmpDir = "C:\temp"
  21.  
  22. DIM mySelection&, done$, i, t$
  23.     COLOR _RGB32(180, 180, 255)
  24.     CLS
  25.     t$ = "Current Directory: " + _CWD$
  26.     LOCATE 2, (_WIDTH / 8 - LEN(t$)) / 2: PRINT t$
  27.     REDIM DIRs(0) AS STRING
  28.     loadDIR DIRs()
  29.     REDIM FILs(0) AS STRING
  30.     loadFiles FILs()
  31.     FOR i = 0 TO UBOUND(FILs)
  32.         IF i < 30 THEN LOCATE i + 4, 60: PRINT FILs(i) ELSE EXIT FOR
  33.     NEXT
  34.     mySelection& = getArrayItemNumber&(5, 5, 50, 30, DIRs())
  35.     CLS
  36.     IF selectedFile <> "" THEN
  37.         PRINT "You selected a file: "; selectedFile
  38.         INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  39.         selectedFile = ""
  40.     ELSEIF mySelection& <> -1719 THEN
  41.         CHDIR DIRs(mySelection&)
  42.     ELSE
  43.         PRINT "Nothing selected."
  44.         INPUT "Press enter to continue navigator, any + enter to quit... "; done$
  45.     END IF
  46.     _LIMIT 60
  47. LOOP UNTIL done$ <> ""
  48.  
  49. SUB loadDIR (fa() AS STRING)
  50.     DIM tmpFile AS STRING, Index%, fline$, d$
  51.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  52.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  53.     OPEN tmpFile FOR INPUT AS #1
  54.     Index% = -1
  55.     DO WHILE NOT EOF(1)
  56.         LINE INPUT #1, fline$
  57.         IF INSTR(fline$, "<DIR>") THEN
  58.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  59.             Index% = Index% + 1
  60.             REDIM _PRESERVE fa(Index%)
  61.             fa(Index%) = d$
  62.         END IF
  63.     LOOP
  64.     CLOSE #1
  65.     KILL tmpFile
  66.  
  67. SUB loadFiles (fa() AS STRING)
  68.     DIM tmpFile AS STRING, Index%
  69.     tmpFile = tmpDir + "\FILE$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  70.     SHELL _HIDE "DIR *.* /a:-d /b /o:-gen > " + tmpFile
  71.     OPEN tmpFile$ FOR INPUT AS #1
  72.     Index% = -1
  73.     DO WHILE NOT EOF(1)
  74.         Index% = Index% + 1
  75.         REDIM _PRESERVE fa(Index%) AS STRING
  76.         LINE INPUT #1, fa(Index%)
  77.     LOOP
  78.     CLOSE #1
  79.     KILL tmpFile$
  80.  
  81. FUNCTION rightOf$ (source$, of$)
  82.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  83.  
  84. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  85. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  86.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  87.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  88.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  89.  
  90.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  91.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  92.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  93.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  94.     DIM clrStr AS STRING, b AS STRING, selNum&
  95.  
  96.     'save old settings to restore at end ofsub
  97.     curRow = CSRLIN
  98.     curCol = POS(0)
  99.     fg = _DEFAULTCOLOR
  100.     bg = _BACKGROUNDCOLOR
  101.     _KEYCLEAR
  102.  
  103.     maxWidth = boxWidth '       number of characters in box
  104.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  105.     lba = LBOUND(arr)
  106.     uba = UBOUND(arr)
  107.     page = 0
  108.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  109.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  110.  
  111.     GOSUB update '              show the beginning of the array items for selection
  112.  
  113.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  114.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  115.  
  116.     DO 'until get a selection or demand exit
  117.  
  118.         'handle the key stuff
  119.         kh& = _KEYHIT
  120.         IF kh& THEN
  121.             IF kh& > 0 AND kh& < 255 THEN
  122.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  123.                 IF CHR$(kh&) = "f" THEN
  124.                     REDIM FILs(0) AS STRING
  125.                     loadFiles FILs()
  126.                     selNum& = getArrayItemNumber&(5, 60, 60, 30, FILs())
  127.                     COLOR _RGB32(180, 180, 255)
  128.                     CLS 'need to signal out of file selection
  129.                     IF selNum& >= LBOUND(FILs) AND selNum& <= UBOUND(FILs) THEN selectedFile = FILs(selNum&)
  130.                     EXIT DO
  131.                     'back to directory select
  132.                 END IF
  133.  
  134.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  135.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  136.                     IF LEN(b$) THEN
  137.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  138.                             choice = VAL(b$): EXIT DO
  139.                         ELSE 'clear b$ to show some response to enter
  140.                             b$ = "": GOSUB update 'clear the value that doesn't work
  141.                         END IF
  142.                     ELSE
  143.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  144.                     END IF
  145.                 END IF
  146.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  147.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  148.                 IF kh& = 8 THEN 'backspace to edit number
  149.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  150.                 END IF
  151.             ELSE
  152.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  153.                     CASE 20736 'pg dn
  154.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  155.                     CASE 18688 'pg up
  156.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  157.                     CASE 18432 'up
  158.                         IF hlite - 1 < 0 THEN
  159.                             IF page > 0 THEN
  160.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  161.                             END IF
  162.                         ELSE
  163.                             hlite = hlite - 1: GOSUB update
  164.                         END IF
  165.                     CASE 20480 'down
  166.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  167.                             IF hlite + 1 > maxHeight - 1 THEN
  168.                                 page = page + 1: hlite = 0: GOSUB update
  169.                             ELSE
  170.                                 hlite = hlite + 1: GOSUB update
  171.                             END IF
  172.                         END IF
  173.                     CASE 18176 'home
  174.                         page = 0: hlite = 0: GOSUB update
  175.                     CASE 20224 ' end
  176.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  177.                 END SELECT
  178.             END IF
  179.         END IF
  180.  
  181.         'handle the mouse stuff
  182.         WHILE _MOUSEINPUT
  183.             IF _MOUSEWHEEL = -1 THEN 'up?
  184.                 IF hlite - 1 < 0 THEN
  185.                     IF page > 0 THEN
  186.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  187.                     END IF
  188.                 ELSE
  189.                     hlite = hlite - 1: GOSUB update
  190.                 END IF
  191.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  192.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  193.                     IF hlite + 1 > maxHeight - 1 THEN
  194.                         page = page + 1: hlite = 0: GOSUB update
  195.                     ELSE
  196.                         hlite = hlite + 1: GOSUB update
  197.                     END IF
  198.                 END IF
  199.             END IF
  200.         WEND
  201.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  202.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  203.             'clear mouse clicks
  204.             mb = _MOUSEBUTTON(1)
  205.             IF mb THEN 'clear it
  206.                 WHILE mb 'OK!
  207.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  208.                     _LIMIT 100
  209.                 WEND
  210.             END IF
  211.  
  212.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  213.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  214.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  215.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  216.                     EXIT DO 'escape plan for mouse click top right corner of display box
  217.                 ELSE 'PgUp bar clicked
  218.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  219.                 END IF
  220.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  221.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  222.             END IF
  223.         ELSE '   mouse over highlighting, only if mouse has moved!
  224.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  225.                 IF mx <> lastMX OR my <> lastMY THEN
  226.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  227.                         hlite = my - 1
  228.                         lastMX = mx: lastMY = my
  229.                         GOSUB update
  230.                     END IF
  231.                 END IF
  232.             END IF
  233.         END IF
  234.         _LIMIT 200
  235.     LOOP UNTIL choice >= lba AND choice <= uba
  236.     getArrayItemNumber& = choice
  237.     COLOR fg, bg
  238.     'clear key presses
  239.     _KEYCLEAR
  240.     LOCATE curRow, curCol
  241.     'clear mouse clicks
  242.     mb = _MOUSEBUTTON(1)
  243.     IF mb THEN 'clear it
  244.         WHILE mb 'OK!
  245.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  246.             _LIMIT 100
  247.         WEND
  248.     END IF
  249.     EXIT SUB
  250.  
  251.  
  252.     update: '--------------- display of array sections and controls on screen
  253.  
  254.     'fix hlite if it has dropped below last array item
  255.     WHILE hlite + page * maxHeight + lba > uba
  256.         hlite = hlite - 1
  257.     WEND
  258.  
  259.     'main display of array items at page * maxHeight (lines high)
  260.     FOR row = 0 TO maxHeight - 1
  261.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  262.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  263.         index = row + page * maxHeight + lba
  264.         IF index >= lba AND index <= uba THEN
  265.             LOCATE locateRow + row, locateColumn
  266.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  267.         END IF
  268.     NEXT
  269.  
  270.     'make page up and down bars to click, print PgUp / PgDn if available
  271.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  272.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  273.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  274.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  275.     IF page <> INT(uba / maxHeight) THEN
  276.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  277.     END IF
  278.     'make exit sign for mouse click
  279.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  280.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  281.     PRINT " X "
  282.  
  283.     'if a number selection has been started show it's build = b$
  284.     IF LEN(b$) THEN
  285.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  286.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  287.         PRINT b$;
  288.     END IF
  289.     _DISPLAY
  290.     _LIMIT 100
  291.     RETURN
  292.  
  293.  
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 12:05:49 am
That's cool about the Files one! I'll look into that one after I get the directory one fixed. I changed the code like I said, to use DO/LOOP for the main menu and GOSUB/RETURN for each selection. Still doesn't work. I tried END at the end of the code you gave me (before the RETURN back to the main menu) and it just ends the program after I select a directory. I already know the program can get to the area of the program I want it to be at, and it still plays the music there. But for some reason it doesn't CLS and go to another screen to PRINT things I want people to see about the songs it plays. It just sits there at the main menu playing the songs. lol And like I said, without changing the directory with the change directory code, and just playing the default directory, everything shows up fine as the sounds play. So there must be something in a SUB somewhere freezing up the flow of the program. That's all I can imagine, but you know more than I do. Oh, thanks for telling me about that library, I deleted it. This version should be easier for you to follow:

(Note, a little bit of a better one is after this one.)

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+ and Petr from the QB64.org forum.
  2. 'This program will make a temporary file called MyMusicFiles-Temp000.temp
  3. 'which is just a text file and can be opened by Notepad. It shows a list of
  4. 'the mp3 songs in that directory. The file is deleted once the music starts.
  5.  
  6. _TITLE "Mini MP3 Player"
  7. SCREEN _NEWIMAGE(400, 400, 32)
  8. begin:
  9.     DIM f$(100000)
  10.     record = 0
  11.     rec = 0
  12.     oldp = 0
  13.     p = 0
  14.     CLS
  15.     PRINT: PRINT: PRINT
  16.     PRINT "                Mini MP3 Player"
  17.     PRINT: PRINT: PRINT
  18.     PRINT "                  By Ken G."
  19.     PRINT
  20.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  21.     PRINT: PRINT
  22.     PRINT "            (1) Change Directory"
  23.     PRINT "            (2) Play Song"
  24.     PRINT "            (3) Play Directory"
  25.     PRINT "            (4) Quit"
  26.     PRINT
  27.     PRINT
  28.     INPUT "      ->", a
  29.     IF a = 1 THEN GOSUB changedirectory:
  30.     IF a = 2 THEN GOSUB song:
  31.     IF a = 3 THEN GOSUB playdir:
  32.     IF a = 4 THEN END
  33.  
  34. 'Play One Song Here
  35.  
  36. song:
  37. FILES "*.mp3"
  38. again2:
  39. INPUT "Song: ", song$
  40. IF song$ = "" THEN GOTO begin:
  41. fe% = _FILEEXISTS(song$)
  42. IF fe% <> -1 THEN
  43.     PRINT "Filename doesn't exist."
  44.     PRINT "Try again, or Enter for Menu."
  45.     GOTO again2:
  46. s& = _SNDOPEN(song$)
  47. LOCATE 1, 1: PRINT song$
  48. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  49. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  50. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  51.  
  52.     a$ = INKEY$
  53.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  54.     IF a$ = " " THEN _SNDPAUSE s&
  55.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  56.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  57.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: GOTO begin:
  58.     oldp = p
  59.     p = _SNDGETPOS(s&)
  60.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  61.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO begin:
  62.  
  63. 'Play Directory Here
  64.  
  65. playdir:
  66. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  67. SHELL _HIDE "dir *.mp3 /B > MyMusicFiles-Temp000.temp" 'create mp3 files list.
  68. OPEN "MyMusicFiles-Temp000.temp" FOR INPUT AS #1
  69.     CLOSE #1
  70.     SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  71.     CLS
  72.     PRINT "No mp3 songs on this folder."
  73.     PRINT
  74.     INPUT "Press Enter to go back to Menu.", menu$
  75.     GOTO begin:
  76.     LINE INPUT #1, file$
  77.     file(record) = file$
  78.     f$(record) = file$
  79.     PRINT f$(record)
  80.     record = record + 1 'for next loop we needed array higher up to one
  81.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  82. SHELL _HIDE "DEL MyMusicFiles-Temp000.temp"
  83. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  84. ready:
  85. a$ = ""
  86. p = 0
  87. oldp = 0
  88. s& = _SNDOPEN(file(rec))
  89. LOCATE 1, 1: PRINT f$(rec)
  90. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  91. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  92. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  93.     a$ = INKEY$
  94.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  95.     IF a$ = " " THEN _SNDPAUSE s&
  96.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  97.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  98.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  99.     oldp = p
  100.     p = _SNDGETPOS(s&)
  101.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  102.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more:
  103. more:
  104. IF rec = record - 1 THEN RETURN
  105. rec = rec + 1
  106. GOTO ready:
  107. 'OPTION _EXPLICIT
  108. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  109. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  110. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  111. ' For some reason Windows won't write to a fully pathed file in my user folder???
  112. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  113. ' and now I can chDir anywhere!
  114.  
  115. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  116.  
  117. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  118.  
  119. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  120.  
  121. 'Change Directory Here
  122.  
  123. changedirectory:
  124. 'SCREEN _NEWIMAGE(1200, 600, 32)
  125. '_SCREENMOVE 100, 50
  126.  
  127.  
  128. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  129.  
  130. DIM mySelection&, done$
  131.  
  132.     PRINT "Current Directory: " + _CWD$
  133.     REDIM myFiles(0) AS STRING
  134.     loadFA "*.*", myFiles()
  135.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  136.     CLS
  137.     IF mySelection& <> -1719 THEN
  138.         CHDIR myFiles(mySelection&)
  139.     ELSE
  140.         _KEYCLEAR
  141.         EXIT DO
  142.     END IF
  143.     _LIMIT 60
  144. LOOP 'UNTIL done$ <> ""
  145.  
  146.  
  147. SUB loadFA (spec$, fa() AS STRING)
  148.     DIM tmpFile$, Index%, fline$, d$
  149.     tmpFile$ = "C:\temp\DIR$INF0.INF"
  150.     'PRINT tmpFile$
  151.     'END
  152.     SHELL _HIDE "DIR /a:d >" + tmpFile$ 'get directories  but have to do a little pruning
  153.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  154.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  155.     OPEN tmpFile$ FOR INPUT AS #1
  156.     Index% = -1
  157.     DO WHILE NOT EOF(1)
  158.         LINE INPUT #1, fline$
  159.         IF INSTR(fline$, "<DIR>") THEN
  160.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  161.             Index% = Index% + 1
  162.             REDIM _PRESERVE fa(Index%)
  163.             fa(Index%) = d$
  164.         END IF
  165.     LOOP
  166.     CLOSE #1
  167.     KILL tmpFile$
  168.  
  169. FUNCTION rightOf$ (source$, of$)
  170.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  171.  
  172. 'attempting use this 4 things (2018-12-30)
  173. ' 1. expects HELP sub that uses message and message box but easy to comment out
  174. ' 2. expects to be in graphics mode
  175. ' 3. chages color of screen
  176. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  177. '
  178. ' Future Help Message Box for the function.
  179. ' "*** Mouse and Key Instructions ***"
  180. '
  181. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  182. ' "Press spacebar to select a highlighted item or just click it."
  183. ' "Use number(s) + enter to select an array item by it's index number,"
  184. ' "backspace will remove last number pressed, c will clear a number started."
  185. ' "Numbers started are shown in bottom right PgDn bar."
  186. ' "Enter will also select the highlighted item, if no number has been started."
  187. ' "Home starts you at lowest array index, End highlights then highest index."
  188. ' "Use PgUp and PgDn keys to flip through pages of array items."
  189. '
  190. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  191. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  192.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  193.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  194.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  195.  
  196.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  197.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  198.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  199.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  200.     DIM clrStr AS STRING, b AS STRING
  201.  
  202.     'save old settings to restore at end ofsub
  203.     curRow = CSRLIN
  204.     curCol = POS(0)
  205.     fg = _DEFAULTCOLOR
  206.     bg = _BACKGROUNDCOLOR
  207.     _KEYCLEAR
  208.  
  209.     maxWidth = boxWidth '       number of characters in box
  210.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  211.     lba = LBOUND(arr)
  212.     uba = UBOUND(arr)
  213.     page = 0
  214.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  215.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  216.  
  217.     GOSUB update '              show the beginning of the array items for selection
  218.  
  219.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  220.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  221.  
  222.     DO 'until get a selection or demand exit
  223.  
  224.         'handle the key stuff
  225.         kh& = _KEYHIT
  226.         IF kh& THEN
  227.             IF kh& > 0 AND kh& < 255 THEN
  228.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  229.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  230.  
  231.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  232.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  233.                     IF LEN(b$) THEN
  234.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  235.                             choice = VAL(b$): EXIT DO
  236.                         ELSE 'clear b$ to show some response to enter
  237.                             b$ = "": GOSUB update 'clear the value that doesn't work
  238.                         END IF
  239.                     ELSE
  240.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  241.                     END IF
  242.                 END IF
  243.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  244.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  245.                 IF kh& = 8 THEN 'backspace to edit number
  246.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  247.                 END IF
  248.             ELSE
  249.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  250.                     CASE 20736 'pg dn
  251.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  252.                     CASE 18688 'pg up
  253.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  254.                     CASE 18432 'up
  255.                         IF hlite - 1 < 0 THEN
  256.                             IF page > 0 THEN
  257.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  258.                             END IF
  259.                         ELSE
  260.                             hlite = hlite - 1: GOSUB update
  261.                         END IF
  262.                     CASE 20480 'down
  263.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  264.                             IF hlite + 1 > maxHeight - 1 THEN
  265.                                 page = page + 1: hlite = 0: GOSUB update
  266.                             ELSE
  267.                                 hlite = hlite + 1: GOSUB update
  268.                             END IF
  269.                         END IF
  270.                     CASE 18176 'home
  271.                         page = 0: hlite = 0: GOSUB update
  272.                     CASE 20224 ' end
  273.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  274.                 END SELECT
  275.             END IF
  276.         END IF
  277.  
  278.         'handle the mouse stuff
  279.         WHILE _MOUSEINPUT
  280.             IF _MOUSEWHEEL = -1 THEN 'up?
  281.                 IF hlite - 1 < 0 THEN
  282.                     IF page > 0 THEN
  283.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  284.                     END IF
  285.                 ELSE
  286.                     hlite = hlite - 1: GOSUB update
  287.                 END IF
  288.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  289.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  290.                     IF hlite + 1 > maxHeight - 1 THEN
  291.                         page = page + 1: hlite = 0: GOSUB update
  292.                     ELSE
  293.                         hlite = hlite + 1: GOSUB update
  294.                     END IF
  295.                 END IF
  296.             END IF
  297.         WEND
  298.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  299.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  300.             'clear mouse clicks
  301.             mb = _MOUSEBUTTON(1)
  302.             IF mb THEN 'clear it
  303.                 WHILE mb 'OK!
  304.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  305.                     _LIMIT 100
  306.                 WEND
  307.             END IF
  308.  
  309.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  310.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  311.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  312.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  313.                     EXIT DO 'escape plan for mouse click top right corner of display box
  314.                 ELSE 'PgUp bar clicked
  315.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  316.                 END IF
  317.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  318.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  319.             END IF
  320.         ELSE '   mouse over highlighting, only if mouse has moved!
  321.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  322.                 IF mx <> lastMX OR my <> lastMY THEN
  323.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  324.                         hlite = my - 1
  325.                         lastMX = mx: lastMY = my
  326.                         GOSUB update
  327.                     END IF
  328.                 END IF
  329.             END IF
  330.         END IF
  331.         _LIMIT 200
  332.     LOOP UNTIL choice >= lba AND choice <= uba
  333.     getArrayItemNumber& = choice
  334.     COLOR fg, bg
  335.     'clear key presses
  336.     _KEYCLEAR
  337.     LOCATE curRow, curCol
  338.     'clear mouse clicks
  339.     mb = _MOUSEBUTTON(1)
  340.     IF mb THEN 'clear it
  341.         WHILE mb 'OK!
  342.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  343.             _LIMIT 100
  344.         WEND
  345.     END IF
  346.     EXIT SUB
  347.  
  348.     'display of array sections and controls on screen
  349.     update:
  350.  
  351.     'fix hlite if it has dropped below last array item
  352.     WHILE hlite + page * maxHeight + lba > uba
  353.         hlite = hlite - 1
  354.     WEND
  355.  
  356.     'main display of array items at page * maxHeight (lines high)
  357.     FOR row = 0 TO maxHeight - 1
  358.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  359.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  360.         index = row + page * maxHeight + lba
  361.         IF index >= lba AND index <= uba THEN
  362.             LOCATE locateRow + row, locateColumn
  363.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  364.         END IF
  365.     NEXT
  366.  
  367.     'make page up and down bars to click, print PgUp / PgDn if available
  368.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  369.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  370.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  371.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  372.     IF page <> INT(uba / maxHeight) THEN
  373.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  374.     END IF
  375.     'make exit sign for mouse click
  376.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  377.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  378.     PRINT " X "
  379.  
  380.     'if a number selection has been started show it's build = b$
  381.     IF LEN(b$) THEN
  382.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  383.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  384.         PRINT b$;
  385.     END IF
  386.     _DISPLAY
  387.     _LIMIT 100
  388.     RETURN
  389.  

Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 12:12:53 am
RE: Navigator in Ken's application

OK, I have to take dog out and I will check right after that...
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 12:26:35 am
I made the program a little better by shortening my temp file name (not yours) and put mine in the same c:\temp directory as yours. That wasn't the problem but I will try anything at this point just about. LOL I also added your name and updated info on the top comments.

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+ and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in a directory called c:\temp
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. begin:
  8.     DIM f$(10000)
  9.     record = 0
  10.     rec = 0
  11.     oldp = 0
  12.     p = 0
  13.     CLS
  14.     PRINT: PRINT: PRINT
  15.     PRINT "                Mini MP3 Player"
  16.     PRINT: PRINT: PRINT
  17.     PRINT "                  By Ken G."
  18.     PRINT
  19.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  20.     PRINT: PRINT
  21.     PRINT "            (1) Change Directory"
  22.     PRINT "            (2) Play Song"
  23.     PRINT "            (3) Play Directory"
  24.     PRINT "            (4) Quit"
  25.     PRINT
  26.     PRINT
  27.     INPUT "      ->", a
  28.     IF a = 1 THEN GOSUB changedirectory:
  29.     IF a = 2 THEN GOSUB song:
  30.     IF a = 3 THEN GOSUB playdir:
  31.     IF a = 4 THEN END
  32.  
  33. 'Play One Song Here
  34.  
  35. song:
  36. FILES "*.mp3"
  37. again2:
  38. INPUT "Song: ", song$
  39. IF song$ = "" THEN GOTO begin:
  40. fe% = _FILEEXISTS(song$)
  41. IF fe% <> -1 THEN
  42.     PRINT "Filename doesn't exist."
  43.     PRINT "Try again, or Enter for Menu."
  44.     GOTO again2:
  45. s& = _SNDOPEN(song$)
  46. LOCATE 1, 1: PRINT song$
  47. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  48. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  49. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  50.  
  51.     a$ = INKEY$
  52.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  53.     IF a$ = " " THEN _SNDPAUSE s&
  54.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  55.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  56.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: GOTO begin:
  57.     oldp = p
  58.     p = _SNDGETPOS(s&)
  59.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  60.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO begin:
  61.  
  62. 'Play Directory Here
  63.  
  64. playdir:
  65. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  66. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  67. SHELL _HIDE "dir *.mp3 /B > C:\temp\MyMusicFiles.temp" 'create mp3 files list.
  68. OPEN "C:\temp\MyMusicFiles.temp" FOR INPUT AS #1
  69.     CLOSE #1
  70.     SHELL _HIDE "DEL C:\temp\MyMusicFiles.temp"
  71.     CLS
  72.     PRINT "No mp3 songs on this folder."
  73.     PRINT
  74.     INPUT "Press Enter to go back to Menu.", menu$
  75.     GOTO begin:
  76.     LINE INPUT #1, file$
  77.     file(record) = file$
  78.     f$(record) = file$
  79.     PRINT f$(record)
  80.     record = record + 1 'for next loop we needed array higher up to one
  81.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  82. SHELL _HIDE "DEL C:\temp\MyMusicFiles.temp"
  83. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  84. ready:
  85. a$ = ""
  86. p = 0
  87. oldp = 0
  88. s& = _SNDOPEN(file(rec))
  89. LOCATE 1, 1: PRINT f$(rec)
  90. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  91. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  92. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  93.     a$ = INKEY$
  94.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  95.     IF a$ = " " THEN _SNDPAUSE s&
  96.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  97.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  98.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  99.     oldp = p
  100.     p = _SNDGETPOS(s&)
  101.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  102.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more:
  103. more:
  104. IF rec = record - 1 THEN RETURN
  105. rec = rec + 1
  106. GOTO ready:
  107. 'OPTION _EXPLICIT
  108. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  109. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  110. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  111. ' For some reason Windows won't write to a fully pathed file in my user folder???
  112. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  113. ' and now I can chDir anywhere!
  114.  
  115. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  116.  
  117. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  118.  
  119. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  120.  
  121. 'Change Directory Here
  122.  
  123. changedirectory:
  124. 'SCREEN _NEWIMAGE(1200, 600, 32)
  125. '_SCREENMOVE 100, 50
  126.  
  127.  
  128. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  129.  
  130. DIM mySelection&, done$
  131.  
  132.     PRINT "Current Directory: " + _CWD$
  133.     REDIM myFiles(0) AS STRING
  134.     loadFA "*.*", myFiles()
  135.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  136.     CLS
  137.     IF mySelection& <> -1719 THEN
  138.         CHDIR myFiles(mySelection&)
  139.     ELSE
  140.         _KEYCLEAR
  141.         EXIT DO
  142.     END IF
  143.     _LIMIT 60
  144. LOOP 'UNTIL done$ <> ""
  145.  
  146.  
  147. SUB loadFA (spec$, fa() AS STRING)
  148.     DIM tmpFile$, Index%, fline$, d$
  149.     tmpFile$ = "C:\temp\DIR$INF0.INF"
  150.     'PRINT tmpFile$
  151.     'END
  152.     SHELL _HIDE "DIR /a:d >" + tmpFile$ 'get directories  but have to do a little pruning
  153.     'SHELL _HIDE "DIR " + spec$ + " /b > " + TmpFile$
  154.     'SHELL _HIDE "DIR " + spec$ + " /b /s /o:gen> " + TmpFile$
  155.     OPEN tmpFile$ FOR INPUT AS #1
  156.     Index% = -1
  157.     DO WHILE NOT EOF(1)
  158.         LINE INPUT #1, fline$
  159.         IF INSTR(fline$, "<DIR>") THEN
  160.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  161.             Index% = Index% + 1
  162.             REDIM _PRESERVE fa(Index%)
  163.             fa(Index%) = d$
  164.         END IF
  165.     LOOP
  166.     CLOSE #1
  167.     KILL tmpFile$
  168.  
  169. FUNCTION rightOf$ (source$, of$)
  170.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  171.  
  172. 'attempting use this 4 things (2018-12-30)
  173. ' 1. expects HELP sub that uses message and message box but easy to comment out
  174. ' 2. expects to be in graphics mode
  175. ' 3. chages color of screen
  176. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  177. '
  178. ' Future Help Message Box for the function.
  179. ' "*** Mouse and Key Instructions ***"
  180. '
  181. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  182. ' "Press spacebar to select a highlighted item or just click it."
  183. ' "Use number(s) + enter to select an array item by it's index number,"
  184. ' "backspace will remove last number pressed, c will clear a number started."
  185. ' "Numbers started are shown in bottom right PgDn bar."
  186. ' "Enter will also select the highlighted item, if no number has been started."
  187. ' "Home starts you at lowest array index, End highlights then highest index."
  188. ' "Use PgUp and PgDn keys to flip through pages of array items."
  189. '
  190. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  191. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  192.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  193.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  194.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  195.  
  196.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  197.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  198.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  199.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  200.     DIM clrStr AS STRING, b AS STRING
  201.  
  202.     'save old settings to restore at end ofsub
  203.     curRow = CSRLIN
  204.     curCol = POS(0)
  205.     fg = _DEFAULTCOLOR
  206.     bg = _BACKGROUNDCOLOR
  207.     _KEYCLEAR
  208.  
  209.     maxWidth = boxWidth '       number of characters in box
  210.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  211.     lba = LBOUND(arr)
  212.     uba = UBOUND(arr)
  213.     page = 0
  214.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  215.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  216.  
  217.     GOSUB update '              show the beginning of the array items for selection
  218.  
  219.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  220.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  221.  
  222.     DO 'until get a selection or demand exit
  223.  
  224.         'handle the key stuff
  225.         kh& = _KEYHIT
  226.         IF kh& THEN
  227.             IF kh& > 0 AND kh& < 255 THEN
  228.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  229.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  230.  
  231.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  232.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  233.                     IF LEN(b$) THEN
  234.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  235.                             choice = VAL(b$): EXIT DO
  236.                         ELSE 'clear b$ to show some response to enter
  237.                             b$ = "": GOSUB update 'clear the value that doesn't work
  238.                         END IF
  239.                     ELSE
  240.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  241.                     END IF
  242.                 END IF
  243.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  244.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  245.                 IF kh& = 8 THEN 'backspace to edit number
  246.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  247.                 END IF
  248.             ELSE
  249.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  250.                     CASE 20736 'pg dn
  251.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  252.                     CASE 18688 'pg up
  253.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  254.                     CASE 18432 'up
  255.                         IF hlite - 1 < 0 THEN
  256.                             IF page > 0 THEN
  257.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  258.                             END IF
  259.                         ELSE
  260.                             hlite = hlite - 1: GOSUB update
  261.                         END IF
  262.                     CASE 20480 'down
  263.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  264.                             IF hlite + 1 > maxHeight - 1 THEN
  265.                                 page = page + 1: hlite = 0: GOSUB update
  266.                             ELSE
  267.                                 hlite = hlite + 1: GOSUB update
  268.                             END IF
  269.                         END IF
  270.                     CASE 18176 'home
  271.                         page = 0: hlite = 0: GOSUB update
  272.                     CASE 20224 ' end
  273.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  274.                 END SELECT
  275.             END IF
  276.         END IF
  277.  
  278.         'handle the mouse stuff
  279.         WHILE _MOUSEINPUT
  280.             IF _MOUSEWHEEL = -1 THEN 'up?
  281.                 IF hlite - 1 < 0 THEN
  282.                     IF page > 0 THEN
  283.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  284.                     END IF
  285.                 ELSE
  286.                     hlite = hlite - 1: GOSUB update
  287.                 END IF
  288.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  289.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  290.                     IF hlite + 1 > maxHeight - 1 THEN
  291.                         page = page + 1: hlite = 0: GOSUB update
  292.                     ELSE
  293.                         hlite = hlite + 1: GOSUB update
  294.                     END IF
  295.                 END IF
  296.             END IF
  297.         WEND
  298.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  299.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  300.             'clear mouse clicks
  301.             mb = _MOUSEBUTTON(1)
  302.             IF mb THEN 'clear it
  303.                 WHILE mb 'OK!
  304.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  305.                     _LIMIT 100
  306.                 WEND
  307.             END IF
  308.  
  309.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  310.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  311.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  312.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  313.                     EXIT DO 'escape plan for mouse click top right corner of display box
  314.                 ELSE 'PgUp bar clicked
  315.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  316.                 END IF
  317.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  318.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  319.             END IF
  320.         ELSE '   mouse over highlighting, only if mouse has moved!
  321.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  322.                 IF mx <> lastMX OR my <> lastMY THEN
  323.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  324.                         hlite = my - 1
  325.                         lastMX = mx: lastMY = my
  326.                         GOSUB update
  327.                     END IF
  328.                 END IF
  329.             END IF
  330.         END IF
  331.         _LIMIT 200
  332.     LOOP UNTIL choice >= lba AND choice <= uba
  333.     getArrayItemNumber& = choice
  334.     COLOR fg, bg
  335.     'clear key presses
  336.     _KEYCLEAR
  337.     LOCATE curRow, curCol
  338.     'clear mouse clicks
  339.     mb = _MOUSEBUTTON(1)
  340.     IF mb THEN 'clear it
  341.         WHILE mb 'OK!
  342.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  343.             _LIMIT 100
  344.         WEND
  345.     END IF
  346.     EXIT SUB
  347.  
  348.     'display of array sections and controls on screen
  349.     update:
  350.  
  351.     'fix hlite if it has dropped below last array item
  352.     WHILE hlite + page * maxHeight + lba > uba
  353.         hlite = hlite - 1
  354.     WEND
  355.  
  356.     'main display of array items at page * maxHeight (lines high)
  357.     FOR row = 0 TO maxHeight - 1
  358.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  359.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  360.         index = row + page * maxHeight + lba
  361.         IF index >= lba AND index <= uba THEN
  362.             LOCATE locateRow + row, locateColumn
  363.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  364.         END IF
  365.     NEXT
  366.  
  367.     'make page up and down bars to click, print PgUp / PgDn if available
  368.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  369.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  370.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  371.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  372.     IF page <> INT(uba / maxHeight) THEN
  373.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  374.     END IF
  375.     'make exit sign for mouse click
  376.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  377.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  378.     PRINT " X "
  379.  
  380.     'if a number selection has been started show it's build = b$
  381.     IF LEN(b$) THEN
  382.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  383.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  384.         PRINT b$;
  385.     END IF
  386.     _DISPLAY
  387.     _LIMIT 100
  388.     RETURN
  389.  
  390.  

Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 12:54:22 am
RE: Navigator in Ken's application

While walking the dog, I remembered you had allot of things going back to Begin: label, but not Navigator (as I remember) could something need to be reinitialized or zero'd out after change directory?

A thought for you while I go over your latest revision.

This line needs to be done once right at beginning:
Code: QB64: [Select]
  1. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  2.  
just once is enough!

Your main menu loop is beautiful to my eye.

Code: QB64: [Select]
  1. IF song$ = "" THEN GOTO begin:
Instead of GOTO begin, RETURN is much better form, should not jump out of GOSUBs with GOTOs always RETURN because the interpreter or compiler needs to see RETURN for closure, like for every ( open parenthesis there should be a ) close parenthesis.

I think RETURNS are put in a stack of goto lines, if return is never reached in one sub, the next return found is likely to return to where the first sub was suppose to return to. You can use GOTO's that stay completely inside a GOSUB like your goto again2: 3 places in GOSUB Song: you are GOTOing to Begin: just RETURN should do it.

Not a biggy but it is nicer form to EXIT DO rather a GOTO jump.
Code: QB64: [Select]
  1.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN GOTO more: '<<<  just EXIT DO
  2. more:

The GOTO Begin: in Song GOSUB could be causing weird results. That's best I could find at this late hour.
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 09:19:59 am
RE: Navigator in Ken's application
Code: QB64: [Select]
  1.  
  2. changedirectory:
  3. 'SCREEN _NEWIMAGE(1200, 600, 32)
  4. '_SCREENMOVE 100, 50
  5.  
  6. 'VVVVVVVVVVVVV Yuck! I have note about this line in comments VVVVVVVVVVVVVVVVVVVV
  7.  
  8. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  9. ' Replace at start of program to do only once then use SHARED variable tmpDir for writing
  10. ' temp files in a good spot for user, updated sub that uses tmpDir.
  11.  
  12. '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  13.  
  14.  
  15. DIM mySelection&, done$
  16.  
  17.     PRINT "Current Directory: " + _CWD$
  18.     REDIM myFiles(0) AS STRING
  19.     loadFA "*.*", myFiles()
  20.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  21.     IF mySelection& <> -1719 THEN
  22.         CLS  '<<<<<<<<<<<<<<   moved from right after mySelection& = getA....
  23.         CHDIR myFiles(mySelection&)
  24.     ELSE
  25.         _KEYCLEAR
  26.        ' >>>>>>>>>>>>>>>>>>>>>>>>>> OK now CLS is NOT clearing if eXiting
  27. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  28. 'Ken, insert here what ever you want to see the screen display do, that is not happening now.
  29. ' It will / should other wise cycle back to your Menu.
  30. ' Maybe it should GOSUB Song or GOSUB PlayDirectory before RETURN to Menu???
  31. ' This is where the navigator is signaled by escape press or X click in to right corner of screen to eXit
  32. ' Perfect place to get screen ready for return to the business of playing music.
  33. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  34.  
  35.         EXIT DO
  36.     END IF
  37.     _LIMIT 60
  38. LOOP 'UNTIL done$ <> ""
  39.  
  40.  
  41.  

Ken, the Navigator code is improved (but more to go) since you grabbed roughed out version.
Mainly, the DIM SHARED TmpDir as string, fix Steve suggested would be good to add to start of your program but then the LoadFA code needs to be changed (that would get rid of warning too.)

LoadFA changed to this: ( to use TmpDir and drop the spec$ in call to sub )
Code: QB64: [Select]
  1. SUB loadDIR (fa() AS STRING)
  2.     DIM tmpFile AS STRING, Index%, fline$, d$
  3.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  4.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  5.     OPEN tmpFile FOR INPUT AS #1
  6.     Index% = -1
  7.     DO WHILE NOT EOF(1)
  8.         LINE INPUT #1, fline$
  9.         IF INSTR(fline$, "<DIR>") THEN
  10.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  11.             Index% = Index% + 1
  12.             REDIM _PRESERVE fa(Index%)
  13.             fa(Index%) = d$
  14.         END IF
  15.     LOOP
  16.     CLOSE #1
  17.     KILL tmpFile
  18.  

Then the call to it in your app should be:
Code: QB64: [Select]
  1.     PRINT "Current Directory: " + _CWD$
  2.     REDIM myFiles(0) AS STRING   ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  3.  
  4.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  5.     loadDIR myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  6.  
  7.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  8.     CLS
  9.     IF mySelection& <> -1719 THEN
  10.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  11.     ELSE
  12.         _KEYCLEAR
  13.         EXIT DO
  14.     END IF
  15.     _LIMIT 60
  16. LOOP 'UNTIL done$ <> ""
  17.  

Dang! I have 2 sets of changes, one modifies code to updated version of Navigator code involving the tmpDir for temp files, the other moves a CLS and advises where to insert code with the old (current) state of Ken app to play nicely with the music and Ken's vision of the player.
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 10:45:44 am
I guess the next logical step is to turn this into a Modal Dialog for Retrieving File or Directory names. :)

I hope to get the idea of screen state worked in, that I use for mBox and inputBox, maybe put the whole set in a library, maybe change Function getArrayItemNumber to SUB ListBox.
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 01:16:13 pm
Your SUB has an error that won't make it work, on this line:
tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!   

The error says: Cannot convert number to string.

Do I need any of Steve's code for this windows temp directory?

But thanks for the rest, I changed everything to what you said.

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+ and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in a directory called c:\temp
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  8. begin:
  9.     DIM f$(10000)
  10.     record = 0
  11.     rec = 0
  12.     oldp = 0
  13.     p = 0
  14.     CLS
  15.     PRINT: PRINT: PRINT
  16.     PRINT "                Mini MP3 Player"
  17.     PRINT: PRINT: PRINT
  18.     PRINT "                  By Ken G."
  19.     PRINT
  20.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  21.     PRINT: PRINT
  22.     PRINT "            (1) Change Directory"
  23.     PRINT "            (2) Play Song"
  24.     PRINT "            (3) Play Directory"
  25.     PRINT "            (4) Quit"
  26.     PRINT
  27.     PRINT
  28.     INPUT "      ->", a
  29.     IF a = 1 THEN GOSUB changedirectory:
  30.     IF a = 2 THEN GOSUB song:
  31.     IF a = 3 THEN GOSUB playdir:
  32.     IF a = 4 THEN END
  33.  
  34. 'Play One Song Here
  35.  
  36. song:
  37. FILES "*.mp3"
  38. again2:
  39. INPUT "Song: ", song$
  40. IF song$ = "" THEN RETURN
  41. fe% = _FILEEXISTS(song$)
  42. IF fe% <> -1 THEN
  43.     PRINT "Filename doesn't exist."
  44.     PRINT "Try again, or Enter for Menu."
  45.     GOTO again2:
  46. s& = _SNDOPEN(song$)
  47. LOCATE 1, 1: PRINT song$
  48. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  49. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  50. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  51.  
  52.     a$ = INKEY$
  53.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  54.     IF a$ = " " THEN _SNDPAUSE s&
  55.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  56.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  57.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  58.     oldp = p
  59.     p = _SNDGETPOS(s&)
  60.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  61.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  62.  
  63. 'Play Directory Here
  64.  
  65. playdir:
  66. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  67. SHELL _HIDE "dir *.mp3 /B > C:\temp\MyMusicFiles.temp" 'create mp3 files list.
  68. OPEN "C:\temp\MyMusicFiles.temp" FOR INPUT AS #1
  69.     CLOSE #1
  70.     SHELL _HIDE "DEL C:\temp\MyMusicFiles.temp"
  71.     CLS
  72.     PRINT "No mp3 songs on this folder."
  73.     PRINT
  74.     INPUT "Press Enter to go back to Menu.", menu$
  75.     RETURN
  76.     LINE INPUT #1, file$
  77.     file(record) = file$
  78.     f$(record) = file$
  79.     PRINT f$(record)
  80.     record = record + 1 'for next loop we needed array higher up to one
  81.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  82. SHELL _HIDE "DEL C:\temp\MyMusicFiles.temp"
  83. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  84. ready:
  85. a$ = ""
  86. p = 0
  87. oldp = 0
  88. s& = _SNDOPEN(file(rec))
  89. LOCATE 1, 1: PRINT f$(rec)
  90. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  91. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  92. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  93.     a$ = INKEY$
  94.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  95.     IF a$ = " " THEN _SNDPAUSE s&
  96.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  97.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  98.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  99.     oldp = p
  100.     p = _SNDGETPOS(s&)
  101.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  102.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  103. more:
  104. IF rec = record - 1 THEN RETURN
  105. rec = rec + 1
  106. GOTO ready:
  107. 'OPTION _EXPLICIT
  108. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  109. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  110. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  111. ' For some reason Windows won't write to a fully pathed file in my user folder???
  112. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  113. ' and now I can chDir anywhere!
  114.  
  115. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  116.  
  117. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  118.  
  119. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  120.  
  121. 'Change Directory Here
  122.  
  123.  
  124. changedirectory:
  125. 'SCREEN _NEWIMAGE(1200, 600, 32)
  126. '_SCREENMOVE 100, 50
  127.  
  128.  
  129. DIM mySelection&, done$
  130.  
  131.     PRINT "Current Directory: " + _CWD$
  132.     REDIM myFiles(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  133.  
  134.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  135.     loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  136.  
  137.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  138.     CLS
  139.     IF mySelection& <> -1719 THEN
  140.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  141.     ELSE
  142.         _KEYCLEAR
  143.         EXIT DO
  144.     END IF
  145.     _LIMIT 60
  146. LOOP 'UNTIL done$ <> ""
  147.  
  148.  
  149.  
  150.  
  151. SUB loadDIR (fa() AS STRING)
  152.     DIM tmpFile AS STRING, Index%, fline$, d$
  153.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  154.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  155.     OPEN tmpFile FOR INPUT AS #1
  156.     Index% = -1
  157.     DO WHILE NOT EOF(1)
  158.         LINE INPUT #1, fline$
  159.         IF INSTR(fline$, "<DIR>") THEN
  160.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  161.             Index% = Index% + 1
  162.             REDIM _PRESERVE fa(Index%)
  163.             fa(Index%) = d$
  164.         END IF
  165.     LOOP
  166.     CLOSE #1
  167.     KILL tmpFile
  168.  
  169. FUNCTION rightOf$ (source$, of$)
  170.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  171.  
  172. 'attempting use this 4 things (2018-12-30)
  173. ' 1. expects HELP sub that uses message and message box but easy to comment out
  174. ' 2. expects to be in graphics mode
  175. ' 3. chages color of screen
  176. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  177. '
  178. ' Future Help Message Box for the function.
  179. ' "*** Mouse and Key Instructions ***"
  180. '
  181. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  182. ' "Press spacebar to select a highlighted item or just click it."
  183. ' "Use number(s) + enter to select an array item by it's index number,"
  184. ' "backspace will remove last number pressed, c will clear a number started."
  185. ' "Numbers started are shown in bottom right PgDn bar."
  186. ' "Enter will also select the highlighted item, if no number has been started."
  187. ' "Home starts you at lowest array index, End highlights then highest index."
  188. ' "Use PgUp and PgDn keys to flip through pages of array items."
  189. '
  190. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  191. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  192.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  193.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  194.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  195.  
  196.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  197.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  198.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  199.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  200.     DIM clrStr AS STRING, b AS STRING
  201.  
  202.     'save old settings to restore at end ofsub
  203.     curRow = CSRLIN
  204.     curCol = POS(0)
  205.     fg = _DEFAULTCOLOR
  206.     bg = _BACKGROUNDCOLOR
  207.     _KEYCLEAR
  208.  
  209.     maxWidth = boxWidth '       number of characters in box
  210.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  211.     lba = LBOUND(arr)
  212.     uba = UBOUND(arr)
  213.     page = 0
  214.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  215.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  216.  
  217.     GOSUB update '              show the beginning of the array items for selection
  218.  
  219.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  220.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  221.  
  222.     DO 'until get a selection or demand exit
  223.  
  224.         'handle the key stuff
  225.         kh& = _KEYHIT
  226.         IF kh& THEN
  227.             IF kh& > 0 AND kh& < 255 THEN
  228.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  229.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  230.  
  231.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  232.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  233.                     IF LEN(b$) THEN
  234.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  235.                             choice = VAL(b$): EXIT DO
  236.                         ELSE 'clear b$ to show some response to enter
  237.                             b$ = "": GOSUB update 'clear the value that doesn't work
  238.                         END IF
  239.                     ELSE
  240.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  241.                     END IF
  242.                 END IF
  243.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  244.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  245.                 IF kh& = 8 THEN 'backspace to edit number
  246.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  247.                 END IF
  248.             ELSE
  249.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  250.                     CASE 20736 'pg dn
  251.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  252.                     CASE 18688 'pg up
  253.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  254.                     CASE 18432 'up
  255.                         IF hlite - 1 < 0 THEN
  256.                             IF page > 0 THEN
  257.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  258.                             END IF
  259.                         ELSE
  260.                             hlite = hlite - 1: GOSUB update
  261.                         END IF
  262.                     CASE 20480 'down
  263.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  264.                             IF hlite + 1 > maxHeight - 1 THEN
  265.                                 page = page + 1: hlite = 0: GOSUB update
  266.                             ELSE
  267.                                 hlite = hlite + 1: GOSUB update
  268.                             END IF
  269.                         END IF
  270.                     CASE 18176 'home
  271.                         page = 0: hlite = 0: GOSUB update
  272.                     CASE 20224 ' end
  273.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  274.                 END SELECT
  275.             END IF
  276.         END IF
  277.  
  278.         'handle the mouse stuff
  279.         WHILE _MOUSEINPUT
  280.             IF _MOUSEWHEEL = -1 THEN 'up?
  281.                 IF hlite - 1 < 0 THEN
  282.                     IF page > 0 THEN
  283.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  284.                     END IF
  285.                 ELSE
  286.                     hlite = hlite - 1: GOSUB update
  287.                 END IF
  288.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  289.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  290.                     IF hlite + 1 > maxHeight - 1 THEN
  291.                         page = page + 1: hlite = 0: GOSUB update
  292.                     ELSE
  293.                         hlite = hlite + 1: GOSUB update
  294.                     END IF
  295.                 END IF
  296.             END IF
  297.         WEND
  298.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  299.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  300.             'clear mouse clicks
  301.             mb = _MOUSEBUTTON(1)
  302.             IF mb THEN 'clear it
  303.                 WHILE mb 'OK!
  304.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  305.                     _LIMIT 100
  306.                 WEND
  307.             END IF
  308.  
  309.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  310.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  311.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  312.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  313.                     EXIT DO 'escape plan for mouse click top right corner of display box
  314.                 ELSE 'PgUp bar clicked
  315.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  316.                 END IF
  317.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  318.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  319.             END IF
  320.         ELSE '   mouse over highlighting, only if mouse has moved!
  321.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  322.                 IF mx <> lastMX OR my <> lastMY THEN
  323.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  324.                         hlite = my - 1
  325.                         lastMX = mx: lastMY = my
  326.                         GOSUB update
  327.                     END IF
  328.                 END IF
  329.             END IF
  330.         END IF
  331.         _LIMIT 200
  332.     LOOP UNTIL choice >= lba AND choice <= uba
  333.     getArrayItemNumber& = choice
  334.     COLOR fg, bg
  335.     'clear key presses
  336.     _KEYCLEAR
  337.     LOCATE curRow, curCol
  338.     'clear mouse clicks
  339.     mb = _MOUSEBUTTON(1)
  340.     IF mb THEN 'clear it
  341.         WHILE mb 'OK!
  342.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  343.             _LIMIT 100
  344.         WEND
  345.     END IF
  346.     EXIT SUB
  347.  
  348.     'display of array sections and controls on screen
  349.     update:
  350.  
  351.     'fix hlite if it has dropped below last array item
  352.     WHILE hlite + page * maxHeight + lba > uba
  353.         hlite = hlite - 1
  354.     WEND
  355.  
  356.     'main display of array items at page * maxHeight (lines high)
  357.     FOR row = 0 TO maxHeight - 1
  358.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  359.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  360.         index = row + page * maxHeight + lba
  361.         IF index >= lba AND index <= uba THEN
  362.             LOCATE locateRow + row, locateColumn
  363.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  364.         END IF
  365.     NEXT
  366.  
  367.     'make page up and down bars to click, print PgUp / PgDn if available
  368.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  369.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  370.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  371.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  372.     IF page <> INT(uba / maxHeight) THEN
  373.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  374.     END IF
  375.     'make exit sign for mouse click
  376.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  377.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  378.     PRINT " X "
  379.  
  380.     'if a number selection has been started show it's build = b$
  381.     IF LEN(b$) THEN
  382.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  383.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  384.         PRINT b$;
  385.     END IF
  386.     _DISPLAY
  387.     _LIMIT 100
  388.     RETURN
  389.  
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 01:26:34 pm
Your SUB has an error that won't make it work, on this line:
tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!   

The error says: Cannot convert number to string.

Do I need any of Steve's code for this windows temp directory?

QB64 thinks it's a number because we didn't DIM SHARED  tmpDir at start and then set it at start also.
So, you need this clip for starting program, sorry:
Code: QB64: [Select]
  1. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  2. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  3.     tmpDir = ENVIRON$("TEMP")
  4. ELSEIF ENVIRON$("TMP") <> "" THEN
  5.     tmpDir = ENVIRON$("TMP")
  6. ELSE 'Thanks to Steve McNeill this should be very unlikely
  7.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  8.     tmpDir = "C:\temp"
  9.  

ENVIRON$ is a function that returns values for various variables Windows uses for settings and Paths.
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 03:50:41 pm
Thanks, but we are now back where we started. Maybe you misunderstood me about the problem. Your menu exits out back to my main menu fine. There's no problem with that at all, that I know of. The problem is when after I use your menu, and go back to my main menu and choose "Play Directory", it just sits there, but it also plays the songs. So it DOES go to the playdir section, but for some crazy reason it doesn't CLS and PRINT the sound information that it's playing. Another funny thing is that I can still use the space bar to Pause and P to keep playing, etc., that's in the playdir section. Another strange thing is that if I do not use your code to change the directory and just open the program and choose Play Directory, everything displays fine. So in other words, half of my code is working and the other half is not, on the same section (playdir). Try it out if you want to see what it's doing. But like I said before, no pressure. You mentioned to put whatever I want in that area in the changedir area, I might play around with putting the playdir code inside that and just make 1 section both a change directory and a play directory at the same time. Maybe that will work. I'll try it out. For now, this is what I have. I do appreciate the help. Actually, since your menu exits out fine back to my main menu good, I'm not going to mess with combining them yet.

Edit: I also just added the right temp directory to all the code.

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+ and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in a directory called c:\temp
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. begin:
  17.     DIM f$(10000)
  18.     record = 0
  19.     rec = 0
  20.     oldp = 0
  21.     p = 0
  22.     CLS
  23.     PRINT: PRINT: PRINT
  24.     PRINT "                Mini MP3 Player"
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                  By Ken G."
  27.     PRINT
  28.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  29.     PRINT: PRINT
  30.     PRINT "            (1) Change Directory"
  31.     PRINT "            (2) Play Song"
  32.     PRINT "            (3) Play Directory"
  33.     PRINT "            (4) Quit"
  34.     PRINT
  35.     PRINT
  36.     INPUT "      ->", a
  37.     IF a = 1 THEN GOSUB changedirectory:
  38.     IF a = 2 THEN GOSUB song:
  39.     IF a = 3 THEN GOSUB playdir:
  40.     IF a = 4 THEN END
  41.  
  42. 'Play One Song Here
  43.  
  44. song:
  45. FILES "*.mp3"
  46. again2:
  47. INPUT "Song: ", song$
  48. IF song$ = "" THEN RETURN
  49. fe% = _FILEEXISTS(song$)
  50. IF fe% <> -1 THEN
  51.     PRINT "Filename doesn't exist."
  52.     PRINT "Try again, or Enter for Menu."
  53.     GOTO again2:
  54. s& = _SNDOPEN(song$)
  55. LOCATE 1, 1: PRINT song$
  56. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  57. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  58. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  59.  
  60.     a$ = INKEY$
  61.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  62.     IF a$ = " " THEN _SNDPAUSE s&
  63.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  64.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  65.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  66.     oldp = p
  67.     p = _SNDGETPOS(s&)
  68.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  69.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  70.  
  71. 'Play Directory Here
  72.  
  73. playdir:
  74. record = 0
  75. rec = 0
  76. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  77. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  78. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  79.     CLOSE #1
  80.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  81.     CLS
  82.     PRINT "No mp3 songs on this folder."
  83.     PRINT
  84.     INPUT "Press Enter to go back to Menu.", menu$
  85.     RETURN
  86.     LINE INPUT #1, file$
  87.     file(record) = file$
  88.     f$(record) = file$
  89.     PRINT f$(record)
  90.     record = record + 1 'for next loop we needed array higher up to one
  91.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  92. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  93. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  94. ready:
  95. a$ = ""
  96. p = 0
  97. oldp = 0
  98. s& = _SNDOPEN(file(rec))
  99. LOCATE 1, 1: PRINT f$(rec)
  100. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  101. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  102. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  103.     a$ = INKEY$
  104.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  105.     IF a$ = " " THEN _SNDPAUSE s&
  106.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  107.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  108.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  109.     oldp = p
  110.     p = _SNDGETPOS(s&)
  111.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  112.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  113. more:
  114. IF rec = record - 1 THEN RETURN
  115. rec = rec + 1
  116. GOTO ready:
  117. 'OPTION _EXPLICIT
  118. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  119. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  120. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  121. ' For some reason Windows won't write to a fully pathed file in my user folder???
  122. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  123. ' and now I can chDir anywhere!
  124.  
  125. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  126.  
  127. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  128.  
  129. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  130.  
  131. 'Change Directory Here
  132.  
  133.  
  134. changedirectory:
  135. 'SCREEN _NEWIMAGE(1200, 600, 32)
  136. '_SCREENMOVE 100, 50
  137.  
  138.  
  139. DIM mySelection&, done$
  140.  
  141.     PRINT "Current Directory: " + _CWD$
  142.     REDIM myFiles(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  143.  
  144.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  145.     loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  146.  
  147.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  148.     CLS
  149.     IF mySelection& <> -1719 THEN
  150.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  151.     ELSE
  152.         _KEYCLEAR
  153.         EXIT DO
  154.     END IF
  155.     _LIMIT 60
  156. LOOP 'UNTIL done$ <> ""
  157.  
  158.  
  159.  
  160.  
  161. SUB loadDIR (fa() AS STRING)
  162.     DIM tmpFile AS STRING, Index%, fline$, d$
  163.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  164.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  165.     OPEN tmpFile FOR INPUT AS #1
  166.     Index% = -1
  167.     DO WHILE NOT EOF(1)
  168.         LINE INPUT #1, fline$
  169.         IF INSTR(fline$, "<DIR>") THEN
  170.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  171.             Index% = Index% + 1
  172.             REDIM _PRESERVE fa(Index%)
  173.             fa(Index%) = d$
  174.         END IF
  175.     LOOP
  176.     CLOSE #1
  177.     KILL tmpFile
  178.  
  179. FUNCTION rightOf$ (source$, of$)
  180.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  181.  
  182. 'attempting use this 4 things (2018-12-30)
  183. ' 1. expects HELP sub that uses message and message box but easy to comment out
  184. ' 2. expects to be in graphics mode
  185. ' 3. chages color of screen
  186. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  187. '
  188. ' Future Help Message Box for the function.
  189. ' "*** Mouse and Key Instructions ***"
  190. '
  191. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  192. ' "Press spacebar to select a highlighted item or just click it."
  193. ' "Use number(s) + enter to select an array item by it's index number,"
  194. ' "backspace will remove last number pressed, c will clear a number started."
  195. ' "Numbers started are shown in bottom right PgDn bar."
  196. ' "Enter will also select the highlighted item, if no number has been started."
  197. ' "Home starts you at lowest array index, End highlights then highest index."
  198. ' "Use PgUp and PgDn keys to flip through pages of array items."
  199. '
  200. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  201. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  202.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  203.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  204.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  205.  
  206.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  207.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  208.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  209.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  210.     DIM clrStr AS STRING, b AS STRING
  211.  
  212.     'save old settings to restore at end ofsub
  213.     curRow = CSRLIN
  214.     curCol = POS(0)
  215.     fg = _DEFAULTCOLOR
  216.     bg = _BACKGROUNDCOLOR
  217.     _KEYCLEAR
  218.  
  219.     maxWidth = boxWidth '       number of characters in box
  220.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  221.     lba = LBOUND(arr)
  222.     uba = UBOUND(arr)
  223.     page = 0
  224.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  225.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  226.  
  227.     GOSUB update '              show the beginning of the array items for selection
  228.  
  229.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  230.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  231.  
  232.     DO 'until get a selection or demand exit
  233.  
  234.         'handle the key stuff
  235.         kh& = _KEYHIT
  236.         IF kh& THEN
  237.             IF kh& > 0 AND kh& < 255 THEN
  238.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  239.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  240.  
  241.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  242.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  243.                     IF LEN(b$) THEN
  244.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  245.                             choice = VAL(b$): EXIT DO
  246.                         ELSE 'clear b$ to show some response to enter
  247.                             b$ = "": GOSUB update 'clear the value that doesn't work
  248.                         END IF
  249.                     ELSE
  250.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  251.                     END IF
  252.                 END IF
  253.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  254.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  255.                 IF kh& = 8 THEN 'backspace to edit number
  256.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  257.                 END IF
  258.             ELSE
  259.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  260.                     CASE 20736 'pg dn
  261.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  262.                     CASE 18688 'pg up
  263.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  264.                     CASE 18432 'up
  265.                         IF hlite - 1 < 0 THEN
  266.                             IF page > 0 THEN
  267.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  268.                             END IF
  269.                         ELSE
  270.                             hlite = hlite - 1: GOSUB update
  271.                         END IF
  272.                     CASE 20480 'down
  273.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  274.                             IF hlite + 1 > maxHeight - 1 THEN
  275.                                 page = page + 1: hlite = 0: GOSUB update
  276.                             ELSE
  277.                                 hlite = hlite + 1: GOSUB update
  278.                             END IF
  279.                         END IF
  280.                     CASE 18176 'home
  281.                         page = 0: hlite = 0: GOSUB update
  282.                     CASE 20224 ' end
  283.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  284.                 END SELECT
  285.             END IF
  286.         END IF
  287.  
  288.         'handle the mouse stuff
  289.         WHILE _MOUSEINPUT
  290.             IF _MOUSEWHEEL = -1 THEN 'up?
  291.                 IF hlite - 1 < 0 THEN
  292.                     IF page > 0 THEN
  293.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  294.                     END IF
  295.                 ELSE
  296.                     hlite = hlite - 1: GOSUB update
  297.                 END IF
  298.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  299.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  300.                     IF hlite + 1 > maxHeight - 1 THEN
  301.                         page = page + 1: hlite = 0: GOSUB update
  302.                     ELSE
  303.                         hlite = hlite + 1: GOSUB update
  304.                     END IF
  305.                 END IF
  306.             END IF
  307.         WEND
  308.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  309.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  310.             'clear mouse clicks
  311.             mb = _MOUSEBUTTON(1)
  312.             IF mb THEN 'clear it
  313.                 WHILE mb 'OK!
  314.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  315.                     _LIMIT 100
  316.                 WEND
  317.             END IF
  318.  
  319.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  320.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  321.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  322.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  323.                     EXIT DO 'escape plan for mouse click top right corner of display box
  324.                 ELSE 'PgUp bar clicked
  325.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  326.                 END IF
  327.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  328.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  329.             END IF
  330.         ELSE '   mouse over highlighting, only if mouse has moved!
  331.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  332.                 IF mx <> lastMX OR my <> lastMY THEN
  333.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  334.                         hlite = my - 1
  335.                         lastMX = mx: lastMY = my
  336.                         GOSUB update
  337.                     END IF
  338.                 END IF
  339.             END IF
  340.         END IF
  341.         _LIMIT 200
  342.     LOOP UNTIL choice >= lba AND choice <= uba
  343.     getArrayItemNumber& = choice
  344.     COLOR fg, bg
  345.     'clear key presses
  346.     _KEYCLEAR
  347.     LOCATE curRow, curCol
  348.     'clear mouse clicks
  349.     mb = _MOUSEBUTTON(1)
  350.     IF mb THEN 'clear it
  351.         WHILE mb 'OK!
  352.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  353.             _LIMIT 100
  354.         WEND
  355.     END IF
  356.     EXIT SUB
  357.  
  358.     'display of array sections and controls on screen
  359.     update:
  360.  
  361.     'fix hlite if it has dropped below last array item
  362.     WHILE hlite + page * maxHeight + lba > uba
  363.         hlite = hlite - 1
  364.     WEND
  365.  
  366.     'main display of array items at page * maxHeight (lines high)
  367.     FOR row = 0 TO maxHeight - 1
  368.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  369.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  370.         index = row + page * maxHeight + lba
  371.         IF index >= lba AND index <= uba THEN
  372.             LOCATE locateRow + row, locateColumn
  373.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  374.         END IF
  375.     NEXT
  376.  
  377.     'make page up and down bars to click, print PgUp / PgDn if available
  378.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  379.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  380.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  381.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  382.     IF page <> INT(uba / maxHeight) THEN
  383.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  384.     END IF
  385.     'make exit sign for mouse click
  386.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  387.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  388.     PRINT " X "
  389.  
  390.     'if a number selection has been started show it's build = b$
  391.     IF LEN(b$) THEN
  392.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  393.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  394.         PRINT b$;
  395.     END IF
  396.     _DISPLAY
  397.     _LIMIT 100
  398.     RETURN
  399.  
Title: Re: Tiny Navigator
Post by: SMcNeill on August 24, 2019, 04:06:15 pm
Sounds like a sub is setting _DISPLAY internally, while the program expects _AUTODISPLAY to be in use.
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 04:29:36 pm
Sounds like a sub is setting _DISPLAY internally, while the program expects _AUTODISPLAY to be in use.

Aha! could be it! but isn't the menu showing OK, but that waits for INPUT... hmm...

I need to get that array display code updated with the Screen State saver sub!

Ken try _AUTODISPLAY in that insert section of changedDirectory GOSUB line 174 and then exit do.

Update: Yep! that fixed it! I just found out I have an MP3 file in QB64 Directory that plays fireworks, maybe you guys do too? It is just as Ken said, info displays fine until run the Change directory code and then nothing shows until there is an input line. And _AUTODISPLAY at line 174 fixed it.

Thanks Steve! saved me some time reworking code.

Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 04:36:13 pm
ROFL WE DID IT!!!!!!!!!!!!!!! LOLOLOL Thanks Steve and B+! I added it right before it RETURN's back to the main menu and it's perfect now. I was almost getting to the point like on the Star Trek II Wrath of Khan when he talks about Kirk (who is this program to me): Khan Noonien Singh: He tasks me. He tasks me, and I shall have him. I'll chase him round the Moons of Nibia and round the Antares Maelstrom and round Perdition's flames before I give him up!

(Edit: I just added one CLS line so it would erase the name of the older song.)

Thanks guys.

Here is the code that works:

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+,  SMcneill, and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in your default temp directory.
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. begin:
  17.     DIM f$(10000)
  18.     record = 0
  19.     rec = 0
  20.     oldp = 0
  21.     p = 0
  22.     CLS
  23.     PRINT: PRINT: PRINT
  24.     PRINT "                Mini MP3 Player"
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                  By Ken G."
  27.     PRINT
  28.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  29.     PRINT: PRINT
  30.     PRINT "            (1) Change Directory"
  31.     PRINT "            (2) Play Song"
  32.     PRINT "            (3) Play Directory"
  33.     PRINT "            (4) Quit"
  34.     PRINT
  35.     PRINT
  36.     INPUT "      ->", a
  37.     IF a = 1 THEN GOSUB changedirectory:
  38.     IF a = 2 THEN GOSUB song:
  39.     IF a = 3 THEN GOSUB playdir:
  40.     IF a = 4 THEN END
  41.  
  42. 'Play One Song Here
  43.  
  44. song:
  45. FILES "*.mp3"
  46. again2:
  47. INPUT "Song: ", song$
  48. IF song$ = "" THEN RETURN
  49. fe% = _FILEEXISTS(song$)
  50. IF fe% <> -1 THEN
  51.     PRINT "Filename doesn't exist."
  52.     PRINT "Try again, or Enter for Menu."
  53.     GOTO again2:
  54. s& = _SNDOPEN(song$)
  55. LOCATE 1, 1: PRINT song$
  56. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  57. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  58. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  59.  
  60.     a$ = INKEY$
  61.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  62.     IF a$ = " " THEN _SNDPAUSE s&
  63.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  64.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  65.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  66.     oldp = p
  67.     p = _SNDGETPOS(s&)
  68.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  69.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  70.  
  71. 'Play Directory Here
  72.  
  73. playdir:
  74. record = 0
  75. rec = 0
  76. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  77. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  78. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  79.     CLOSE #1
  80.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  81.     CLS
  82.     PRINT "No mp3 songs on this folder."
  83.     PRINT
  84.     INPUT "Press Enter to go back to Menu.", menu$
  85.     RETURN
  86.     LINE INPUT #1, file$
  87.     file(record) = file$
  88.     f$(record) = file$
  89.     record = record + 1 'for next loop we needed array higher up to one
  90.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  91. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  92. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  93. ready:
  94. a$ = ""
  95. p = 0
  96. oldp = 0
  97. s& = _SNDOPEN(file(rec))
  98. LOCATE 1, 1: PRINT f$(rec)
  99. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  100. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  101. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  102.     a$ = INKEY$
  103.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  104.     IF a$ = " " THEN _SNDPAUSE s&
  105.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  106.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  107.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  108.     oldp = p
  109.     p = _SNDGETPOS(s&)
  110.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  111.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  112. more:
  113. IF rec = record - 1 THEN RETURN
  114. rec = rec + 1
  115. GOTO ready:
  116. 'OPTION _EXPLICIT
  117. '_TITLE "Tiny Navigator mod orig post with perm tmpfile" 'B+
  118. ' 2019-08-22 orig post at https://www.qb64.org/forum/index.php?topic=1646.msg108682#msg108682
  119. ' 2019-08-23 try fix (to nav all directories) with one place for tmpFile, theory can't write files in some dir's
  120. ' For some reason Windows won't write to a fully pathed file in my user folder???
  121. ' Try testing if dir exists "C:\temp" exists and making one if not, yes! and I can write my temp files there
  122. ' and now I can chDir anywhere!
  123.  
  124. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  125.  
  126. ' Attention!!!  this creates a temp directory "C:\temp", do not run this program if you forbid this.
  127.  
  128. '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  129.  
  130. 'Change Directory Here
  131.  
  132.  
  133. changedirectory:
  134. 'SCREEN _NEWIMAGE(1200, 600, 32)
  135. '_SCREENMOVE 100, 50
  136.  
  137.  
  138. DIM mySelection&, done$
  139.  
  140.     PRINT "Current Directory: " + _CWD$
  141.     REDIM myFiles(0) AS STRING ' >>>>>>>>>>>>>> you could change this name to myDIRs(0)
  142.  
  143.     'loadFA "*.*", myFiles()  ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  144.     loadDIR myFiles() ' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> myFiles to myDIRS()
  145.  
  146.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  147.     CLS
  148.     IF mySelection& <> -1719 THEN
  149.         CHDIR myFiles(mySelection&) ' >>>>>>>>>>>>>>> myFiles(mySelection&) to myDIRS(mySelection&)
  150.     ELSE
  151.         _KEYCLEAR
  152.         EXIT DO
  153.     END IF
  154.     _LIMIT 60
  155. LOOP 'UNTIL done$ <> ""
  156.  
  157.  
  158.  
  159. SUB loadDIR (fa() AS STRING)
  160.     DIM tmpFile AS STRING, Index%, fline$, d$
  161.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  162.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  163.     OPEN tmpFile FOR INPUT AS #1
  164.     Index% = -1
  165.     DO WHILE NOT EOF(1)
  166.         LINE INPUT #1, fline$
  167.         IF INSTR(fline$, "<DIR>") THEN
  168.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  169.             Index% = Index% + 1
  170.             REDIM _PRESERVE fa(Index%)
  171.             fa(Index%) = d$
  172.         END IF
  173.     LOOP
  174.     CLOSE #1
  175.     KILL tmpFile
  176.  
  177. FUNCTION rightOf$ (source$, of$)
  178.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  179.  
  180. 'attempting use this 4 things (2018-12-30)
  181. ' 1. expects HELP sub that uses message and message box but easy to comment out
  182. ' 2. expects to be in graphics mode
  183. ' 3. chages color of screen
  184. ' 4. needs _KEYCLEAR 2 before calling of previous keyhits will interfere!!!
  185. '
  186. ' Future Help Message Box for the function.
  187. ' "*** Mouse and Key Instructions ***"
  188. '
  189. ' "Mouse, mouse wheel, and arrow keys should work as expected for item selection."
  190. ' "Press spacebar to select a highlighted item or just click it."
  191. ' "Use number(s) + enter to select an array item by it's index number,"
  192. ' "backspace will remove last number pressed, c will clear a number started."
  193. ' "Numbers started are shown in bottom right PgDn bar."
  194. ' "Enter will also select the highlighted item, if no number has been started."
  195. ' "Home starts you at lowest array index, End highlights then highest index."
  196. ' "Use PgUp and PgDn keys to flip through pages of array items."
  197. '
  198. ' "Escape returns -1719 to allow a Cancel function and signal no slection."
  199. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  200.     'Notes: locateRow, locateColumn for top right corner of selection box on screen in characters for LOCATE.
  201.     'boxWidth and boxHeight are in character units, again for locate and print at correct places.
  202.     'All displaying is restricted to inside the box, which has PgUP and PgDn as top and bottom lines in the display.
  203.  
  204.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  205.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  206.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  207.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  208.     DIM clrStr AS STRING, b AS STRING
  209.  
  210.     'save old settings to restore at end ofsub
  211.     curRow = CSRLIN
  212.     curCol = POS(0)
  213.     fg = _DEFAULTCOLOR
  214.     bg = _BACKGROUNDCOLOR
  215.     _KEYCLEAR
  216.  
  217.     maxWidth = boxWidth '       number of characters in box
  218.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  219.     lba = LBOUND(arr)
  220.     uba = UBOUND(arr)
  221.     page = 0
  222.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  223.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  224.  
  225.     GOSUB update '              show the beginning of the array items for selection
  226.  
  227.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  228.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  229.  
  230.     DO 'until get a selection or demand exit
  231.  
  232.         'handle the key stuff
  233.         kh& = _KEYHIT
  234.         IF kh& THEN
  235.             IF kh& > 0 AND kh& < 255 THEN
  236.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  237.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  238.  
  239.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  240.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  241.                     IF LEN(b$) THEN
  242.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  243.                             choice = VAL(b$): EXIT DO
  244.                         ELSE 'clear b$ to show some response to enter
  245.                             b$ = "": GOSUB update 'clear the value that doesn't work
  246.                         END IF
  247.                     ELSE
  248.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  249.                     END IF
  250.                 END IF
  251.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  252.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  253.                 IF kh& = 8 THEN 'backspace to edit number
  254.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  255.                 END IF
  256.             ELSE
  257.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  258.                     CASE 20736 'pg dn
  259.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  260.                     CASE 18688 'pg up
  261.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  262.                     CASE 18432 'up
  263.                         IF hlite - 1 < 0 THEN
  264.                             IF page > 0 THEN
  265.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  266.                             END IF
  267.                         ELSE
  268.                             hlite = hlite - 1: GOSUB update
  269.                         END IF
  270.                     CASE 20480 'down
  271.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  272.                             IF hlite + 1 > maxHeight - 1 THEN
  273.                                 page = page + 1: hlite = 0: GOSUB update
  274.                             ELSE
  275.                                 hlite = hlite + 1: GOSUB update
  276.                             END IF
  277.                         END IF
  278.                     CASE 18176 'home
  279.                         page = 0: hlite = 0: GOSUB update
  280.                     CASE 20224 ' end
  281.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  282.                 END SELECT
  283.             END IF
  284.         END IF
  285.  
  286.         'handle the mouse stuff
  287.         WHILE _MOUSEINPUT
  288.             IF _MOUSEWHEEL = -1 THEN 'up?
  289.                 IF hlite - 1 < 0 THEN
  290.                     IF page > 0 THEN
  291.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  292.                     END IF
  293.                 ELSE
  294.                     hlite = hlite - 1: GOSUB update
  295.                 END IF
  296.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  297.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  298.                     IF hlite + 1 > maxHeight - 1 THEN
  299.                         page = page + 1: hlite = 0: GOSUB update
  300.                     ELSE
  301.                         hlite = hlite + 1: GOSUB update
  302.                     END IF
  303.                 END IF
  304.             END IF
  305.         WEND
  306.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  307.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  308.             'clear mouse clicks
  309.             mb = _MOUSEBUTTON(1)
  310.             IF mb THEN 'clear it
  311.                 WHILE mb 'OK!
  312.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  313.                     _LIMIT 100
  314.                 WEND
  315.             END IF
  316.  
  317.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  318.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  319.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  320.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  321.                     EXIT DO 'escape plan for mouse click top right corner of display box
  322.                 ELSE 'PgUp bar clicked
  323.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  324.                 END IF
  325.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  326.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  327.             END IF
  328.         ELSE '   mouse over highlighting, only if mouse has moved!
  329.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  330.                 IF mx <> lastMX OR my <> lastMY THEN
  331.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  332.                         hlite = my - 1
  333.                         lastMX = mx: lastMY = my
  334.                         GOSUB update
  335.                     END IF
  336.                 END IF
  337.             END IF
  338.         END IF
  339.         _LIMIT 200
  340.     LOOP UNTIL choice >= lba AND choice <= uba
  341.     getArrayItemNumber& = choice
  342.     COLOR fg, bg
  343.     'clear key presses
  344.     _KEYCLEAR
  345.     LOCATE curRow, curCol
  346.     'clear mouse clicks
  347.     mb = _MOUSEBUTTON(1)
  348.     IF mb THEN 'clear it
  349.         WHILE mb 'OK!
  350.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  351.             _LIMIT 100
  352.         WEND
  353.     END IF
  354.     EXIT SUB
  355.  
  356.     'display of array sections and controls on screen
  357.     update:
  358.  
  359.     'fix hlite if it has dropped below last array item
  360.     WHILE hlite + page * maxHeight + lba > uba
  361.         hlite = hlite - 1
  362.     WEND
  363.  
  364.     'main display of array items at page * maxHeight (lines high)
  365.     FOR row = 0 TO maxHeight - 1
  366.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  367.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  368.         index = row + page * maxHeight + lba
  369.         IF index >= lba AND index <= uba THEN
  370.             LOCATE locateRow + row, locateColumn
  371.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  372.         END IF
  373.     NEXT
  374.  
  375.     'make page up and down bars to click, print PgUp / PgDn if available
  376.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  377.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  378.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  379.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  380.     IF page <> INT(uba / maxHeight) THEN
  381.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  382.     END IF
  383.     'make exit sign for mouse click
  384.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  385.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  386.     PRINT " X "
  387.  
  388.     'if a number selection has been started show it's build = b$
  389.     IF LEN(b$) THEN
  390.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  391.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  392.         PRINT b$;
  393.     END IF
  394.     _DISPLAY
  395.     _LIMIT 100
  396.     RETURN
  397.  
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 05:32:51 pm
It's too bad we can't use the Windows Default Music Directory with this. I tried adding it just now to my music program just with a couple lines to switch to it, which it did. But I then used the selection to change it again with your folder menu to go deeper to play music in it, but the subscript was out of range. I found out how to switch to it from a Wiki example. I have no idea why it wouldn't work with your folder changer once you are in it. I don't use the Windows Default Music Directory myself but just thought it would be good for people that did.
Here is the Wiki example:
http://www.qb64.org/wiki/DIR$ (http://www.qb64.org/wiki/DIR$)

The subscript is out of range on this line:
 CHDIR myFiles(mySelection&)
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 05:50:48 pm
Nice find Ken! I did not know of this command.

Try chdir to that directory first in the start of your code, the navigator code has to be in the directory to get more directory info to move around from where it is.

BTW I found a spot in my hard drive that has neither a dot directory nor a .. go up directory, hp is hole navigator can fall into and not be able to get out, no ..


Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 05:55:04 pm
Yes, that's what I did. I made Default Music Directory part of my main menu. So I went there first, then after it changed to the Default Music Directory, it automatically went back to the main menu so then I went to your directory changing selection to go deeper inside of it. When I did it, it showed the deeper folder, and I went to it, but  when I closed it with your X, is when I got that error and the program closed. The error is this:
The subscript is out of range on this line:
 CHDIR myFiles(mySelection&)
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 05:58:53 pm
The code is very simple to change to the Default Music Directory. It's just this:

Code: QB64: [Select]
  1.  
  2. defaultdir:
  3. CHDIR _DIR$("music")
  4.  
  5.  
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 06:10:18 pm
Hi Ken,

Short on time I just put this line:
CHDIR _DIR$("music") 

Right after, we set tmpDir, and it seems OK to me, a quick test exiting by clicking X. I will test more after supper...
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 06:19:04 pm
It works fine when you don't click any folders inside your menu. Put a test folder inside of your default music folder and click that. Then click the X and see if you are getting the same error I am.
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 07:46:52 pm
Hi Ken, I am not able to replicate your error
  [ This attachment cannot be displayed inline in 'Print Page' view ]  
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 08:01:27 pm
Did you click the X or press Esc? Pressing Esc seems to work for some odd reason.
This also brings me back to something you offered me to change earlier, which I didn't do. You said to change myFiles to myFolders right? I didn't do it though but I wonder if that makes any difference? The reason I didn't do it is because it was already fixed by the time I saw your advice on the code.
Also, just so you know, the mouse's wheel never worked on the menu, I always have to press the top or bottom to scroll up or down. I don't know if you ever got that working yet.
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 08:26:17 pm
WOW! I fixed it! LOL! I will test it a couple more times but I think I found the problem. Every computer uses _LIMIT 100 probably a tiny bit differently. I commented out _LIMIT 100 on 2 of yours toward the bottom of your code (and the program). In my experience of working with the _LIMIT command is that when my computers gets around 100, the program slows down dramatically. Sometimes it takes to _LIMIT 50. But this is why I try to not keep it under _LIMIT 200 unless I need something to run very slow. So far I've tested my program and so far it's fixed! Thank you again for the help B+! :)
Now to decide if I want to move my tons of music from its own folder to the Windows Default Music folder lol. I probably should also make that the starting folder of the program as well. I think I will.
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 08:53:00 pm
Here is my Music Player code that's fixed. I also had to fix the 1 song selection, it had an error when there were no .mp3 files in the directory. So I just changed it to FILES and not FILES *.mp3
I might change that section sometime but as for today, this is my finished version. :)
This version starts out in the Windows Default Music Folder and lets you use B+'s directory selector to choose which one you want to listen to. It also lets you come back to the Windows Default Music Folder if you leave it.

Code: QB64: [Select]
  1. 'This program was made on August 23, 2019 by Ken G. with lots of help by B+, SMcneill, and Petr from the QB64.org forum.
  2. 'This program makes 2 temporary files called MyMusicFiles.temp and DIR$INF0.INF in your default temp directory.
  3. 'If for some reason these files exist after this program is shut down, you are free to delete them.
  4.  
  5. _TITLE "Mini MP3 Player"
  6. SCREEN _NEWIMAGE(400, 400, 32)
  7. DIM SHARED tmpDir AS STRING '  establish a permanent spot for temp files
  8. IF ENVIRON$("TEMP") <> "" THEN 'Thanks to Steve McNeill use user temp files directory
  9.     tmpDir = ENVIRON$("TEMP")
  10. ELSEIF ENVIRON$("TMP") <> "" THEN
  11.     tmpDir = ENVIRON$("TMP")
  12. ELSE 'Thanks to Steve McNeill this should be very unlikely
  13.     IF _DIREXISTS("C:\temp") THEN ELSE MKDIR "C:\temp"
  14.     tmpDir = "C:\temp"
  15.  
  16. GOSUB defaultdir: 'Set default folder to Windows Music Default Folder
  17.  
  18. begin:
  19.     DIM f$(10000)
  20.     record = 0
  21.     rec = 0
  22.     oldp = 0
  23.     p = 0
  24.     CLS
  25.     PRINT: PRINT: PRINT
  26.     PRINT "                Mini MP3 Player"
  27.     PRINT: PRINT: PRINT
  28.     PRINT "                  By Ken G."
  29.     PRINT
  30.     LOCATE 11, 1: PRINT "Directory: "; _CWD$
  31.     PRINT: PRINT
  32.     PRINT "(1) Change Directory"
  33.     PRINT "(2) Change Back To Windows Default Music Directory"
  34.     PRINT "(3) Play Entire Directory"
  35.     PRINT "(4) Play One Song"
  36.     PRINT "(5) Quit"
  37.     PRINT
  38.     PRINT
  39.     INPUT "->", a
  40.     IF a = 1 THEN GOSUB changedirectory:
  41.     IF a = 2 THEN GOSUB defaultdir:
  42.     IF a = 3 THEN GOSUB playdir:
  43.     IF a = 4 THEN GOSUB song:
  44.     IF a = 5 THEN END
  45.  
  46. defaultdir:
  47. CHDIR _DIR$("music")
  48.  
  49. 'Play One Song Here
  50.  
  51. song:
  52. again2:
  53. PRINT "Press only Enter to go back to Menu."
  54. INPUT "Song Name: ", song$
  55. IF song$ = "" THEN RETURN
  56. fe% = _FILEEXISTS(song$)
  57. IF fe% <> -1 THEN
  58.     PRINT "Filename doesn't exist."
  59.     PRINT "Try again, or Enter for Menu."
  60.     GOTO again2:
  61. s& = _SNDOPEN(song$)
  62. LOCATE 1, 1: PRINT song$
  63. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  64. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  65. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (S)top (M)enu"
  66.  
  67.     a$ = INKEY$
  68.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  69.     IF a$ = " " THEN _SNDPAUSE s&
  70.     IF a$ = "S" OR a$ = "s" THEN _SNDSTOP s&
  71.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  72.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: RETURN
  73.     oldp = p
  74.     p = _SNDGETPOS(s&)
  75.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  76.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN RETURN
  77.  
  78. 'Play Directory Here
  79.  
  80. playdir:
  81. record = 0
  82. rec = 0
  83. REDIM file(0) AS STRING 'create empty text array. 0 is record nr. 1!
  84. SHELL _HIDE "dir *.mp3 /B > " + tmpDir + "\MyMusicFiles.temp" 'create mp3 files list.
  85. OPEN tmpDir + "\MyMusicFiles.temp" FOR INPUT AS #1
  86.     CLOSE #1
  87.     SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  88.     CLS
  89.     PRINT "No mp3 songs on this folder."
  90.     PRINT
  91.     INPUT "Press Enter to go back to Menu.", menu$
  92.     RETURN
  93.     LINE INPUT #1, file$
  94.     file(record) = file$
  95.     f$(record) = file$
  96.     record = record + 1 'for next loop we needed array higher up to one
  97.     REDIM _PRESERVE file(record) AS STRING 'this do array bigger without deleting content
  98. SHELL _HIDE "DEL " + tmpDir + "\MyMusicFiles.temp"
  99. 'so now file(0) is first file from disk. file(3) is 4th file from disk. Try it:
  100. ready:
  101. a$ = ""
  102. p = 0
  103. oldp = 0
  104. s& = _SNDOPEN(file(rec))
  105. LOCATE 1, 1: PRINT f$(rec)
  106. LOCATE 2, 1: PRINT "Sound Rate: "; _SNDRATE
  107. LOCATE 4, 1: PRINT "Length: "; INT(_SNDLEN(s&))
  108. LOCATE 6, 1: PRINT "Space Bar = Pause (P)lay (N)ext Song (M)enu"
  109.     a$ = INKEY$
  110.     IF a$ = CHR$(27) THEN _SNDSTOP s&: END
  111.     IF a$ = " " THEN _SNDPAUSE s&
  112.     IF a$ = "N" OR a$ = "n" THEN _SNDSTOP s&
  113.     IF a$ = "P" OR a$ = "p" THEN _SNDPLAY s&
  114.     IF a$ = "M" OR a$ = "m" THEN _SNDSTOP s&: rec = 0: RETURN
  115.     oldp = p
  116.     p = _SNDGETPOS(s&)
  117.     LOCATE 3, 1: PRINT "Position: "; INT(p)
  118.     IF INT(oldp) > INT(p) AND INT(p) = 0 THEN EXIT DO
  119. more:
  120. IF rec = record - 1 THEN RETURN
  121. rec = rec + 1
  122. GOTO ready:
  123.  
  124.  
  125. 'Change Directory Here
  126.  
  127.  
  128. changedirectory:
  129.  
  130.  
  131. DIM mySelection&
  132.  
  133.  
  134.     PRINT "Current Directory: " + _CWD$
  135.     REDIM myFiles(0) AS STRING
  136.  
  137.     loadDIR myFiles()
  138.  
  139.     mySelection& = getArrayItemNumber&(5, 2, 48, 20, myFiles())
  140.     CLS
  141.     IF mySelection& <> -1719 THEN
  142.         CHDIR myFiles(mySelection&)
  143.     ELSE
  144.         _KEYCLEAR
  145.         EXIT DO
  146.     END IF
  147.     _LIMIT 60
  148.  
  149.  
  150.  
  151. SUB loadDIR (fa() AS STRING)
  152.     DIM tmpFile AS STRING, Index%, fline$, d$
  153.     tmpFile = tmpDir + "\DIR$INF0.INF" 'aha!, not a fully pathed file to user directory but here is good!
  154.     SHELL _HIDE "DIR /a:d >" + tmpFile 'get directories  but have to do a little pruning
  155.     OPEN tmpFile FOR INPUT AS #1
  156.     Index% = -1
  157.     DO WHILE NOT EOF(1)
  158.         LINE INPUT #1, fline$
  159.         IF INSTR(fline$, "<DIR>") THEN
  160.             d$ = _TRIM$(rightOf$(fline$, "<DIR>"))
  161.             Index% = Index% + 1
  162.             REDIM _PRESERVE fa(Index%)
  163.             fa(Index%) = d$
  164.         END IF
  165.     LOOP
  166.     CLOSE #1
  167.     KILL tmpFile
  168.  
  169. FUNCTION rightOf$ (source$, of$)
  170.     IF INSTR(source$, of$) > 0 THEN rightOf$ = MID$(source$, INSTR(source$, of$) + LEN(of$))
  171.  
  172.  
  173. FUNCTION getArrayItemNumber& (locateRow, locateColumn, boxWidth, boxHeight, arr() AS STRING)
  174.  
  175.     DIM curRow AS INTEGER, curCol AS INTEGER, fg AS _UNSIGNED LONG, bg AS _UNSIGNED LONG
  176.     DIM maxWidth AS INTEGER, maxHeight AS INTEGER, page AS INTEGER, hlite AS INTEGER, mx AS INTEGER, my AS INTEGER
  177.     DIM lastMX AS INTEGER, lastMY AS INTEGER, row AS INTEGER, mb AS INTEGER
  178.     DIM lba AS LONG, uba AS LONG, choice AS LONG, kh AS LONG, index AS LONG
  179.     DIM clrStr AS STRING, b AS STRING
  180.  
  181.     'save old settings to restore at end ofsub
  182.     curRow = CSRLIN
  183.     curCol = POS(0)
  184.     fg = _DEFAULTCOLOR
  185.     bg = _BACKGROUNDCOLOR
  186.     _KEYCLEAR
  187.  
  188.     maxWidth = boxWidth '       number of characters in box
  189.     maxHeight = boxHeight - 2 ' number of lines displayed of array at one time = 1 page
  190.     lba = LBOUND(arr)
  191.     uba = UBOUND(arr)
  192.     page = 0
  193.     hlite = 0 '                 line in display ready for selection by spacebar or if no number is started, enter
  194.     clrStr$ = SPACE$(maxWidth) 'clearing a display line
  195.  
  196.     GOSUB update '              show the beginning of the array items for selection
  197.  
  198.     'signal cancel selection process, exit sub with this unlikely index to signal canel
  199.     choice = -1719 'primes 7 and 8, not likely to be a select index of an array
  200.  
  201.     DO 'until get a selection or demand exit
  202.  
  203.         'handle the key stuff
  204.         kh& = _KEYHIT
  205.         IF kh& THEN
  206.             IF kh& > 0 AND kh& < 255 THEN
  207.                 IF INSTR("0123456789", CHR$(kh&)) > 0 THEN b$ = b$ + CHR$(kh&): GOSUB update
  208.                 'IF CHR$(kh&) = "h" THEN HELP: _KEYCLEAR
  209.  
  210.                 IF CHR$(kh&) = "c" THEN b$ = "": GOSUB update
  211.                 IF kh& = 13 THEN 'enter pressed check if number is being entered?
  212.                     IF LEN(b$) THEN
  213.                         IF VAL(b$) >= lba AND VAL(b$) <= uba THEN 'we have number started
  214.                             choice = VAL(b$): EXIT DO
  215.                         ELSE 'clear b$ to show some response to enter
  216.                             b$ = "": GOSUB update 'clear the value that doesn't work
  217.                         END IF
  218.                     ELSE
  219.                         choice = hlite + page * maxHeight + lba 'must mean to select the highlighted item
  220.                     END IF
  221.                 END IF
  222.                 IF kh& = 27 THEN EXIT DO 'escape clause offered to Cancel selection process
  223.                 IF kh& = 32 THEN choice = hlite + page * maxHeight + lba 'best way to choose highlighted selection
  224.                 IF kh& = 8 THEN 'backspace to edit number
  225.                     IF LEN(b$) THEN b$ = LEFT$(b$, LEN(b$) - 1): GOSUB update
  226.                 END IF
  227.             ELSE
  228.                 SELECT CASE kh& 'choosing sections of array to display and highlighted item
  229.                     CASE 20736 'pg dn
  230.                         IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  231.                     CASE 18688 'pg up
  232.                         IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  233.                     CASE 18432 'up
  234.                         IF hlite - 1 < 0 THEN
  235.                             IF page > 0 THEN
  236.                                 page = page - 1: hlite = maxHeight - 1: GOSUB update
  237.                             END IF
  238.                         ELSE
  239.                             hlite = hlite - 1: GOSUB update
  240.                         END IF
  241.                     CASE 20480 'down
  242.                         IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  243.                             IF hlite + 1 > maxHeight - 1 THEN
  244.                                 page = page + 1: hlite = 0: GOSUB update
  245.                             ELSE
  246.                                 hlite = hlite + 1: GOSUB update
  247.                             END IF
  248.                         END IF
  249.                     CASE 18176 'home
  250.                         page = 0: hlite = 0: GOSUB update
  251.                     CASE 20224 ' end
  252.                         page = INT((uba - lba) / maxHeight): hlite = maxHeight - 1: GOSUB update
  253.                 END SELECT
  254.             END IF
  255.         END IF
  256.  
  257.         'handle the mouse stuff
  258.         WHILE _MOUSEINPUT
  259.             IF _MOUSEWHEEL = -1 THEN 'up?
  260.                 IF hlite - 1 < 0 THEN
  261.                     IF page > 0 THEN
  262.                         page = page - 1: hlite = maxHeight - 1: GOSUB update
  263.                     END IF
  264.                 ELSE
  265.                     hlite = hlite - 1: GOSUB update
  266.                 END IF
  267.             ELSEIF _MOUSEWHEEL = 1 THEN 'down?
  268.                 IF (hlite + 1) + page * maxHeight + lba <= uba THEN 'ok to move up
  269.                     IF hlite + 1 > maxHeight - 1 THEN
  270.                         page = page + 1: hlite = 0: GOSUB update
  271.                     ELSE
  272.                         hlite = hlite + 1: GOSUB update
  273.                     END IF
  274.                 END IF
  275.             END IF
  276.         WEND
  277.         mx = INT((_MOUSEX - locateColumn * 8) / 8) + 2: my = INT((_MOUSEY - locateRow * 16) / 16) + 2
  278.         IF _MOUSEBUTTON(1) THEN 'click contols or select array item
  279.             'clear mouse clicks
  280.             mb = _MOUSEBUTTON(1)
  281.             IF mb THEN 'clear it
  282.                 WHILE mb 'OK!
  283.                     IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  284.                     _LIMIT 100
  285.                 WEND
  286.             END IF
  287.  
  288.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  289.                 choice = my + page * maxHeight + lba - 1 'select item clicked
  290.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = 0 THEN 'page up or exit
  291.                 IF my = 0 AND (mx <= maxWidth AND mx >= maxWidth - 2) THEN 'exit sign
  292.                     EXIT DO 'escape plan for mouse click top right corner of display box
  293.                 ELSE 'PgUp bar clicked
  294.                     IF (page - 1) * maxHeight + lba >= lba THEN page = page - 1: GOSUB update
  295.                 END IF
  296.             ELSEIF mx >= 1 AND mx <= maxWidth AND my = maxHeight + 1 THEN 'page down bar clicked
  297.                 IF (page + 1) * maxHeight + lba <= uba THEN page = page + 1: GOSUB update
  298.             END IF
  299.         ELSE '   mouse over highlighting, only if mouse has moved!
  300.             IF mx >= 1 AND mx <= maxWidth AND my >= 1 AND my <= maxHeight THEN
  301.                 IF mx <> lastMX OR my <> lastMY THEN
  302.                     IF my - 1 <> hlite AND (my - 1 + page * maxHeight + lba <= uba) THEN
  303.                         hlite = my - 1
  304.                         lastMX = mx: lastMY = my
  305.                         GOSUB update
  306.                     END IF
  307.                 END IF
  308.             END IF
  309.         END IF
  310.         _LIMIT 200
  311.     LOOP UNTIL choice >= lba AND choice <= uba
  312.     getArrayItemNumber& = choice
  313.     COLOR fg, bg
  314.     'clear key presses
  315.     _KEYCLEAR
  316.     LOCATE curRow, curCol
  317.     'clear mouse clicks
  318.     mb = _MOUSEBUTTON(1)
  319.     IF mb THEN 'clear it
  320.         WHILE mb 'OK!
  321.             IF _MOUSEINPUT THEN mb = _MOUSEBUTTON(1)
  322.             '_LIMIT 100
  323.         WEND
  324.     END IF
  325.     EXIT SUB
  326.  
  327.     'display of array sections and controls on screen
  328.     update:
  329.  
  330.     'fix hlite if it has dropped below last array item
  331.     WHILE hlite + page * maxHeight + lba > uba
  332.         hlite = hlite - 1
  333.     WEND
  334.  
  335.     'main display of array items at page * maxHeight (lines high)
  336.     FOR row = 0 TO maxHeight - 1
  337.         IF hlite = row THEN COLOR _RGB(200, 200, 255), _RGB32(0, 0, 88) ELSE COLOR _RGB32(0, 0, 88), _RGB(200, 200, 255)
  338.         LOCATE locateRow + row, locateColumn: PRINT clrStr$
  339.         index = row + page * maxHeight + lba
  340.         IF index >= lba AND index <= uba THEN
  341.             LOCATE locateRow + row, locateColumn
  342.             PRINT LEFT$(LTRIM$(STR$(index)) + ") " + arr(index), maxWidth)
  343.         END IF
  344.     NEXT
  345.  
  346.     'make page up and down bars to click, print PgUp / PgDn if available
  347.     COLOR _RGB32(200, 200, 255), _RGB32(0, 100, 50)
  348.     LOCATE locateRow - 1, locateColumn: PRINT SPACE$(maxWidth)
  349.     IF page <> 0 THEN LOCATE locateRow - 1, locateColumn: PRINT LEFT$(" Pg Up" + SPACE$(maxWidth), maxWidth)
  350.     LOCATE locateRow + maxHeight, locateColumn: PRINT SPACE$(maxWidth)
  351.     IF page <> INT(uba / maxHeight) THEN
  352.         LOCATE locateRow + maxHeight, locateColumn: PRINT LEFT$(" Pg Dn" + SPACE$(maxWidth), maxWidth)
  353.     END IF
  354.     'make exit sign for mouse click
  355.     COLOR _RGB32(255, 255, 255), _RGB32(200, 100, 0)
  356.     LOCATE locateRow - 1, locateColumn + maxWidth - 3
  357.     PRINT " X "
  358.  
  359.     'if a number selection has been started show it's build = b$
  360.     IF LEN(b$) THEN
  361.         COLOR _RGB(255, 255, 0), _RGB32(0, 0, 0)
  362.         LOCATE locateRow + maxHeight, locateColumn + maxWidth - LEN(b$) - 1
  363.         PRINT b$;
  364.     END IF
  365.     _DISPLAY
  366.     '_LIMIT 100
  367.     RETURN
  368.  
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 10:19:04 pm
Did you click the X or press Esc? Pressing Esc seems to work for some odd reason.
This also brings me back to something you offered me to change earlier, which I didn't do. You said to change myFiles to myFolders right? I didn't do it though but I wonder if that makes any difference? The reason I didn't do it is because it was already fixed by the time I saw your advice on the code.
Also, just so you know, the mouse's wheel never worked on the menu, I always have to press the top or bottom to scroll up or down. I don't know if you ever got that working yet.

Quote
This also brings me back to something you offered me to change earlier, which I didn't do. You said to change myFiles to myFolders right?
Not necessary, just trying to call the things DIRs not files.

Quote
Also, just so you know, the mouse's wheel never worked on the menu, I always have to press the top or bottom to scroll up or down. I don't know if you ever got that working yet.
YIKES!!! Man! the scroller is best part! Do you have any clippet's of code where the mouse wheel does work?
Maybe we can figure what's off. I assume the arrow keys and PgUp, PgDn keys work?
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 10:24:38 pm
WOW! I fixed it! LOL! I will test it a couple more times but I think I found the problem. Every computer uses _LIMIT 100 probably a tiny bit differently. I commented out _LIMIT 100 on 2 of yours toward the bottom of your code (and the program). In my experience of working with the _LIMIT command is that when my computers gets around 100, the program slows down dramatically. Sometimes it takes to _LIMIT 50. But this is why I try to not keep it under _LIMIT 200 unless I need something to run very slow. So far I've tested my program and so far it's fixed! Thank you again for the help B+! :)
Now to decide if I want to move my tons of music from its own folder to the Windows Default Music folder lol. I probably should also make that the starting folder of the program as well. I think I will.

_LIMIT just saves your CPU from overheating, it limits a loop to a set amount of loops per second if it is going faster than that. 100 is fast enough to check mouse often enough but saves on fan and CPU if code could run faster, it does nothing if code runs slower per loop.
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 10:36:30 pm
Wow the wheel does work, I guess the times I've tried it I didn't have the program focused right and I needed to click the window somewhere, sorry about that. Also, when I was using the wheel, sometimes it would flip to where the mouse is pointed instead, but only you would know about that. In my experience with 64 bit computers is, or even Windows in general, things can happen that we never know why but they just do. lol
By the way, today is the 24th anniversary of Windows 95. lol
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 10:42:35 pm
Oh I know why I didn't think the mouse wheel wasn't working, I was used to website scrolling and not the way you did it with selection scrolling instead. Website scrolling scrolls the whole window at once, yours only does that when it gets to the bottom of the list, or the top. :)
Title: Re: Tiny Navigator
Post by: SierraKen on August 24, 2019, 10:52:09 pm
I just noticed one little problem with the wheel. The mouse pointer overtakes any menu selection than the wheel has highlighted. For example, if I am using the mouse wheel to highlight the names and come to one called Prince, and the mouse pointer at the same time is over one called Jeff Beck, and I click the mouse button, it will choose Jeff Beck, and not the highlighted one of Prince. This is probably what confused me about the wheel to begin with.
Title: Re: Tiny Navigator
Post by: bplus on August 24, 2019, 10:56:13 pm
Yeah, if the highlite is on one thing and mouse somewhere else, not moving, press space bar or enter to select highlighted thing.