Using an External Text Editor With QB45

I previously wrote how I had been inspired to use the methods found in Issue #2 of QB Express to liberate QB from DOS. Since that time I have stopped thinking of liberating QB and started thinking of ways to enhance the QB experience. In this article I describe how I write, compile, and run QB programs within a WindowsXP environment.

The first thing you need to decide on is what text editor you want to use as a programming environment. For the last few years I have used Crimson Editor almost exclusively, but a few days ago I switched to Programmer's Notepad. Both text editors can be configured to do everything I describe in this article. Each editor has features not found in the other. It is up to you to choose your programming environment, but for the sake of this article I will be using Programmer's Notepad (PN).

In PN, create a text file and type the following line of code:

PRINT "Hello, Windows!"

Save this as "hello.bas" anywhere on your computer. Now we have created QuickBASIC source code in our editor, but what can we do with it?

Press Ctrl+N to create a new document. Type (or copy and paste) the following text into the new file:

Save this file as "compileMaker.bat". I recommend saving it to your QB install folder. Make sure you change the paths in this batch file so they are correct on your system.

This batch file creates another batch file in your .BAS file's directory. This new batch file will be used to compile your code.

Before we can use this batch file we will need to create a tool to pass our file name and path to compileMaker.bat. In PN, click Tools>Options. A new window should pop open. In this, the Options window, select Tools and then click the Add button you see on the right.Yet another window will open.Make the window look like this:Make sure that the Command section of this tool contains the full path, file name, and extension to compileMaker.bat. You can click the button to the right of the field to browse to the file. You can choose whatever shortcut keys you like.

In this window click the Console I/O tab and make sure the Capture output checkbox is un-checked.Now click on OK in the tool properties window and then the OK in the Options window.

If you click on Tools you should now see your new tool. Every time you create a tool for .BAS files, it will appear here.With our hello.bas file selected in PN, run the Create compile%1.BAT tool. A console window should pop open:If you needed to send command-line options to BC, this is where you would type them. Since hello.bas only has a print statement, just press return.

Running this tool creates a batch file in the same directory as our code. If we run that new batch file we can compile our code into an executable. One way of running batch files is to navigate in Windows explorer to the file and double click it. Another way of running the file is to set up a user tool.

@ECHO OFF
REM Pass the file title into this batch to compile.
:: If there's no COMPILE%1.BAT...
:: Make the COMPILE%1.BAT
IF NOT EXIST COMPILE%1.BAT CALL C:\QBasic\compileMaker.bat %1
:: Compile our .BAS file
CALL COMPILE%1.bat
PAUSE

Save This file in your QB install folder as "batchCompile.bat". Make sure the path to compileMaker.bat is correct for your computer.

Now run your new tool (find it in the Tools menu or use your hotkeys). If all went well you should see a prompt like this:What this means is you just compiled a QuickBASIC program!

To run the program, we will make yet another tool. In PN, click Tools>Options and make the options window look like this:Make sure the command portion of the tool points to your QB install folder. Again, on the Console I/O tab, de-select the capture output option. Click OK then OK again.

Back in PN, press Ctrl+N and enter the following text:

@ECHO OFF
CLS
PROMPT
COLOR 1F
TITLE "%~N1" IS NOW RUNNING...
REM Use this simple batch to run command-line programs
REM from explorer and programming editors.
REM Pass into it the full path with file name and extension.
CALL %1
ECHO.
ECHO.
PAUSE

Save this as CommandLineExecutor.bat in your QB install folder.

In PN, select hello.bas again and use your newest tool to run your compiled program:

Two IDE's Are Better Than One
(this part of the page first published HERE)

In my last article I showed how to use Programmer's Notepad with BC.exe (the QuickBASIC compiler). Some people might have gotten the impression I was trying to do away with the QuickBASIC IDE. That's just not true! I have chosen to see QuickBASIC as a programming language that happens to have an IDE. The QB IDE has a built-in help system and advanced debugging tools (tools that do not work in WindowsXP). It also has a cumbersome text editor that is difficult or impossible to use on many current computers. This is especially true for my laptop.

Luckily, the QuickBASIC IDE can be set to save and open QB projects as plain text. These plain text files can be opened, modified, and saved by modern text editors. Using a combination of QB.EXE and modern text editors, working in tandem, you can significantly increase productivity on newer computers. This is especially true for large, multi-file QB projects. Then there are advantages in terms of memory and performance, but I'll get into that some other day.

The previous article was an introduction to using Programmer's Notepad(PN) along with BC.EXE. In this article I will introduce the idea of using PN with QB.EXE.

With a BASIC file open in QB.EXE, select File>Save AsA new window will openIn the Format section, select the option marked Text - Readable by Other Programs and click OK. Save your BASIC file.

In PN, you can now open the very same BASIC file for editing.

There are many differences between the QB IDE and PN. PN can make organizing, editing, and compiling multifile QB projects easier. You can also have each file of a multiple module program open in its own tab. There are also some advanced features, including user tools and macros written in Python, which allow you to do things in PN that you cannot do in QB.EXE.

PN will not check your code as you write it the way QB does (I'll work on that later), but PN has autocomplete functionality. Just start typing and you will see a list of words that you might use.

Another cool feature is code folding. To get an idea of what code folding is, look at this code:And now look at the same code after it's folded:You see here a program with 141 lines of code can fit in a small space if it's all folded up. Each section of code can be folded or unfolded or all code can be folded or unfolded.You may also notice that as you type, your text changes color. This is called syntax highlighting. It makes reading code easier. The words recognized by autocomplete and syntax highlighting can be adapted to suit your needs.

If you look around PN, you will find many more useful features. There are windows for projects, tags, and scripts. PN also allows users to create macros and user tools. Of all these features, we will just be looking at user tools in this article.

With your BASIC file open in PN, select Tools>Options and then make sure Tools is selected on the left. Press the Add button. Make the next window that opens look like this:Make sure the path to QB.EXE is correct. Press OK and then OK again. Press your hotkeys to use the tool. You should now see your code opened in the QB IDE. You can use all the tools of the QB IDE (if you are on an older system) and save the file. When you go back to PN you will see this popup:If you want to keep the changes you made to your code in the QB IDE, choose Yes. Your updated code will appear in PN.

If you would like to have QB.EXE interpret the code you are working on in PN, you can do that as well.

With your BASIC file open in PN, select Tools>Options and then make sure Tools is selected on the left. Press the Add button. Make the next window that opens look like this:
Again, make sure the path to QB.EXE is correct on your computer. Press OK and then OK again. Press your hotkeys to use the tool. You should now see your code interpreted by the QB IDE. If there are errors in your code, the IDE will let you know with a message like this:If there are no errors your code will execute. When finished, your code will be opened in the IDE.

NOTE: If you do not want your interpreted program to exit to the QB IDE, make your code end with the keyword SYSTEM.

One nice thing about using PN for a programming environment is how easy it is to create and use simple tools as you need them. In this article I will walk you through the creation of a programming tool that will allow you to insert a SUB or FUNCTION while working with .BAS files in PN.

Open a new document in PN and type (or copy and paste) the following text into the file:

Save this as subShop.bat in your QB install folder. This file inserts a SUB or FUNCTION into whatever BASIC code you are working on.

To use it we will have to associate it with a tool in PN.

Press Ctrl+N to open a new document. Save this document anywhere on your computer as BLT.BAS.

Click Tools>Options and then select Tools and click the Add button. Make your new tool look like this:On the Console I/O tab, make sure the first two checkboxes are NOT checked. Click OK and then OK again.

In your empty document write the line:PRINT "I love ";

And then select Tools>Add SUB or FUNCTION.

Into the command prompt that appears type SUBand press Enter.

For the next prompt enter BLTand press Enter.

At the next prompt type BACON$, LETTUCE$, TOMATO$and press Enter.

Inside the SUB, in place of the comment line, type this code:PRINT BACON$; LETTUCE$; TOMATO$;

DISCLAIMER!

By accessing this web site you agree to the following:

All copyrights on abandoned programming platforms are sketchy. Anything you find on this site is not copyrighted unless otherwise stated. If you use anything from this site you should give proper credit.

All code and other information on this site is offered as is without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability, magical efficacy, or fitness for a particular purpose or unparticular purpose. The author assumes no liability for any alleged (or actual, I guess) damages arising from the use of any information contained in this site.

If your computer freezes, burns, or casts any other level 2 spell, please call a cleric. The 16bit binary bindrune found in this site's header was placed as a jest, but now it cannot be removed or undone. Sorry about that. Not too sorry though, since it only seems to affect trolls.