First Program

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
TuLithu
Coder
Posts: 14
Joined: Sun Jan 06, 2013 10:07 am

First Program

Post by TuLithu »

Last night, I wrote my first QBASIC program, which went something like this:

CLS
FOR I% = 0 to 255
PRINT CHR$(I%);
NEXT I%
END

For some reason, the program began by printing ASCII character 014. I couldn't figure out what was going on, so I tried changing it to this:

CLS
FOR I% = 1 to 256
PRINT CHR$(I% - 1);
NEXT I%
END

This gave me an error message which led me to believe that the index variable in QBASIC is actually an array. So, what is going on in these programs? Please, don't give me the answer to this program, but if someone can give me a hint why these don't work, that would be great. Forgive my ignorance...I have only programmed before in UCBLogo :-)
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

ASCII character 7 beeps, 9 backspaces, 10 linefeeds, 11 vertical tabs, 12 formfeeds, and 13 is Return. After that you are home free except for characters 28 through 31 that don't print and 32 is a space.

CHR$(256) does not exist.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
TuLithu
Coder
Posts: 14
Joined: Sun Jan 06, 2013 10:07 am

Thank you...

Post by TuLithu »

So the reason I didn't see anything before 14 was because of ASCII code 13, which executed a carriage return. As you can see, I've never written a program using ASCII codes :oops:
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

You can print them all in QB64 with _CONTROLCHR OFF before the PRINTs.

You can use Unicode too.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply