Learning QBASIC for DOS and Windows

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 (100100), 501
 3 CIRCLE (200100), 502
 4 CIRCLE (300100), 503
 5 CIRCLE (100200), 504
 6 CIRCLE (200200), 505
 7 CIRCLE (300200), 506
 8 CIRCLE (100300), 507
 9 CIRCLE (200300), 508
10 CIRCLE (300300), 509
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 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));
 9         PRINT "ASCII code: "ASC(KEY$)
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!


3 thoughts on “Learning QBASIC for DOS and Windows

  1. Can you please tell me which version of Windows are you currently running?
    Personally, I’ve used Linux my whole life and never really experienced Windows. I am free this whole month and want to try something new or really old… :p


    1. I’m currently using Windows 7, though I have MS-DOS 6.22 running in a VirtualBox VM, which is where I’m running QBASIC (it comes preinstalled on the system). If you want to install MS-DOS, you can go to Vetusware.com. They have a lot of different DOS’s, including several versions of MS-DOS and DR-DOS. QBASIC is also available for 32-bit versions of Windows, which basically means Windows 9x and Windows XP. I can’t run it in my Windows 7 host because I’m using the 64-bit version of Windows. In fact I have yet to see a Windows 7 installation that wasn’t 64-bit, though a 32-bit version apparently exists. If you want to try it in Windows I would suggest downloading Windows 95 or 98 from Vetusware and installing it in a VM (Windows XP is a lot harder to find and it also forces you to activate it, so I don’t know how that would work).

      Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s