Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.acorn.programmer > #946

Re: BASIC and uppercase

Date 2011-10-30 07:57 +0000
From Matthew Phillips <spam2011m@yahoo.co.uk>
Newsgroups comp.sys.acorn.programmer
Subject Re: BASIC and uppercase
Message-ID <63bc2e2a52.Matthew@sinenomine.freeserve.co.uk> (permalink)
References <cfae0b2a52.beeb@ron1954.woosh.co.nz>

Show all headers | View raw


In message <cfae0b2a52.beeb@ron1954.woosh.co.nz>
 on 30 Oct 2011 Ron  wrote:

> I have been working with !Confix and have found that the
> example uses a function to convert variable names to
> uppercase before they are used in a CASE OF structure.
> 
> DEFFNupcase(input$)
>    LOCAL pos%
>    $par% = input$
>    FOR pos%=0 TO LEN(input$)-1
>       char% = ?(par%+pos%)
>       IF char%>64 THEN
>          ?(par%+pos%) = char% AND NOT 32
>       ENDIF
>    NEXT
> =$par%
> 
> With the example,  
> DIM par% 255 is needed but not included.

This example function is not going to convert "variable names" to upper case:
it will convert a string value, which may or may not be held in a variable:

PRINT FNupcase("This")
--> THIS

> I am using the WHEN variables in mixed case, ie.
> 
> WHEN "Foo"  : Bar% = VAL(val$)
>  
> and no problems on my Iyonix.
> Do earlier BASIC's need uppercase or is it some sort of
> optimisation for BASIC to use uppercase?
> 
> WHEN "FOO"  : Bar% = VAL(val$) 

You've missed out the CASE statement, which makes it harder to see what is
going on.  I'm guessing it was something like:

CASE upcase(a$) OF

It's just that the author of Confix wanted the code for "FOO" to be executed
when a$ was FOO, FOo, FoO, Foo, fOO, fOo, foO or foo without having to write
them all out.

It all depends on your application.  Can you rely on the capitalisation of
the terms being as you expect?  If you can, no need to bother with
upper-casing it all.  But if you're accepting user input or reading from a
user-editable configuration file or something like that, it is friendlier to
allow for a mixed case input.

And be careful about copying that example for converting a string to upper
case: it's not desperately well-written for general use as it also affects
various punctuation marks and does not handle accented characters properly.

You could try:

DEFFNupcase(input$)
  LOCAL pos%
  LOCAL table%
  IF input$="" THEN =""
  SYS"Territory_UpperCaseTable",-1 TO table%
  FOR pos%=1 TO LEN(input$)
    MID$(input$,pos%,1) = CHR$( table% ? ASC(MID$(input$,pos%,1)) )
  NEXT
  = input$

This uses the Territory module to find the upper case conversion table, so
should work whatever alphabet the machine is using (apart from UTF-8 and
things like that).

Note the use of assigning to MID$ which avoids having to have a separate
buffer to build the string in.

-- 
Matthew Phillips
Durham

Back to comp.sys.acorn.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 14:34 +1300
  Re: BASIC and uppercase Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-10-30 07:57 +0000
    Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 21:35 +1300
      Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 22:57 +1300
        Re: BASIC and uppercase "John Williams (News)" <UCEbin@tiscali.co.uk> - 2011-10-30 11:38 +0100
        Re: BASIC and uppercase Matthew Phillips <spam2011m@yahoo.co.uk> - 2011-10-30 16:50 +0000
          Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 01:02 +0100
            Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 15:47 +0000
              Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 20:06 +0100
        Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 00:28 +0100
          Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-31 17:04 +1300
            Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 16:12 +0100
              Re: BASIC and uppercase jgharston <jgh@arcade.demon.co.uk> - 2011-11-01 04:51 -0700
    Re: BASIC and uppercase "Ste (news)" <steve@revi11.plus.com> - 2011-10-31 01:03 +0000
      Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 19:48 +0000
        Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-11-01 21:11 +0100
          Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-11-02 14:26 +0000
    Re: BASIC and uppercase Steve Drain <steve@kappa.me.uk> - 2011-10-31 11:10 +0000
  Re: BASIC and uppercase Chris Johnson <chrisjohnson+news@spamcop.net> - 2011-10-30 08:44 +0000
    Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-30 22:52 +1300
  Re: BASIC and uppercase Alan Adams <alan@adamshome.org.uk> - 2011-10-30 15:16 +0000
    Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-10-31 14:37 +1300
      Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-10-31 16:15 +0100
        Re: BASIC and uppercase Ron <beeb@woosh.co.nz> - 2011-11-01 11:39 +1300
          Re: BASIC and uppercase Rick Murray <heyrickmail-usenet@yahoo.co.uk> - 2011-11-01 21:21 +0100

csiph-web