← Back to list

Exploring Programming Languages — QBasic

Let’s continue our exploration of programming languages, with another well know language that now is mostly forgotten, QBasic.

Blag aka Alvaro Tejada Galindo in Dev Genius · 2024-05-28 09:59 · 10 claps · 6.1 min read paywalled
#qbasic #programming #programming-languages
Open on Medium ↗
Wiki topics: FT · Fine-tuning & Adaptation 💻 · Programming

Exploring Programming Languages — QBasic

Generated by Google’s Gemini

Generated by Google’s Gemini

Let’s continue our exploration of programming languages, with another well-known language that now is mostly forgotten, QBasic.

Not a Medium member? 🙁 Read it here for free 🥳

QBasic has been amongst us for 33 years already, as it was first published in 1991. Basic came out 60 years ago, in 1964.

QBasic popularity was due mainly because it was used to teach programming, it came bundled in most PC computers and people like to play Gorillas.

QBasic’s Gorillas

QBasic’s Gorillas

The first I learned QBasic was around 1997 and I learned it because come on…it’s QBasic 😎.

For this, I’m using QB64 which tries to keep things as close to the real thing as possible.

Ok, let’s jump into our main topic, which is creating an LED Numbers application.

The application should work like this, we input 1977 and it returns:

LED Numbers output

LED Numbers output

Now, keep in mind that we want to show this to newcomers to QBasic not to seasoned developers.

The first thing we’re going to do is to create multiple Arrays, as at the time, things like Maps, Hashes, or Dictionary didn’t even exist, these arrays will hold all the components of the LED numbers:

Zero$(0) = " _  "
Zero$(1) = "| | "
Zero$(2) = "|_| "
One$(0) = "  "
One$(1) = "| "
One$(2) = "| "
Two$(0) = " _  "
Two$(1) = " _| "
Two$(2) = "|_  "
Three$(0) = "_  "
Three$(1) = "_| "
Three$(2) = "_| "
Four$(0) = "    "
Four$(1) = "|_| "
Four$(2) = "  | "
Five$(0) = " _  "
Five$(1) = "|_  "
Five$(2) = " _| "
Six$(0) = " _  "
Six$(1) = "|_  "
Six$(2) = "|_| "
Seven$(0) = "_  "
Seven$(1) = "  |"
Seven$(2) = "  |"
Eight$(0) = " _  "
Eight$(1) = "|_| "
Eight$(2) = "|_| "
Nine$(0) = " _  "
Nine$(1) = "|_| "
Nine$(2) = " _| "

We’re separating each number into three lines. So for example if we were to print the number 6 we could do it like this:

Print(Six$(0))
Print(Six$(1))
Print(Six$(2))

So that’s very straightforward. We just grab the number we want and print each line.

And the result would be:

 _  
|_  
|_|

Of course, we would like to print more than one number, so the idea would be to concatenate each number’s line and then print them:

Print(Six$(0) + Two$(0))
Print(Six$(1) + Two$(1))
Print(Six$(2) + Two$(2))

Again, easy to read and understand. We’re just printing two values together.

And the result would be:

 _   _  
|_   _| 
|_| |_

Of course, we need a way to automate this as the longer the number gets, the longer our print commands would be, and also, we don’t want to have anything hardcoded.

Ok, we have then 3 lines that need to be printed. But an unknown number. It’s important to know at runtime how many digits our number has so that we act accordingly. Let’s say we want to print the number 1593, so we have 4 digits, and we need to print 3 lines, each line with sections of those 4 digits, so here’s our application code:

Zero$(0) = " _  "
Zero$(1) = "| | "
Zero$(2) = "|_| "
One$(0) = "  "
One$(1) = "| "
One$(2) = "| "
Two$(0) = " _  "
Two$(1) = " _| "
Two$(2) = "|_  "
Three$(0) = "_  "
Three$(1) = "_| "
Three$(2) = "_| "
Four$(0) = "    "
Four$(1) = "|_| "
Four$(2) = "  | "
Five$(0) = " _  "
Five$(1) = "|_  "
Five$(2) = " _| "
Six$(0) = " _  "
Six$(1) = "|_  "
Six$(2) = "|_| "
Seven$(0) = "_  "
Seven$(1) = "  |"
Seven$(2) = "  |"
Eight$(0) = " _  "
Eight$(1) = "|_| "
Eight$(2) = "|_| "
Nine$(0) = " _  "
Nine$(1) = "|_| "
Nine$(2) = " _| "
Input "Enter a Number: ", Number$
NumLen = Len(Number$)
For i = 1 To NumLen
    Digit$ = Mid$(Number$, i, 1)
    If Digit$ = "0" Then line1$ = line1$ + Zero$(0): line2$ = line2$ + Zero$(1): line3$ = line3$ + Zero$(2)
    If Digit$ = "1" Then line1$ = line1$ + One$(0): line2$ = line2$ + One$(1): line3$ = line3$ + One$(2)
    If Digit$ = "2" Then line1$ = line1$ + Two$(0): line2$ = line2$ + Two$(1): line3$ = line3$ + Two$(2)
    If Digit$ = "3" Then line1$ = line1$ + Three$(0): line2$ = line2$ + Three$(1): line3$ = line3$ + Three$(2)
    If Digit$ = "4" Then line1$ = line1$ + Four$(0): line2$ = line2$ + Four$(1): line3$ = line3$ + Four$(2)
    If Digit$ = "5" Then line1$ = line1$ + Five$(0): line2$ = line2$ + Five$(1): line3$ = line3$ + Five$(2)
    If Digit$ = "6" Then line1$ = line1$ + Six$(0): line2$ = line2$ + Six$(1): line3$ = line3$ + Six$(2)
    If Digit$ = "7" Then line1$ = line1$ + Seven$(0): line2$ = line2$ + Seven$(1): line3$ = line3$ + Seven$(2)
    If Digit$ = "8" Then line1$ = line1$ + Eight$(0): line2$ = line2$ + Eight$(1): line3$ = line3$ + Eight$(2)
    If Digit$ = "9" Then line1$ = line1$ + Nine$(0): line2$ = line2$ + Nine$(1): line3$ = line3$ + Nine$(2)
Next i
Print line1$
Print line2$
Print line3$

Before we go into analyzing and running this code, let me mention that the first time I wrote this code, it was on a Macintosh Plus Emulator (As my first computer ever was a Macintosh Plus 🥰). I used Microsoft BASIC, since 1984.

Microsoft Basic on Macintosh Plus Emulator

Microsoft Basic on Macintosh Plus Emulator

Here’s an image so you know it was 🤓

Running LED_Numbers on Microsoft Basic on Macintosh Plus Emulator

Running LED_Numbers on Microsoft Basic on Macintosh Plus Emulator

To make things easier, let’s debug our application and see which values would be present on each iteration:

  • We input the number 1593 and store it on the variable Number$.
  • We get the length of the variable and store it on the variable NumLen. Notice that NumLen doesn’t have the $ because it’s an integer.
  • We perform a loop that goes from 1 to NumLen. So, 1 to 4 in this example.
  • Digit$ = Mid$(Number$, i, 1) This is going to grab each digit from Number$ using the Mid$ function and store it on Digit$.
  • On the first iteration, it will grab 1, on the second 5, on the third 9, and on the fourth 3.
  • For every iteration, we’re going to ask the value of the digit.
  • If the digit is 1, then line1$ = line1$ + One$(0): line2$ = line2$ + One$(1): line3$ = line3$ + One$(2) which means read One$(0) and assign it line1$, read One$(1) and assign it line2$, read One$(2) and assign it line3$.
  • We simply continue like that, concatenating the values on line1$, line2$ and line3$.
  • Next i this is needed to make the loop keep going.
  • When we’re done, we can simply print all three lines.
   _   _  _  
| |_  |_| _| 
|  _|  _| _|

And the application is over. If we named our application LED_Numbers.bas, we can run like this, and here comes the fun part:

cd QB64
./bb64

Running QB64

Running QB64

You get a DOS window 😍. Press OK and the File → Open to select your file.

Open up LED_Numbers.bas

Open up LED_Numbers.bas

After this, we can select Run → Start (Or press F5 on Windows):

Select Run → Start or Press F5

Select Run → Start or Press F5

QB64 will create an exec file and run it for us 😊

We input 1593, and get the LED Numbers printed

We input 1593, and get the LED Numbers printed

That’s it 🤓 I hope you liked it and I will see you again in the next installment, which will present Dreamberd.

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Follow me on X: @Blag Connect with me on LinkedIn: Blag aka Alvaro Tejada Galindo


메타데이터
post_id
4ab3588bb303
slug
exploring-programming-languages-qbasic-4ab3588bb303
url
https://blog.devgenius.io/exploring-programming-languages-qbasic-4ab3588bb303
canonical_url
https://blog.devgenius.io/exploring-programming-languages-qbasic-4ab3588bb303
author_url
https://medium.com/@atejada
status
ok
fetched_at
2026-07-23 18:27:49