Programming in QuickBasic with repl.it?

511 Views Asked by At

I'm trying to get a "retro-computing" class open and would like to give people the opportunity to finish projects at home (without carrying a 3kb monstrosity out of 1980 with them) I've heard that repl.it has every programming language, does it have QuickBasic and how do I use it online? Thanks for the help in advance!

1

There are 1 best solutions below

1
On

You can do it (hint: search for QBasic; it shares syntax with QuickBASIC), but you should be aware that it has some limitations as it's running on an incomplete JavaScript implementation. For completeness, I'll reproduce the info from the original blog post:

What works

Only text mode is supported. The most common commands (enough to run nibbles) are implemented. These include:

  • Subs and functions
  • Arrays
  • User types
  • Shared variables
  • Loops
  • Input from screen

What doesn't work

  • Graphics modes are not supported
  • No statements are allowed on the same line as IF/THEN
  • Line numbers are not supported
  • Only the built-in functions used by NIBBLES.BAS are implemented
  • All subroutines and functions must be declared using DECLARE

This is far from being done. In the comments, AC0KG points out that P=1-1 doesn't work.

In short, it would need another 50 or 100 hours of work and there is no reason to do this.

One caveat that I haven't been able to determine is a statement like INPUT or LINE INPUT... They just don't seem to work for me on repl.it, and I don't know where else one might find qb.js hosted.


My recommendation: FreeBASIC

I would recommend FreeBASIC instead, if possible. It's essentially a modern reimplementation coded in C++ (last I knew) with additional functionality.

Old DOS stuff like the DEF SEG statement and VARSEG function are no longer applicable since it is a modern BASIC implementation operating on a 32-bit flat address space rather than 16-bit segmented memory. I'm not sure what the difference between the old SADD function and the new StrPtr function is, if there is any, but the idea is the same: return the address of the bytes that make up a string.

You could also disable some stuff and maintain QB compatibility using #lang "qb" as the first line of a program as there will be noticeable differences when using the default "fb" dialect, or you could embrace the new features and avoid the "qb" dialect, focusing primarily on the programming concepts instead; the choice is yours. Regardless of the dialect you choose, the basic stuff should work just fine:

DECLARE SUB collatz ()
DIM SHARED n AS INTEGER

INPUT "Enter a value for n: ", n
PRINT n
DO WHILE n <> 4
    collatz
    PRINT n
LOOP
PRINT 2
PRINT 1

SUB collatz
    IF n MOD 2 = 1 THEN
        n = 3 * n + 1
    ELSE
        n = n \ 2
    END IF
END SUB

A word about QB64

One might argue that there is a much more compatible transpiler known as QB64 (except for some things like DEF FN...), but I cannot recommend it if you want a tool for students to use. It's a large download for Windows users, and its syntax checking can be a bit poor at times, to the point that you might see the QB code compile only to see a cryptic message like "C++ compilation failed! See internals\temp\compile.txt for details". Simply put, it's usable and highly compatible, but it needs some work, like the qb.js script that repl.it uses.


An alternative: DOSBox and autorun

You could also find a way to run an actual copy of QB 4.5 in something like DOSBox and simply modify the autorun information in the default DOSBox.conf (or whatever it's called) to automatically launch QB. Then just repackage it with the modified DOSBox.conf in a nice installer for easy distribution (NSIS, Inno Setup, etc.) This will provide the most retro experience beyond something like a FreeDOS virtual machine as you'll be dealing with the 16-bit segmented memory, VGA, etc.—all emulated of course.