File Templates

A file template is the framework for a new file, which you can load into the IDE with the "New File As…" option.  While a template can contain anything you like, it is typically used to automate the basic boilerplate needed for a new document.  For example, the "Generic PB program" template creates a new file with the following information already filled out:

#COMPILE EXE

#DIM ALL

 

FUNCTION PBMAIN () AS LONG

 

   

 

END FUNCTION

What's more, the caret is conveniently placed in the middle of the FUNCTION block for you, letting you get right to programming!

You can readily build templates of your own, or modify the ones that come with the IDE.  A template is simply a text file created according to a few simple rules.  Let's look at the default template (you can load it into the IDE, NotePad, or any other text editor).  PowerBASIC templates use ".PBTPL" for their file extension.  The default template is "Default.pbtpl", then.  You can find it in the Bin subdirectory for your compiler ("C:\Program Files\PBWin10\Bin", by default).

The first line starts out with a number:

2

This is the template version number, 2 (two).  Version 1 (one) templates are still supported.

The second line contains the target. The target may be PBCC, PBWIN, or CCWIN. If it is CCWIN, any following lines that start with [PBCC] are used for PB/CC, any lines that start with [PBWIN] are used for PB/Win, and any lines without a [target] apply to both compilers.

The third line contains the file extension to apply to files that are created with this template:

.bas

The fourth and fifth lines gives the name of the template, which will be used in the "New File As…" menu:

[PBCC]Console program

[PBWIN]Generic PB program

The following lines give the text to be filled into the file created by the template.  There is one special character, the "|" vertical bar or pipe symbol.  This indicates where the caret should be placed after the text is filled in.

#COMPILE EXE

#DIM ALL

 

FUNCTION PBMAIN () AS LONG

 

    |

 

END FUNCTION

That's all there is to it!

After creating a new template, save the .PBTPL file in the Bin subdirectory for your compiler.  The default location for this is, typically, "C:\Program Files\PBWin10\Bin\".  Now, the next time you start the PowerBASIC IDE, your custom template will be available on the "New File As…" menu.

 

See Also

The Integrated Development Environment

Project Files