Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / DB tutorials

Author
Message
Richard Swipe
20
Years of Service
User Offline
Joined: 13th Jul 2004
Location: England
Posted: 30th Jul 2004 19:19
Hi, i'm new to DB and am working through the tutorials in the user manual (these are also the tutorials available within DB itself) and ive come across a problem with tutorial 3: screen switcher.
the code crashes on line 18 (loop) with the error 'display mode invalid'.
can anyone spot a bug in the code?
ive copied the code below
many thanks.

R. Swipe
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 30th Jul 2004 20:10
It works ok here, I'm guessing you're using Darkbasic Classic.

Does it crash straight away, or do you press a button then it crashes?
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 31st Jul 2004 04:10 Edited at: 31st Jul 2004 04:11
Well, I'm going to take a guess here that you're pressing a key that is beyond the limit of the check list generated, since your input code only references from ascii "0" and higher. That means it allows for like the letter "a" and up as well, decoding them in a rather odd fashion. (And certainly not a nummeric one.)

Oh crud! Now I see it!!

the problem is easier than that -- it's SPACES!

change the lines to;

WIDTH = CHECKLIST VALUE A(POSITION)
HEIGHT = CHECKLIST VALUE B(POSITION)
DEPTH = CHECKLIST VALUE C(POSITION)

ie, no space between the Position values and the A, B, C...

But you should also do a check for the end of the checklist too,
as in;

POSITION = ASC (INKEY$()) - 48
if position > 0 and position < CHECKLIST QUANTITY()
...
rest of code.

S.

Any truly great code should be indisguishable from magic.
Richard Swipe
20
Years of Service
User Offline
Joined: 13th Jul 2004
Location: England
Posted: 11th Aug 2004 05:01
Many thanks for the replies - heres what happens:
i'm using DB v1.12.
when i run, the screen clears and displays the 24 display modes and then waits for input.
i hit 4
the screen clears then produces the following error
'runtime warning at line 14 - cannot create display mode'

so i changed the code to that attached
ie i put some print lines in and remed out the display mode
now it displays the 24 modes, waits for input, i press 4 and it displays:
4 4 800 4 -48
'runtime error at line 11. checklist index is illegal.'

i think i'm barking up the wrong tree here.
can anyone tell me what this program is trying to acheive?
i guess its supposed to be showing me the different display modes available. is that right?

R. Swipe
SandraD
20
Years of Service
User Offline
Joined: 30th May 2004
Location: Down on the corner, out in the street.
Posted: 11th Aug 2004 12:11
Yes, it is supposed to display the possible range of video modes available and allow you to switch between them, however the program is "a little strange" in the way that it allows you to select them.

The key element is that asc(inkey$())-48 part in the program, which takes a key from the keyboard and assumes it's a number from 0 to 9. An ASCII zero is code 48 from the keyboard, while the numbers of 1 to 9 are codes 48 to 57 respectively. Since you say you get a list of 24 codes for example, that means you can only get into any of the first ten. (0 to 9.)

If you would like to change the program to be able to get into all 24 of the modes you see listed then you must change the way the keyboard is interpretted, making the asc(inkey$())-48 into the term of asc(inkey$())-65. This allows that each mode coud be selected by pressing A to Z on the keyboard because ASCII A is the value of 65 in the ASCII code.


Another way to handle this is;

position = asc(inkey$())-48
if position > 57 then position = position - 7

Which corrects for the 7 keys that exist between "9" and "A" on the ASCII code scale. Using this, A=10, B=11 and so on, after the number keys of 0 to 9. And finally, you should make a check to see if the value is valid in the check list itself putting the following in just before the code that gets the values and tries to switch mode;

if position <= checklist quantity()
...(change modes stuff here)...
endif

goodluck,
S.

Any truly great code should be indisguishable from magic.

Login to post a reply

Server time is: 2024-09-22 20:21:15
Your offset time is: 2024-09-22 20:21:15