After seeing some QBASIC videos on YouTube, I’ve been inspired to start learning the language myself. I started reading some tutorials on the web to gain a grasp of all the essentials. I already have some experience programming in BASIC with my Commodore 64, so learning the basic syntax was more or less a refresher course. There are a few differences, but overall it’s the same language.
I started off with a simple “Hello, World!” program and then started playing around with other syntactical elements, until eventually I had a fairly comprehensive understanding of the language and some of its features. I did all this in a single evening. So far the language is pretty cool. In this post I’m going to talk about the QBASIC features that excited me most.
First, QBASIC allows you to change the screen mode. This controls features like the font and colors, how large the text appears, and whether you can draw pictures on the screen. The default screen mode is 0. You can change it if you want to display text in more of an Atari-style font or if you want to implement graphics. You do this with the
SCREEN command, which has one argument – a number corresponding to the screen mode.
I wrote the following program to experiment with some of the graphical capabilities of QBASIC:
1 SCREEN 12 2 CIRCLE (100, 100), 50, 1 3 CIRCLE (200, 100), 50, 2 4 CIRCLE (300, 100), 50, 3 5 CIRCLE (100, 200), 50, 4 6 CIRCLE (200, 200), 50, 5 7 CIRCLE (300, 200), 50, 6 8 CIRCLE (100, 300), 50, 7 9 CIRCLE (200, 300), 50, 8 10 CIRCLE (300, 300), 50, 9 11 END
When run, this program displays the following graphic on the screen:
I also did some playing around with scan codes. QBASIC gives you an easy method for reading the scan code of a key typed at the keyboard. How it works is when you call the
INKEY$ function, it will give you a string that is either one byte corresponding to the key typed if it’s an ASCII character, or a two-byte string consisting of the
NUL character followed by the scan code if it’s a non-ASCII character. I had some difficulty finding a way to get the scan code, but I managed to come up with a solution by reading the online help manual as well as some tutorials on the Internet:
1 REM Prints the ASCII code or scan code of the key pressed 2 CLS 3 DO 4 1 KEY$ = INKEY$ 5 IF KEY$ = "" GOTO 1 6 IF ASC(KEY$) = 0 THEN 7 PRINT "Scan code: ("; ASC(LEFT$(KEY$, 1)); ","; ASC(RIGHT$(KEY$, 1)); 8 ELSE 9 PRINT "ASCII code: "; ASC(KEY$) 10 END IF 11 LOOP UNTIL KEY$ = CHR$(27) 12 END
Here is a sample session running this program and typing all the function keys as well as some other keys in that general area of the keyboard:
This is more of a proof of concept than anything else. Of course QBASIC comes with a handy table of scan codes in case I want to do anything more sophisticated with them, like actually bind those function keys to their own functions.
This is my favorite part of QBASIC so far. I just love the concept of scan codes, because it gets into the nitty-gritty details of the system and gives you direct access to some of the hardware, which I think is pretty awesome.
All in all, I’m really excited to be learning this neat little language. Now that I know the basic syntax, I will have no problem just going through the manual’s index and learning all the different functions and advanced syntactical constructs that are available. Soon I’ll be able to make really cool MS-DOS apps with it, just like that Bisqwit guy from YouTube who inspired me to do this in the first place!
The video that inspired me to start learning QBASIC
A website I found that teaches the basics of the language and also gives you access to a bunch of compilers
A brief explanation of scan codes along with a table of scan codes for the IBM keyboard
See you next time, and happy hacking!