Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MMBasic "Open" cmd
Author | Message | ||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
I'm trying to implement Bryan1's HelpV2 text files on my Maximite using MMBasic V3.1. I have a folder on the SD B: drive called "HELPV2" which contains all of Bryan's .txt files for the different commands and functions and have put a small program called "HELP.BAS" (listed below) in the B: root of the SD drive. When I run HELP.BAS it gets to the "OPEN" command in the file reading/printing subroutine "prntfile (query$)" and then gives an error saying it can't find the file. I've tried all sorts of variations here but can't get it working. Can someone tell me what I'm doing wrong please? Greg Cls Do Line Input "Which command?: ",query$ If query$ = Chr$(27) Then Exit Else Cls: prntfile (query$) EndIf Loop Until query$ = Chr$(27) Print "Return to the original program" End ' Subroutine to open and print the cmd/func file Sub prntfile (filename$) filename$ = "b:\v2help\"+filename$+".txt" Print "filename$ =",filename$ Open filename$ For input As #1 Do Line Input #1 info$ Print info$ Loop Until eof Close #1 End Sub |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
The only thing that I can see is that the line: Line Input #1 info$ Should be: Line Input #1, info$ But that does not sound like your particular problem. Geoff Geoff Graham - http://geoffg.net |
||||
crackerjack Senior Member Joined: 11/07/2011 Location: AustraliaPosts: 164 |
You say you have a folder called "HELPV2" but your program is atrying to access a file in a folder called "V2HELP" - is that it? Also, it would be more efficient to code the main loop as follows: [code] ... Do While query$ <> Chr$(27) Line Input "Which command?: ",query$ Cls: prntfile (query$) Loop ... [/code] Also, just out of interest - how do you enter Character 27 from the keyboard? |
||||
Gadget Regular Member Joined: 22/06/2011 Location: AustraliaPosts: 70 |
character 27 is the standard ascii code for escape, without checking the manual I'd say it is the escape key |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Thanks Geoff and CrackerJack, I've fixed both these but it still throws "Error: Cannot find file" on the open staement. Can't believe I swapped "helpv2" and "v2help" Any other ideas? Greg |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Yes, it's the ESC key Greg |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Thanks for this too - I've "room for improvement" as my teachers used to say! Greg |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
I should have included the new version - which still can't find the file. ------------------- Cls Do While query$ <> Chr$(27) Line Input "which command?: ",query$ Cls: prntfile (query$) Loop ' Subroutine to open and print the cmd/func file Sub prntfile (filename$) filename$ = "b:\helpv2\"+filename$+".txt" Print "filename$ =",filename$ Open filename$ For input As #1 Do Line Input #1, info$ Print info$ Loop Until eof Close #1 End Sub ------------------------ |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
assuming drive B: as the default, I tried this filename$="B:\example.txt"
open filename$ for input as 1 and it fails. If I take out the B: so the program is filename$="\example.txt"
open filename$ for input as 1 that works. The MM Basic Manual V3.1 says in part for the OPEN command Opens a file for reading or writing
‘fname’ is the filename (8 chars max) with an optional extension (3 chars max) separated by a dot (.). It can be prefixed with a directory path. For example: "B:\DIR1\DIR2\FILE.EXT". and so it looks like a bug to me or change the manual. The work around looks like changing to the drive before issuing the command. |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Hi BobD, Excellent, thanks for that, I'll give it a go when I've done a couple of my better half's jobs. I read that in the manual too so maybe Geoff does have a teensy bug. Greg |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Mr Paceman You were a bit stiff with this one, a typo and a real bug both st the same time. I have been advised this was the first report of it and it's on the do list for fixing in V3.2. At least you can easily work around it. Bob |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Hi Bob, Oops, Geoff was very helpful to me yesterday with another issue and now I've given him another hassle! I've changed the directory and by leaving the drive designation off the filename$ build it seems to run. I say seems because it flashes onto the screen what looks like the appropriate queried help file but immediately erases it and hangs. Control comes back OK with cntrl'c' but for some reason the cursor is at the bottom of the screen. Also the CHR$(27) (ESC character) doesn't seem to be working in the main program. Were you suggesting something slightly different for a workaround? Greg Current code: Do While query$ <> Chr$(27) Line Input "Which command or function?: ",query$ prntfile (query$) Loop ' Subroutine to open and print the queried cmd/func help file Sub prntfile (filename$) Cls Chdir "b:\helpv2\" filename$ = "\helpv2\"+filename$+".txt" 'this works but not if b: included 'filename$ = filename$ + ".txt" 'this doesn't work Print "filename$ =",filename$ Open filename$ For input As #1 Do Line Input #1, info$ Print info$ Loop Until eof Close #1 Chdir ".." End Sub |
||||
Bryan1 Guru Joined: 22/02/2006 Location: AustraliaPosts: 1344 |
Hi Paceman, When I first started on the Help file I did in basic but soon found I was running quickly out of program memory and it was suggested to do it in a text based system and Ken took it on to implement it software where on the DM as shown on the main help page changing the 'autorun.bas' file will when F1 is pressed the help file will come up. Also one can simply do help " whatever and if there is a file name name called 'whatever' the screen will blank out and that help file will be shown and what ever program you are working on is kept in program memory. Don also suggested by saving ones own files, code snippets, post it notes etc was also a feature so why Geoff hasn't done this 'help file system' for the MM is beyond me as I did say once I realeased it IS open source and free for users to improve, modify etc. Now I did try that 3.1 on my mega DM and as soon as the help file didnt work I reflashed back to the latest DM firmware. I did spend a great deal of time doing that for my first project so every user either new to this great idea or experienced users could look it up when and if required and for member to improve it. Regards Bryan |
||||
paceman Guru Joined: 07/10/2011 Location: AustraliaPosts: 1329 |
Hi Bryan, Yes I tried out your .BAS based system but decided your new .TXT one was a lot more flexible (editable files, more examples etc.). I'm trying to get it going on my Maximite much the same way you've described i.e. see the description I've included at the start of the code. I didn't include these comments in the previous posts to save space and keep my problem more in focus. ' .............HELP.BAS.............
' Print's Bryan1's help text files. The program is resident ' in the B: drive & launched by pressing the F5 key & typing ' "help". It assumes the .txt files are in a directory ' called HELPV2 on the SD card B: drive & that the command ' OPTION F5 = "RUN "+CHR$(34) has previously been run e.g. ' as by the MMBasic Library AUTORUN program. It should be quick and easy to use this way for Maximite users and the little "HELP.BAS" program is pretty minimal. I thought about unloading and re-loading a program that might have been loaded but it's not necessary when you're using the full-screen editor. All that's needed is to use the editor's F2 key to RUN what you're editing, CTRL'C' back out, then get HELP with the F5 key (the key can be changed to F1 if you want with the OPTION Fx command e.g. in your AUTORUN program) .Typing in EDIT again brings the code you're editing back up. Doing it this way is a simple way of implementing editable help text files using the current MMBasic code so it's not surprising that Geoff hasn't built a special function key command for it - that would probably also mean you couldn't change the key it's assigned to which would limit the OPTION Fx command. He may also have something quite different in mind. Your efforts getting all the text files organised is appreciated I assume by everyone. This little program will just make them easier to access for the Maximite users if they haven't already done it for themselves. Best Regards, Greg |
||||
Print this page |