Author |
Message |
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
Posted: 08:13pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Hi folks.
I am doing something wrong here, but can't see where:
Dim A$(100)
Dim Q$(1)
Open "B:\eeprom.txt" For input As #1
start:
Cls
For x=1 To 20
Line Input #1, A$
Print A$
Next x
Input "SHOW MORE"; Q$
Print Q$
If Q$="Y" Or Q$="y" Then GoTo start
End
This code just reads from a text file, and then prompts the user to press a key, and it shows more. This is just some very simple code I am playing with, to teach myself some MM code.
First page of text loads from the file and shows on the screen great, but whenever I type Y or y for YES, the program stops. I can understand this, as Q=0, but it should be either 89 for Y or 121 for y.
In other words, if the input from the keyboard is NOT Y or y, it will stop, but if it IS Y or y, it will clear the screen and show another page of text, which is not happening.
If I press Y or y, the program just exits.
I am obviously doing something wrong - can someone give me a hint please?
MM BASIC Manual, page 23 indicates that this should be working.
EDIT: Hang on a tick - a variable is a number, not a letter, so I probably need to make that Q$ - I will try and post back...
ANOTHER EDIT: YES! I have to make that a string - I have also updated the code window above.
YAY!
I think I now understand that if you have INPUT Q, and I type "1" then "2" then "3", Q will return as the number 123 - just a nice easy way of getting numbers back from the keyboard.Edited by Grogster 2013-01-16 Smoke makes things work. When the smoke gets out, it stops! |
|
BobD
Guru
Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Posted: 09:09pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
You could also try the following. It allows only pressing the y or Y key with no need for a CR. If you are paging through lots of data it saves effort.
Print "SHOW MORE?"
do
K$=Inkey$
Loop Until K$ <> ""
K$=Lcase$(K$)
If K$="y" then goto start
|
|
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
Posted: 09:21pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Lovely.
From what I can see, this loop just keep checking the keyboard input buffer until there is something there, then checks, and if it is a "y" then goes to start immediately.
I don't really follow the K$=Lcase$(K$) line - can you elaborate?
Smoke makes things work. When the smoke gets out, it stops! |
|
djuqa
Guru
Joined: 23/11/2011 Location: AustraliaPosts: 447 |
Posted: 09:35pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Lcase$ converts the input parameter to lowercase
so both "Y" and "y" are returned as "y: so you then only have to check for "y" VK4MU MicroController Units
|
|
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
Posted: 09:36pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Ahhhh - I see - thanks. Smoke makes things work. When the smoke gets out, it stops! |
|
MicroBlocks
Guru
Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Posted: 10:52pm 14 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Another way to check it only once:
if instr("Yy",K$) > 0 then
If you want to have some fun learning mmbasic try to change your code so that pressing the Y key twice will not show two pages very quickly.
Also good practice is to make it such that pressing the spacebar will show the next full page, the enter key shows the next line and ESC stops the program.
Have fun!
Microblocks. Build with logic. |
|
BobD
Guru
Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Posted: 05:31am 15 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Now having a bit more time to think about your code (I already had the call to dinner when I wrote the previous) you might consider writing your code like this. It also includes TZA's idea of double presses of the Y key. As you can see I'm a fan of DO loops.
start:
Do
Cls
For x=1 To 20
Line Input #1, A$
Print A$
Next x
'clear the keyboard buffer
Do
K$=Inkey$
Loop Until K$ = ""
Print "SHOW MORE?"
'get a key press
Do
K$=Inkey$
Loop Until K$ <> ""
K$=Lcase$(K$)
Loop Until K$ <> "y"
End
|
|
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
Posted: 01:21pm 15 Jan 2013 |
Copy link to clipboard |
Print this post |
|
Great. Thanks for the code examples, guys - I will have a play around.
I am still working on my SM1 from Dontronics, which is B/W not colour, but I am drooling in anticipation of the arrival of my colour one.
B/W is great, and does the job, but even four colours would add so much more to the visible appeal of code and screen displays.
Geoff came out with 8 colours, which was even better.
I like to use colour in my programs where I can - keeps the screen looking interesting. Smoke makes things work. When the smoke gets out, it stops! |
|
Grogster
Admin Group
Joined: 31/12/2012 Location: New ZealandPosts: 9307 |
Posted: 01:38pm 15 Jan 2013 |
Copy link to clipboard |
Print this post |
|
What I REALLY love about the MM BASIC, is it is really easy to learn - even relatively advanced features.
Coming from a PICAXE background, I can say that MM BASIC is much easier to learn and do things with then PICAXE BASIC. This is NOT a put-down of PICAXE - I still used them a lot for simpler things, and comparing the 8-bit PICAXE to the 32-bit MM is not really fair...
What I am getting at is even with things like this thread.
In PICAXE BASIC I would have needed much more code then above, to do the same thing.
Again, this is NOT a put-down of PICAXE, just my own comparison.
Some people prefer byte-by-byte processing in code - I don't.
I am much happier if there is a command such as LINE INPUT which will do it all for you in one single line of code.
While you can do the equivalent of LINE INPUT on the PICAXE, it involves much more code rather then one single line as in MM BASIC, and also things like driving a VGA module such as the 4D Systems serial VGA module, just seems to be so much more complicated - MY HUMBLE OPINION ONLY - not meaning to offend any PICAXE users who may be reading this forum...
Smoke makes things work. When the smoke gets out, it stops! |
|