BBC BASIC
« Example program challenge »

Welcome Guest. Please Login or Register.
Jan 20th, 2018, 6:05pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1 2 3 4  Notify Send Topic Print
 veryhotthread  Author  Topic: Example program challenge  (Read 3247 times)
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Example program challenge
« Reply #45 on: Jan 30th, 2017, 9:25pm »

on Jan 30th, 2017, 5:25pm, hellomike wrote:
Code:
i% = ASCMID$(zeros$, RND(LENzeros$) - (LENzeros$ == 1), 1) 

OK, I've made that change.

I can't say I'm enthusiastic about deliberately passing a non-integer value as the second parameter of MID$() - it feels a bit kludgy - but at least the truncation to the next lower integer is a documented feature so it should be reliable.

Although it's not relevant in this case, because the parameter is always positive, perhaps I should take the opportunity to remind people that these two statements are not equivalent:

Code:
      a% = a
      a% = INT(a) 

If a is negative (and not an integer) they will do different things. The first truncates towards zero so if a was -3.5 a% would be set to -3. However the second truncates towards minus infinity so if a was -3.5 a% would be set to -4.

This is documented behaviour for BBC BASIC (and several other languages) and ought always to be reliable, but in my experience not everybody is aware of it.

Richard.
User IP Logged

hellomike
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 55
xx Re: Example program challenge
« Reply #46 on: Jan 31st, 2017, 08:29am »

Thanks Richard.

Interesting reminder.

I was not aware of exactly the behavior however, if I knew the floating point variable could be negative I would surely do tests to assure its behavior and I would find out.
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 689
xx Re: Example program challenge
« Reply #47 on: Apr 7th, 2017, 11:08am »

on Jan 24th, 2017, 08:04am, hellomike wrote:
I wouldn't mind having to add code similar to
Code:
IF (INKEY(-256) == &57) GUIFONT$="Clear Sans Bold" ELSE GUIFONT$="FreeSans" 

I found I had to make a small change to make your program compatible with Windows 95 (you may well ask why I bothered in 2017....). The original had:

Code:
      FONTCMD$ = "FONT Clear Sans Bold,"
      OSCLI FONTCMD$ + ",10"
      SYS "GetTextFace", @memhdc%, 32, f%
      IF $$f% <> "Clear Sans Bold" THEN
        TH&() = 0, 70, 70, 70, 70, 70, 70, 48, 48, 48, 37, 37, 37, 37
        BASE% = -6
      ENDIF
 

which relies on Windows substituting a 'sensible' font if Clear Sans Bold is not available. Unfortunately Windows 95 substitutes an entirely unsuitable symbols font so I have changed the code as follows:

Code:
      FONTCMD$ = "FONT Clear Sans Bold,"
      OSCLI FONTCMD$ + ",10"
      SYS "GetTextFace", @memhdc%, 32, f%
      IF $$f% <> "Clear Sans Bold" THEN
        FONTCMD$ = "FONT Arial,"
        TH&() = 0, 70, 70, 70, 70, 70, 70, 48, 48, 48, 37, 37, 37, 37
        BASE% = -6
      ENDIF
 

Richard.
User IP Logged

hellomike
Junior Member
ImageImage


member is offline

Avatar




PM

Gender: Male
Posts: 55
xx Re: Example program challenge
« Reply #48 on: Apr 7th, 2017, 8:21pm »

Thanks for letting me know.
User IP Logged

Pages: 1 2 3 4  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls