Hello!
(NOTE: If this isn't possible to do please someone post and let me know so I don't wait forever. Thanks so much!)
Sorry I am sure this should be an easy answer but I am Googling to no avail. Instead of the normal command:
OPEN "FILE.TXT" FOR INPUT AS #1
I want to be able to have the user choose which file to open. I think this is possible and I have probably done it in the past, but I haven't done much programming for several years now. The consequence is I have forgotten how.
Any help would be appreciated!
Licentia
Sure just use a string variable like FileName$ in the open statement instead of a literal value.
Create a menu display for the user and use SELECT CASE:
Code:
DO: choice$ = INKEY$ : LOOP UNTIL choice$ <> ""
SELECT CASE choice$
    CASE "1": Filename$ = "ABCD.txt"
    CASE "2": Filename$ = "EFGH.txt"
END SELECT
Then open the file: OPEN Filename$ FOR INPUT AS #1
Thanks for your speedy response!
Sorry that I am not more clear about what I am trying to do. I don't want the user to choose from a list of options. I want the user to select any file they want as long as it's in the same file folder on the computer as the program is located.
You know, I can compile the program and put it in any folder on my computer (run it in DosBox on Ubuntu Linux), and then put a text file in that same folder and the program will open that text file. This way people can name the text file whatever they want.
PS: I found this bit of code online, and I don't like it:
Code:
INPUT "CHOOSE THE FILE YOU NEED", FILE$
Rem   CLS
     FILE$ = "c:\data\" + FILE$ + ".PRF"
     Open FILE$ For Input As #3
I hope it's not saying that I need to pre-select a location for any file that I input as this isn't going to happen in Ubuntu. Unless DosBox somehow assigns a default location?
Is there not a simple way to have QB just check for files in the same location that it is in without having to specify?
I tried this code here but it won't work:
Code:
DO
DO
 PRINT " Please enter the name of the file you are working with."
 PRINT ""
 INPUT FILE.CHOICE$
 PRINT ""
 PRINT " Did you type the file name correctly? Choose 'Y' or 'N'."
 PRINT ""
 INPUT OPTION.3$
LOOP UNTIL OPTION.3$ = "Y" OR OPTION.3$ = "y" OR OPTION.3$ = "N" OR OPTION.3$ = "n"
PRINT ""
PRINT " If the file name is correct, type 'correct'."
PRINT ""
INPUT OPTION.3$
LOOP UNTIL OPTION.3$ = "CORRECT" OR OPTION.3$ = "Correct" OR OPTION.3$ = "correct"
 OPEN FILE.CHOICE$ FOR INPUT AS #1
If it's not possible let me know so I can get on with my life!
Thanks!
Licentia
FILES "*.BAS" would work, but it may scroll too fast to read all of the names.
The following pipes folder file information in DOS to a file. Then you can print them page by page. If you added a mouse and place the names into an array the user can click on them as each page is formatted the same way:
Code:
SCREEN 12 '80 X 30 text
SHELL "DIR *.BAS /B > BASLIST.DIR"Â '/B = pipe without file information. Filenames only!
OPEN "BASLIST.DIR" FOR INPUT AS #1
COLOR 11: LOCATE 3, 2
IF LOF(1) THEN
 Fcount = 0 'number of files found
 DO WHILE NOT EOF(1)
  Fcount = Fcount + 1
  LINE INPUT #1, FileN$
  PRINT FileN$; SPACE$(13 - LEN(FileN$));   'max DOS filename is 12 characters
  IF Fcount MOD 6 = 0 THEN PRINT : LOCATE , 2 'new line
  IF Fcount MOD 156 = 0 THEN          'next screen
   COLOR 14: LOCATE 29, 25: PRINT "Press any key to continue!";
   DO: SLEEP: LOOP UNTIL INKEY$ <> ""
   CLS : COLOR 11: LOCATE 3, 2
  END IF
 LOOP
 CLOSE #1
ELSE : COLOR 12: LOCATE 15, 20: PRINT "NO Files Found!"
END IF
PRINT " ";
COLOR 10: LOCATE , 2: PRINT SPACE$(30); "Total Files ="; Fcount;
SYSTEM
The file is updated each run. Then you can check the files to see if they are empty with LOF() before trying to INPUT #. Reduces INPUT # errors.
So it's not an easy fix.
Thanks so much for your help!
Licentia