QBasic
Encyclopedia
QBasic is an IDE
and interpreter
for a variant of the BASIC programming language which is based on QuickBASIC
. Code entered into the IDE is compiled to an intermediate form, and this intermediate form is immediately interpreted on demand within the IDE. It can run under nearly all versions of DOS
and Windows
, or through DOSBox
/DOSEMU
, on Linux
and FreeBSD
. For its time, QBasic provided a state-of-the-art IDE, including a debugger
with features such as on-the-fly expression evaluation and code modification.
Like QuickBASIC, but unlike earlier versions of Microsoft BASIC, QBasic is a structured programming
language, supporting constructs such as subroutines and while loop
s. Line number
s, a concept often associated with BASIC, are supported for compatibility, but are not considered good form, having been replaced by descriptive line labels. QBasic has limited support for user-defined data types (structures
), and several primitive types used to contain strings of text or numeric data.
. It was based on the earlier QuickBASIC 4.5 compiler but without QuickBASIC's compiler and linker elements. Version 1.0 was shipped together with MS-DOS
5.0 and higher, as well as Windows 95
, Windows NT 3.x
, and Windows NT 4.0
. IBM
recompiled QBasic and included it in PC-DOS 5.x, as well as OS/2
2.0 onwards. eComStation
, descended from OS/2 code, includes QBasic 1.0. QBasic 1.1 is included with MS-DOS 6.x, and, without EDIT, in Windows 95
, Windows 98
and Windows Me
. Starting with Windows 2000
, Microsoft no longer includes QBasic with their operating systems. (However, some localized versions of Windows 2000
and Windows XP
still have it, and it can be given out as freeware.)
QBasic (as well as the built-in MS-DOS Editor) is backward compatible with DOS releases prior to 5.0 (down to at least DOS 3.20). However, if used on any 8088
/8086
computers, or on some 80286
computers, the QBasic program may run very slowly, or perhaps not at all, due to its memory size. Until MS-DOS 7, MS-DOS Editor required QBasic: the "edit.com" program simply started QBasic in editor mode only, and this mode can also be entered by running QBASIC.EXE with the /EDITOR switch (i.e., command line "QBASIC /EDITOR".
", a variant of the Snake
game; "Gorillas", an Artillery game; "MONEY MANAGER", a personal finance manager; and "RemLine", a GW-BASIC code line-number-removing program.
CLS
PRINT "Guess the number!"
INPUT "Would you like to play? (Y/N): ", choice$ ' An input statement, that takes what the user inputs...
choice$ = UCASE$(choice$) ' makes the input completely uppercase (fkld ---> FKLD)
IF choice$ = "YES" OR choice$ = "Y" THEN ' and decides whether or not they want to play:
guesses% = 5 ' Set up number of guess remaining
RANDOMIZE TIMER ' Sets up the random number generator
target% = INT(RND * 10) + 1 ' Picks a random number between 1 and 10 (inclusive)
won% = 0 ' Sets up a flag called 'won%' to check if user has won
PRINT "The number is between 1 and 10."
WHILE guesses% > 0 AND won% = 0 ' Enters a loop until the user wins or runs out of chances
INPUT "Enter your guess: ", guess% ' Takes user input (the guess)
IF guess% = target% THEN ' Determines if the guess was correct
PRINT "Correct, the answer was"; target%; "!"
won% = 1 ' Sets a flag to indicate user has won
ELSE
guesses% = guesses% - 1 ' Deducts one chance
PRINT "Sorry, please try again. You have"; guesses%; "guesses left."
END IF
WEND ' End of guessing loop
IF won% = 0 THEN PRINT "You ran out of guesses, the number was"; target%; "."
END IF
, with the switch on to slow the CPU to 4.77 MHz) or in an emulator like Bochs
or DOSBox
which can be slowed down.
Integrated development environment
An integrated development environment is a software application that provides comprehensive facilities to computer programmers for software development...
and interpreter
Interpreted language
Interpreted language is a programming language in which programs are 'indirectly' executed by an interpreter program. This can be contrasted with a compiled language which is converted into machine code and then 'directly' executed by the host CPU...
for a variant of the BASIC programming language which is based on QuickBASIC
QuickBASIC
Microsoft QuickBASIC is an Integrated Development Environment and compiler for the BASIC programming language that was developed by Microsoft. QuickBASIC runs mainly on DOS, though there was a short-lived version for Mac OS...
. Code entered into the IDE is compiled to an intermediate form, and this intermediate form is immediately interpreted on demand within the IDE. It can run under nearly all versions of DOS
DOS
DOS, short for "Disk Operating System", is an acronym for several closely related operating systems that dominated the IBM PC compatible market between 1981 and 1995, or until about 2000 if one includes the partially DOS-based Microsoft Windows versions 95, 98, and Millennium Edition.Related...
and Windows
Microsoft Windows
Microsoft Windows is a series of operating systems produced by Microsoft.Microsoft introduced an operating environment named Windows on November 20, 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces . Microsoft Windows came to dominate the world's personal...
, or through DOSBox
DOSBox
DOSBox is emulator software that emulates an IBM PC compatible computer running MS-DOS. It is intended especially for use with old PC games. DOSBox is free software....
/DOSEMU
DOSEMU
DOSEMU, alternatively rendered dosemu, is a compatibility layer software package that enables MS-DOS systems, DOS clones such as FreeDOS, and DOS software to run under Linux on x86-based PCs ....
, on Linux
Linux
Linux is a Unix-like computer operating system assembled under the model of free and open source software development and distribution. The defining component of any Linux system is the Linux kernel, an operating system kernel first released October 5, 1991 by Linus Torvalds...
and FreeBSD
FreeBSD
FreeBSD is a free Unix-like operating system descended from AT&T UNIX via BSD UNIX. Although for legal reasons FreeBSD cannot be called “UNIX”, as the direct descendant of BSD UNIX , FreeBSD’s internals and system APIs are UNIX-compliant...
. For its time, QBasic provided a state-of-the-art IDE, including a debugger
Debugger
A debugger or debugging tool is a computer program that is used to test and debug other programs . The code to be examined might alternatively be running on an instruction set simulator , a technique that allows great power in its ability to halt when specific conditions are encountered but which...
with features such as on-the-fly expression evaluation and code modification.
Like QuickBASIC, but unlike earlier versions of Microsoft BASIC, QBasic is a structured programming
Structured programming
Structured programming is a programming paradigm aimed on improving the clarity, quality, and development time of a computer program by making extensive use of subroutines, block structures and for and while loops - in contrast to using simple tests and jumps such as the goto statement which could...
language, supporting constructs such as subroutines and while loop
While loop
In most computer programming languages, a while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement....
s. Line number
Line number
In computing, a line number is a method used to specify a particular sequence of characters in a text file. The most common method of assigning numbers to lines is to assign every line a unique number, starting at 1 for the first line, and incrementing by 1 for each successive line.In the C...
s, a concept often associated with BASIC, are supported for compatibility, but are not considered good form, having been replaced by descriptive line labels. QBasic has limited support for user-defined data types (structures
Record (computer science)
In computer science, a record is an instance of a product of primitive data types called a tuple. In C it is the compound data in a struct. Records are among the simplest data structures. A record is a value that contains other values, typically in fixed number and sequence and typically indexed...
), and several primitive types used to contain strings of text or numeric data.
History
QBasic was intended as a replacement for GW-BASICGW-BASIC
GW-BASIC was a dialect of the programming language BASIC developed by Microsoft from BASICA, originally for Compaq. It is compatible with Microsoft/IBM BASICA, but was disk based and did not need the ROM BASIC. It was bundled with MS-DOS operating systems on IBM PC compatibles by Microsoft...
. It was based on the earlier QuickBASIC 4.5 compiler but without QuickBASIC's compiler and linker elements. Version 1.0 was shipped together with MS-DOS
MS-DOS
MS-DOS is an operating system for x86-based personal computers. It was the most commonly used member of the DOS family of operating systems, and was the main operating system for IBM PC compatible personal computers during the 1980s to the mid 1990s, until it was gradually superseded by operating...
5.0 and higher, as well as Windows 95
Windows 95
Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products...
, Windows NT 3.x
Windows NT 3.1
Windows NT 3.1 is the first release of Microsoft's Windows NT line of server and business desktop operating systems, and was released to manufacturing on 27 July 1993. The version number was chosen to match the one of Windows 3.1, the then-latest operating environment from Microsoft, on account of...
, and Windows NT 4.0
Windows NT 4.0
Windows NT 4.0 is a preemptive, graphical and business-oriented operating system designed to work with either uniprocessor or symmetric multi-processor computers. It was the next release of Microsoft's Windows NT line of operating systems and was released to manufacturing on 31 July 1996...
. IBM
IBM
International Business Machines Corporation or IBM is an American multinational technology and consulting corporation headquartered in Armonk, New York, United States. IBM manufactures and sells computer hardware and software, and it offers infrastructure, hosting and consulting services in areas...
recompiled QBasic and included it in PC-DOS 5.x, as well as OS/2
OS/2
OS/2 is a computer operating system, initially created by Microsoft and IBM, then later developed by IBM exclusively. The name stands for "Operating System/2," because it was introduced as part of the same generation change release as IBM's "Personal System/2 " line of second-generation personal...
2.0 onwards. eComStation
EComStation
eComStation or eCS is a PC operating system based on OS/2, published by Serenity Systems. It includes several additions and accompanying software not present in the IBM version of the system.-Differences between eComStation and OS/2:...
, descended from OS/2 code, includes QBasic 1.0. QBasic 1.1 is included with MS-DOS 6.x, and, without EDIT, in Windows 95
Windows 95
Windows 95 is a consumer-oriented graphical user interface-based operating system. It was released on August 24, 1995 by Microsoft, and was a significant progression from the company's previous Windows products...
, Windows 98
Windows 98
Windows 98 is a graphical operating system by Microsoft. It is the second major release in the Windows 9x line of operating systems. It was released to manufacturing on 15 May 1998 and to retail on 25 June 1998. Windows 98 is the successor to Windows 95. Like its predecessor, it is a hybrid...
and Windows Me
Windows Me
Windows Millennium Edition, or Windows Me , is a graphical operating system released on September 14, 2000 by Microsoft, and was the last operating system released in the Windows 9x series. Support for Windows Me ended on July 11, 2006....
. Starting with Windows 2000
Windows 2000
Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...
, Microsoft no longer includes QBasic with their operating systems. (However, some localized versions of Windows 2000
Windows 2000
Windows 2000 is a line of operating systems produced by Microsoft for use on personal computers, business desktops, laptops, and servers. Windows 2000 was released to manufacturing on 15 December 1999 and launched to retail on 17 February 2000. It is the successor to Windows NT 4.0, and is the...
and Windows XP
Windows XP
Windows XP is an operating system produced by Microsoft for use on personal computers, including home and business desktops, laptops and media centers. First released to computer manufacturers on August 24, 2001, it is the second most popular version of Windows, based on installed user base...
still have it, and it can be given out as freeware.)
QBasic (as well as the built-in MS-DOS Editor) is backward compatible with DOS releases prior to 5.0 (down to at least DOS 3.20). However, if used on any 8088
Intel 8088
The Intel 8088 microprocessor was a variant of the Intel 8086 and was introduced on July 1, 1979. It had an 8-bit external data bus instead of the 16-bit bus of the 8086. The 16-bit registers and the one megabyte address range were unchanged, however...
/8086
Intel 8086
The 8086 is a 16-bit microprocessor chip designed by Intel between early 1976 and mid-1978, when it was released. The 8086 gave rise to the x86 architecture of Intel's future processors...
computers, or on some 80286
Intel 80286
The Intel 80286 , introduced on 1 February 1982, was a 16-bit x86 microprocessor with 134,000 transistors. Like its contemporary simpler cousin, the 80186, it could correctly execute most software written for the earlier Intel 8086 and 8088...
computers, the QBasic program may run very slowly, or perhaps not at all, due to its memory size. Until MS-DOS 7, MS-DOS Editor required QBasic: the "edit.com" program simply started QBasic in editor mode only, and this mode can also be entered by running QBASIC.EXE with the /EDITOR switch (i.e., command line "QBASIC /EDITOR".
Examples
QBasic came complete with four pre-written example programs. These were "NibblesNibbles (computer game)
Nibbles is a simple video game and variant of Snake. It was inspired by an early 1980's game called Hustle from the Radio Shack TRS-80 micro-computer....
", a variant of the Snake
Snake (video game)
Snake is a video game that originated during the late 1970s in arcades and has maintained popularity since then, becoming something of a classic...
game; "Gorillas", an Artillery game; "MONEY MANAGER", a personal finance manager; and "RemLine", a GW-BASIC code line-number-removing program.
Simple game
This program challenges the user to guess a randomly selected number within the 1-10 range, without offering the usual hints of "higher"/"lower":CLS
PRINT "Guess the number!"
INPUT "Would you like to play? (Y/N): ", choice$ ' An input statement, that takes what the user inputs...
choice$ = UCASE$(choice$) ' makes the input completely uppercase (fkld ---> FKLD)
IF choice$ = "YES" OR choice$ = "Y" THEN ' and decides whether or not they want to play:
guesses% = 5 ' Set up number of guess remaining
RANDOMIZE TIMER ' Sets up the random number generator
target% = INT(RND * 10) + 1 ' Picks a random number between 1 and 10 (inclusive)
won% = 0 ' Sets up a flag called 'won%' to check if user has won
PRINT "The number is between 1 and 10."
WHILE guesses% > 0 AND won% = 0 ' Enters a loop until the user wins or runs out of chances
INPUT "Enter your guess: ", guess% ' Takes user input (the guess)
IF guess% = target% THEN ' Determines if the guess was correct
PRINT "Correct, the answer was"; target%; "!"
won% = 1 ' Sets a flag to indicate user has won
ELSE
guesses% = guesses% - 1 ' Deducts one chance
PRINT "Sorry, please try again. You have"; guesses%; "guesses left."
END IF
WEND ' End of guessing loop
IF won% = 0 THEN PRINT "You ran out of guesses, the number was"; target%; "."
END IF
Easter egg
QBasic has a little-known Easter egg. To see it, press and hold and simultaneously after running QBasic at the DOS prompt but before the title screen loads: this lists The Team of programmers. Note that on modern computers, it is much too fast to perform. It is best done on an old PC (preferably one with a working Turbo buttonTurbo button
A turbo button refers to a button on a piece of electronic equipment, which makes the equipment run faster in some way. Although the name is based on that of a forced induction air compressor which makes a car go faster, automotive turbochargers are not manually operated, but are directly linked...
, with the switch on to slow the CPU to 4.77 MHz) or in an emulator like Bochs
Bochs
Bochs is a portable x86 and x86-64 IBM PC compatible emulator and debugger mostly written in C++ and distributed as free software under GNU Lesser General Public License...
or DOSBox
DOSBox
DOSBox is emulator software that emulates an IBM PC compatible computer running MS-DOS. It is intended especially for use with old PC games. DOSBox is free software....
which can be slowed down.
See also
- DarkBASICDarkBASICDarkBASIC is a commercial game creation programming language released by The Game Creators. The language is a structured form of BASIC and is similar to AMOS on the Amiga. The purpose of the language is game creation using Microsoft's DirectX from a BASIC programming language. It is faster and...
- FreeBASICFreeBASICFreeBASIC is a free/open source , 32-bit BASIC compiler for Microsoft Windows, protected-mode DOS , Linux, FreeBSD and Xbox....
- Just BasicJust BASICJust BASIC is a dialect of the highly popular programming language BASIC of the 1970s, for 32-bit computer systems using Windows. It's the freeware version of Liberty BASIC, popular since 1992. Just BASIC development began in 2001; first public release was in 2004...
- PowerBASICPowerBASICPowerBASIC is the brand of several commercial compilers by Venice, Florida-based PowerBASIC Inc. that compile a dialect of the BASIC programming language. The DOS versions have a syntax similar to that of QBasic and QuickBASIC, while the Windows versions utilize a standard BASIC syntax that can be...
- PureBasicPureBasicPureBasic is a commercially distributed procedural computer programming language and integrated development environment based on BASIC and developed by Fantaisie Software for Windows 32/64-bit, Linux 32/64-bit, and Mac OS X. An Amiga version is available, although it has been discontinued and...
- QB64QB64QB64 is a self-hosting BASIC compiler for Microsoft Windows, Linux and MacOSX, designed to be compatible with Microsoft QBasic and QuickBASIC...
- True BasicTrue BASICTrue BASIC is a variant of the BASIC programming language descended from Dartmouth BASIC — the original BASIC — invented by college professors John G. Kemeny and Thomas E...
- Visual BasicVisual BasicVisual Basic is the third-generation event-driven programming language and integrated development environment from Microsoft for its COM programming model...
- Blitz BasicBlitz BASICBlitz BASIC refers to the programming language dialect that was interpreted by the first Blitz compilers, devised by New Zealand-based developer Mark Sibly. Being derived from BASIC, Blitz syntax was designed to be easy to pick-up for beginners first learning to program...
- Liberty BASICLiberty BASICLiberty BASIC is a commercial computer programming language and integrated development environment . It has an interpreter developed in Smalltalk, which recognizes its own dialect of the BASIC programming language...
- Run BASICRun BASICRun BASIC is a web application server, based on the Liberty BASIC version of the BASIC programming language. Run BASIC is developed by Shoptalk Systems; v1.01 was released in November 2008.-Programming model:...
- SmallBASICSmallBASICSmallBASIC is a BASIC programming language dialect with interpreters released as free software under the GNU General Public License version 2.-Description:...
External links
- Download QBASIC 1.1 from Microsoft (included in the "Old MS-DOS Utilities" part of Windows 95 CD-ROM Extras)
- QB Express — Online magazine about QBasic programming
- The QBasic Station — Created in 1997 by Jack Thomson, it is one of the oldest, but still active, QBasic sites on the web.