Thanks +3code!
It sort of worked because now the error cursor is under the zero of 20!
Ah ha! It did work after all. I had deleted the GOTO and tried running it as IF/THEN 20 and it didnt like that but as soon as I added that GOTO it worked
well sort of..trouble is it now loops back to 20 regardless of whether the input is lesser or greater than 6
dammit
Back to the manual
Next BASIC
-
- Microbot
- Posts: 194
- Joined: Mon Oct 08, 2018 3:36 am
Re: Next BASIC
Keep in mind that if it's a string, the comparisons are alphabetical order. If it's a number, the comparisons are numerical.
I'm sure he will return. He seems to be into his amateur astronomy hobby at the moment
-
- Manic Miner
- Posts: 205
- Joined: Thu Feb 22, 2018 3:27 pm
- Location: virginias eastern shore
- Contact:
Re: Next BASIC
Alcoholics Anonymous » Mon Sep 20, 2021 1:53 pm
Keep in mind that if it's a string, the comparisons are alphabetical order. If it's a number, the comparisons are numerical.
I don't follow you AA. How can a string variable (typed in name) use alphabetical order as a way to compare with something?
All I wanted to do was limit the input to - say a dozen - characters long and perhaps repeat the 'type in your name' if there had been no response. Now I come to think of it, the input should also be rejected if it was numeric?
I'm trying to make the routine idiot proof but perhaps I bit off more than I can chew. A helpful manual would be useful.
Keep in mind that if it's a string, the comparisons are alphabetical order. If it's a number, the comparisons are numerical.
I don't follow you AA. How can a string variable (typed in name) use alphabetical order as a way to compare with something?
All I wanted to do was limit the input to - say a dozen - characters long and perhaps repeat the 'type in your name' if there had been no response. Now I come to think of it, the input should also be rejected if it was numeric?
I'm trying to make the routine idiot proof but perhaps I bit off more than I can chew. A helpful manual would be useful.
Re: Next BASIC
Take a look at the Spectrum character set (in the Spectrum +2A Manual it's in Chapter 8, section 28): letter A is CHR$(41), letter B is CHR$(42), so "B">"A".
Re: Next BASIC
You need the LEN function (in the Spectrum +2A Manual it's in Chapter 8, section 9):
IF LEN(N$)>12 THEN blablabla
Re: Next BASIC
Simplifying somewhat, the "alphabetical" comparison works by comparing the letter's positions in the alphabet. So "A" is less than "B" because A is closer to the start of the alphabet. Longer strings are compared letter by letter until a decision can be made, so "AAQ" is less than "AAZ" (the As match, but the Q is less than Z).
You need to be careful if you store numbers as strings. "100" is less than "2" because the "1" is less than the "2", and the comparison stops at the end of the shortest string. In this case you should store the second string as "002", in which case it will give the answer you'd expect. Better, don't store numbers as strings if you want to compare numbers.
BTW, the "alphabet" I'm referring to is properly called "the ASCII table", which is like the English language alphabet but also contains the digits and punctuation marks.
Derek Fountain, author of the ZX Spectrum C Programmer's Getting Started Guide and various open source games, hardware and other projects, including an IF1 and ZX Microdrive emulator.
Re: Next BASIC
Code: Select all
31 IF LEN(N$)=0 THEN PRINT "PLEASE, TYPE SOMETHING" : PAUSE 0 : GOTO 20
32 IF LEN(N$)>=12 THEN PRINT "PLEASE, USE A SORTER NAME" : PAUSE 0 : GOTO 20
Re: Next BASIC
"Alphabetical" is a very misleading way to describe it, since it most definitely isn't. Strings are ordered by character code of consecutive characters.
In ASCII, capital letters all come first so B<a, for example, which can be very confusing if you expect something strictly alphabetic.
In ASCII, capital letters all come first so B<a, for example, which can be very confusing if you expect something strictly alphabetic.