Please help me!

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
stonezeppelinpilot
Newbie
Posts: 2
Joined: Tue May 04, 2010 12:47 am

Please help me!

Post by stonezeppelinpilot » Tue May 04, 2010 12:50 am

Why doesn't this work?


screen 13
CLS
line (9,19)-(9,15),7
line (10,19)-(10,15),7
line (6,14)-(13,14),15
line (6,13)-(13,13),15
LINE (6,12)-(13,12),15
LINE (6,11)-(13,11),15
LINE (6,10)-(13,10),15
LINE (6,9)-(13,9),10
LINE (6,8)-(9,5),10
LINE (10,5)-(13,8),10
PAINT (9,6),10,10
LINE (8,13)-(11,13),4
PSET (8,11),4
PSET (11,11),4
PSET (9,4),5
PSET (10,4),5
GET (0,0)-(19,19),head$
CLS
line (0,0)-(19,0),5
line (0,0)-(0,19),5
line (19,0)-(19,19),5
line (0,19)-(19,19),5
pset (7,7),5
pset (8,6),5
pset (9,5),5
pset (10,5),5
pset (11,6),5
pset (12,7),5
pset (12,8),5
pset (12,9),5
pset (11,10),5
pset (10,11),5
pset (9,11),5
pset (9,12),5
pset (9,13),5
pset (9,16),5
paint (3,3),15,5
get (0,0)-(19,19),box$
CLS
PUT (0,0),head$
put (0,20),box$



Thanks!

izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor » Tue May 04, 2010 4:11 am

Here you go:

Code: Select all

SCREEN 13
DIM head(19, 19)
DIM box(19, 19)
CLS
LINE (9, 19)-(9, 15), 7
LINE (10, 19)-(10, 15), 7
LINE (6, 14)-(13, 14), 15
LINE (6, 13)-(13, 13), 15
LINE (6, 12)-(13, 12), 15
LINE (6, 11)-(13, 11), 15
LINE (6, 10)-(13, 10), 15
LINE (6, 9)-(13, 9), 10
LINE (6, 8)-(9, 5), 10
LINE (10, 5)-(13, 8), 10
PAINT (9, 6), 10, 10
LINE (8, 13)-(11, 13), 4
PSET (8, 11), 4
PSET (11, 11), 4
PSET (9, 4), 5
PSET (10, 4), 5
GET (1, 1)-(19, 19), head()
CLS
LINE (0, 0)-(19, 0), 5
LINE (0, 0)-(0, 19), 5
LINE (19, 0)-(19, 19), 5
LINE (0, 19)-(19, 19), 5
PSET (7, 7), 5
PSET (8, 6), 5
PSET (9, 5), 5
PSET (10, 5), 5
PSET (11, 6), 5
PSET (12, 7), 5
PSET (12, 8), 5
PSET (12, 9), 5
PSET (11, 10), 5
PSET (10, 11), 5
PSET (9, 11), 5
PSET (9, 12), 5
PSET (9, 13), 5
PSET (9, 16), 5
PAINT (3, 3), 15, 5
GET (1, 1)-(19, 19), box()
CLS
PUT (0, 0), head()
PUT (0, 20), box()
When using PUT and GET you need to use DIM and in GET you can't start from 0,0 like you did you must start from 1,1.

btw. Jack in the box, nice

User avatar
RexRanRum
Newbie
Posts: 5
Joined: Wed May 07, 2008 1:45 pm
Location: Pittsburgh, PA
Contact:

GETtin'

Post by RexRanRum » Tue May 04, 2010 8:29 pm

Well, you can start from zero for arrays (like a normal programming language), but you have to jump through an additional hoop to do so.

Code: Select all

OPTION BASE 0 ' sets all arrays in this program to have an implicit 0 starting point instead of 1
OR

Code: Select all

DIM head(0 TO 19, 0 TO 19) ' explicity define a lower bound on the array indices

Also, to grab an image that size, you don't need 20x20 array space. One helpful fact is that you can store a two-dimensional image in a single dimensional array (head(0 TO 399)). Each 16-bit array element (definitely want to use a number over a string) can hold two 8-bit pixels (in SCREEN 13), but you also need room to store a GET'd image's width and height, too, so 400/2 + 2 = 202 = head(0 to 201).


I just checked; GETting from 0 works fine. The only problem in your code was using the strings head$ and box$ instead of arrays.

Code: Select all

DIM head(0 TO 201) ' add to beginning of code
DIM boxx(0 TO 201) ' add to beginning of code
' ...
GET (0, 0)-(19, 19), head
' ...
GET (0, 0)-(19, 19), boxx
CLS
PUT (0, 0), head
PUT (0, 20), boxx
With the above changes, it all worked fine for me -- all while GETting the full twenty pixels of the Jack-in-the-Box instead of only nineteen, too.
"I reject your reality and substitute my own!" ~ Adam Savage

stonezeppelinpilot
Newbie
Posts: 2
Joined: Tue May 04, 2010 12:47 am

Post by stonezeppelinpilot » Thu May 06, 2010 10:20 am

Thanks, guys!

Got it working just fine. It's a project for school. I used to program in qbasic when I was pretty young but haven't done it in a long time. It's starting to come back to me.

Post Reply