BAS File Documentation


Summary

A .bas file is BASIC source code: a text file of program statements written in some dialect of BASIC, such as FreeBASIC, QB64, PureBasic, or a Visual Basic / VBA module. Because it is plain text, any editor (Notepad++, VS Code) opens it for reading; its MIME type is text/plain. To run it you need the interpreter or compiler for its specific dialect. A few old .bas files are tokenized binary from GW-BASIC or QuickBASIC and look like garbage in an editor.

Technical details

FeatureValue
Full nameBASIC Source Code File
File extension.bas
MIME typetext/plain
Format typePlain-text program source code
LanguageBASIC family (Dartmouth, 1964); many incompatible dialects
Common dialectsFreeBASIC, QB64, PureBasic, True BASIC, GW-BASIC, QuickBASIC, VBA/VB6
IntroducedBASIC 1964; .bas widespread since 1980s microcomputers
Open standardText is open; individual dialects are vendor-defined
EncodingASCII / UTF-8 (mostly); some old files are tokenized binary
Magic numberNone — plain text, no fixed signature
VBA/VB6 markerExported modules begin Attribute VB_Name = "..."
Classic markersLine numbers, REM, GOTO, PRINT, DIM
Runs withThe matching dialect’s interpreter/compiler (no universal runner)
Compiles to.exe via QB64, FreeBASIC (fbc), PureBasic
EditorsNotepad++, Visual Studio Code (view/edit only)
Related extensions.vb, .vbs, .frm, .cls, .bi, .bmx
Referenceqb64phoenix.com, freebasic.net
Syntax at a glance

A .bas is plain text with no magic number, so its dialect is read from the code itself. Line numbers with GOTO and REM point to GW-BASIC or QBasic; a leading Attribute VB_Name = "Module1" marks an exported VBA or VB6 module; #include and Dim x As Integer suggest FreeBASIC. The exception: GW-BASIC and QuickBASIC could save programs in a tokenized binary form (keywords stored as single bytes), which shows as unreadable characters in an editor and must be re-saved as ASCII from the original interpreter.

What is a BAS file?

A .bas file is source code written in BASIC (Beginner’s All-purpose Symbolic Instruction Code), the programming language created at Dartmouth College in 1964 that became the default language of 1980s home computers. The extension has been the conventional one for BASIC programs since the microcomputer era. In almost all cases a .bas is a plain ASCII or UTF-8 text file you can open and read in any editor, which is why its practical MIME type is text/plain.

The complication that defines working with .bas files is that there is no single BASIC. The extension is shared by dozens of mutually incompatible dialects, and a program only runs in the toolchain it was written for. Understanding a .bas therefore starts with identifying its dialect from the code, then handling two special cases: tokenized-binary files that are not text at all, and Visual Basic / VBA modules that follow a specific export format. The sections below cover each.

Reading the dialect from the code

Because the extension says nothing about which BASIC produced a file, the first task is inference from syntax. A few reliable tells:

10 REM classic dialect          → GW-BASIC / QBasic
20 FOR I = 1 TO 10                  line numbers + GOTO/GOSUB
30 PRINT I : NEXT I

Attribute VB_Name = "Module1"    → VBA / VB6 exported module
Sub Main() ... End Sub

#include "fbgfx.bi"              → FreeBASIC
Dim As Integer x                   ('As' type suffix, #include)

Line numbers followed by GOTO, GOSUB and REM mark the classic 8-bit and MS-DOS dialects (GW-BASIC, QBasic, QuickBASIC). A file that opens with Attribute VB_Name = is a Microsoft module (covered below). #include, Dim As and pointer syntax indicate FreeBASIC; other structured dialects (PureBasic, True BASIC, BlitzMax) have their own idioms. Matching the tool to these signals is the whole game: QB64 runs QuickBASIC-style code, FreeBASIC’s fbc compiles FreeBASIC, and neither will accept the other’s source unchanged.

Plain text versus tokenized binary

Most .bas files are text, but a class of older ones is not, and this is the single most common “my file is corrupted” confusion. GW-BASIC and QuickBASIC could save a program in a tokenized binary format unless you explicitly asked for the ASCII option (SAVE "prog",A in GW-BASIC). In the tokenized form, each BASIC keyword is stored as a single byte token rather than its spelled-out text: PRINT might be one byte, FOR another. This made programs smaller and faster to load on 1980s hardware.

A tokenized .bas opens in a text editor as a stream of unreadable bytes, often beginning with a marker byte such as 0xFF for GW-BASIC. It is not damaged; it is simply not text. The fix is to load it in the original interpreter (or a compatible one such as QB64) and re-save with the ASCII/text option, which expands the tokens back to readable keywords. Once in text form it behaves like any other source file. If your .bas looks like garbage, this, not corruption, is almost always why.

The VBA / VB6 module: Attribute VB_Name

A very common and quite specific meaning of .bas is a Visual Basic module exported from Microsoft Office’s VBA editor or from Visual Basic 6. When you export a standard code module, the editor writes a text .bas with a fixed header of Attribute statements:

Attribute VB_Name = "Module1"

Sub SayHello()
    MsgBox "Hello from a VBA module"
End Sub

The first line, Attribute VB_Name = "...", names the module and is written automatically on export; further hidden Attribute lines appear for class modules and procedures. Developers exchange these .bas files to share macros and library code between workbooks and documents. They are re-imported through the VBA editor’s File › Import File, which recreates the module inside the host document. This is a genuinely different world from a QBasic game: same extension, entirely different runtime.

From source to a running program

A .bas is source, so “running” it means feeding it to the right dialect’s implementation. For classic QuickBASIC and QBasic code, QB64 Phoenix Edition is the modern home: it is QuickBASIC-compatible, runs most legacy .bas programs unchanged, and compiles them to a native executable on Windows, macOS and Linux. For FreeBASIC source, the fbc compiler turns a .bas into a native binary from the command line (fbc program.bas). PureBasic and True BASIC compile their own dialects in their respective IDEs.

This is why “convert .bas to .exe” is a misnomer: it is a compile, not a file conversion, and there is no universal converter because each BASIC targets a different compiler. You must know the dialect first. A plain text editor, by contrast, will happily open any text .bas for reading or editing regardless of dialect, but it cannot execute it, editing and running are separate steps.

Source code is a program: the macro execution path

Reading a .bas in an editor is harmless, because a text file cannot do anything on its own. The caution is that a .bas is a program, and running or importing one executes whatever it contains. The concrete risk lives in the VBA case. A malicious .bas module imported into an Office document can hold macro code that runs when the document is opened and macros are enabled, using the VBA runtime to touch the filesystem, spawn processes or download further payloads. This macro-import path is a long-standing malware vector precisely because a .bas is small, text, and looks innocuous.

The defence is to read the source before you run or import it, and to never enable or import BASIC code from an untrusted sender. A classic compiled .bas game carries the same principle at compile time: compiling and executing an unknown program runs its code with your permissions. Viewing is safe; execution is a decision you should make only about code you have read or trust.

Frequently asked questions

I opened my .bas in Notepad and it’s gibberish. Why?

It is a tokenized binary GW-BASIC or QuickBASIC file, not text. BASIC keywords are stored as single bytes, which display as unreadable characters. Load it in the original interpreter or QB64 and re-save with the ASCII/text option to get readable source.

How do I run an old QBasic or QuickBASIC .bas today?

Use QB64 Phoenix Edition, a free, QuickBASIC-compatible implementation for Windows, macOS and Linux. It runs most classic .bas programs directly and can compile them to a modern native executable.

What is a .bas file in Excel or Office?

It is a VBA code module exported from the VBA editor, and it begins with Attribute VB_Name = "...". Re-add it to a workbook or document through the VBA editor’s File › Import File, which recreates the module and its macros.

References