Converting strings to upper case

Discussions about the BBC BASIC language, with particular reference to BB4W and BBCSDL
ArryMan
Posts: 12
Joined: Sat 05 Feb 2022, 10:59

Converting strings to upper case

Post by ArryMan »

According to the blurb, I need to import the STRINGLIB to be able to convert lower case strings to upper, then use the function FN_upper. I've done that and it always works just once. After that, it fails with the error code "Mistake" every time. The same happens with FN_lower etc. I have deliberately typed my code in lower case and let the IDE convert it to upper case at will. Here's what my code looked like after I'd entered it and let the IDE have its way:
INSTALL @lib$+"STRINGLIB"

test1$ = "test1"
test2$ = "test2"

PRINT FN_upper(test1$)
print fn_upper(test2$)
print fn_upper("test")

You can see that with the first function command the IDE converted to upper case as normal. But the next two times it left them in lower case. When I run the code, it produces this:

TEST1

Mistake
>

I keep thinking I must be either misunderstanding the use of the function, or making some other mistake I can't see. Can anyone put me right on this, please? :?

ArryMan
Posts: 12
Joined: Sat 05 Feb 2022, 10:59

Re: Converting strings to upper case

Post by ArryMan »

Just tested this in BBC SDLIDE v1.27a and the problem goes away!

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Converting strings to upper case

Post by DDRM »

Copying and pasting your code works fine for me in BB4W, too, so I don't know what you'd done!

:-)

D

PS you could always write your own version of the function, rather than importing the library! ;-)

ArryMan
Posts: 12
Joined: Sat 05 Feb 2022, 10:59

Re: Converting strings to upper case

Post by ArryMan »

DDRM, thanks for the mention. Well, I finally got to the bottom of this, and solved a few other mysteries as well.

I am in the habit of having two BB4Ws running at the same time, using one for the main code and the other as a scratchpad, trying our little snippets of code before committing them to the main code. I now know that the second one misbehaves frequently in these circumstances. If it's the only window open, everything is ok.

This is a disappointment, as I've always found it a convenient way of working. The same thing doesn't happen in Liberty Basic for example, or Python.

What I do now is to insert the snippet to try at the head of the current code followed by END so that I can conveniently run it from there. Sadly, I have to remove it every time as multi-line REMs aren't available. Oh well, you can't please all of the coders all of the time . . . !

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Converting strings to upper case

Post by DDRM »

Hi Arryman,

Sorry, I missed this for some reason!

I regularly have more than one version of BBC BASIC open, and I've never found a problem with interactions, so I'm not sure why you are having problems.

As for multi-line REMs: just select the block you want to REM out, right-click, and choose "Add REMs"! This changes to "remove REMs" if the block is already remmed out.

Best wishes,

D

Hated Moron
Posts: 131
Joined: Thu 07 Apr 2022, 10:10

Re: Converting strings to upper case

Post by Hated Moron »

ArryMan wrote:
Sun 06 Feb 2022, 20:17
This is a disappointment, as I've always found it a convenient way of working. The same thing doesn't happen in Liberty Basic for example, or Python.
Don't be disappointed - it doesn't happen in BBC BASIC either! You can quite safely open and use multiple copies of BB4W, they won't interact with each other (not least because they run in different processes with independent address spaces).

I think the reason for the apparent behaviour is that you have inadvertently set one copy of BB4W to the (non-standard) 'Lowercase keywords' mode and the other copy to the standard 'Keywords must be in capitals' mode. That could happen, for example, if you open one copy, change the mode, and then open a second copy. The mode change doesn't get recorded in the Registry until you exit BB4W so the second copy won't notice that you have changed the mode.

I recommend that the 'Lowercase keywords' mode not be used. It is non-standard in BBC BASIC, can make your programs incompatible with other systems, and significantly reduces your choice of variable names.
If you are unhappy with any aspect of this post, please report it to the forum administrator (click on the exclamation mark icon in the top-right corner) rather than complaining on the open forum or by private email.