Author |
Topic: Example program challenge (Read 3990 times) |
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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: 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.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
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.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
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.
|
|
Logged
|
|
|
|
hellomike
Junior Member
member is offline


Gender: 
Posts: 55
|
 |
Re: Example program challenge
« Reply #48 on: Apr 7th, 2017, 8:21pm » |
|
Thanks for letting me know.
|
|
Logged
|
|
|
|
|