User chooses which file to open - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: User chooses which file to open (/thread-10220.html) |
User chooses which file to open - Licentia - 07-03-2009 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 Re: User chooses which file to open - Clippy - 07-03-2009 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$ <> "" Then open the file: OPEN Filename$ FOR INPUT AS #1 Re: User chooses which file to open - Licentia - 07-03-2009 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$ 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 If it's not possible let me know so I can get on with my life! Thanks! Licentia Re: User chooses which file to open - Clippy - 07-03-2009 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 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. Re: User chooses which file to open - Licentia - 07-04-2009 So it's not an easy fix. Thanks so much for your help! Licentia |