Introducing MaxScript
and its DBL (Database Language) implementation


DBFree rely on MaxScript for all its scripting capabilities.

This is an example of MaxScript code:
alert("Welcome on board, today is " + fulldate())

This message box is generated by the code above: you can close it by clicking on the button here on the right.
Welcome on board, today is Friday 20 October 2017 - 21:52:05 GMT+1

MaxScript is a JIT (Just-in-time) compiler: all the web pages sent to it are processed before to be passed to users. This means that all the scripts contained in the page are executed on the server and the code they contain is never visibile to remote users.
This is known as server-side scripting.

To use DBFree at its best you should have a basic understanding of HTML.

This is a pre-requisites for today's programming in general, but to start to explore MaxScript you should also be familiar with the basic concepts of procedural programming.

The Programming paradigms

Those basic concepts can be summarized this way:


Procedural programming features an orderly flow of control through the program, starting at the top of the page and continuing through the end. When you need to carry out a discrete task, especially one that might be carried out multiple times, you pass the control to a function, which does a specific set of actions, and then returns a value.
BASIC, Pascal, and C are all examples of procedural languages. For instance, MaxScript itself is written in C.


In Functional programming each function is linked such that the output of one function feeds the input of the next. The behavior of the program depends mainly on input data. Functional languages do very well operating on lists, because functional languages excel at recursion, but are not a viable solution for web applications.
Examples of functional programming are Lisp, Haskell, Erlang, and F#.

The main difference among the two paradigms is that in procedural programming you describe how you want something to be done, whereas in functional programming you describes what you want to be done.

Object Oriented

Then we have the now ubiquitous OOP or Object Oriented Programming, where everything is done by the intermediation of objects, that are specific portion of code, usually consisting of two parts: data (also called members) and functions (often called methods).
Examples of object-oriented languages include C++, Java, and C#. And - of course - Javascript.

What language is best

There is no "best language" around. All depends by what you need to do (and what attitude you have).

All the languages mentioned before are intended for specific purposes, and trying to use them for a purpose other than what they were intended for leads to awkward code. Furthermore all of them are for universal use and for low level programming.
MaxScript instead is a specialized high level language (meaning that is written using one of the other languages and often called Metalanguage) designed for small business applications.
In facts all MaxScript code, once processed, is internally resolved to C functions then executed as such.
This allows you to use MaxScript instructions - much simpler and specialized - instead of having to learn the complex C language.

Procedural Vs rest of the world

An advantage of procedural programming for beginners is that once you learn a little of the syntax, you can follow the code and see what it’s doing just by reading off the screen. So if you are just starting to learn a language this is something not to undervaluate.
Furthermore MaxScript follows the path of its ancestor, the DBL language that was part of first versions of dBase, one of the easiest programming language ever appeared on the scene.
Matter of hours and you're in business.
Anyway to really learn to master MaxScript takes time and effort. Learning about control flow, along with loops and variables, is a breeze. Learning about managing data may be a little more complicated, but being strictly related with real world is intuitive.

Once you have just learned those basics you'll be ready to produce fully functional code.

Unfortunately knowing how to manipulate data and control the flow of a program is not enough: what you'll really want is to interact with your users. And you'll want to do that on the web.
MaxScript - as almost all other languages - does not offer much for this. In effects when we it comes to user interfaces - especially rich users interfaces - that's the job for HTML.

As many may tell you, HTML and other web standards were originally designed to provide layout for static, non-changing documents. Nowadays this has changed and with the introduction of HTML5 things have changed.

The separation of program logic from presentation logic is an important concern for software development. This is often referred as front end - back end programming.
It is usually difficult to determine where program logic ends and presentation logic begins. How the application is modeled dictates what is possible to do in the user interface. Sometimes the program and presentation logic is so intricate and dependent on each other that the two get intertwined with each other. MaxScript does not force you on how to proceed: separating the two is completely up to you as programmer. Anyway there are 3 consolidate techniques (CGI mode, Ajax mode, Mixed Mode), that mainly refer to different Programming Styles, that you can adopt to save time and efforts.

Programming styles

In writing MaxScript code you can adopt different styles:

(These topics are discussed in details in another specific document)

Front End programming

Early Web-based applications were simple and usually contained both presentation and program logic. Separating the two simplifies maintenance and development. Furthermore clearly separating presentation and logic when building server-side Web-based applications allows you to generate Web pages with dynamic content using simpler code:.

The front-end side
p( formStart(cSelf) ) //-- default target page is same page 
 p( well() ) 
 p( formField( "XY",, cSeed, "H") ) 
 p( formField( "VA",, "GO", "H") )  //-- action to perform (GO) 
 p( getStr("EF_NAME","Your name?",1,"Mary") ) 
 p( getNum("EF_AGE","Your Age?",0, 44) ) 
 p( startRadio() ) 
   p( radiobutton("EF_GENDER","Male") ) 
   p( radiobutton("EF_GENDER","Female",1) ) 
 p( endRadio() ) 
 p( formSubmit() ) 
 p( well(0) ) 
p( formEnd() ) 
The back-end side:
cName := mspfieldvalue("EF_NAME")
nAge  := val(mspfieldvalue("EF_AGE"))
cGender :=  mspfieldvalue("EF_GENDER")
if nAge < 18
   p( alert("Sorry! You must be 18 or more.") )
An example of separation:
function doSomething( cUser,cType)
use "meetups" index "meet_users" key USR_NAME
cFilter := iif(cGender="M","F",cGender)
set filter to GENDER=cFilter and DATEDAY date()+7
go top
do listRecords()
return %>

Separation can be done easily by using as front-end one page for the presentation (usually containing one or more web forms) and another one (the back-end) for the program logic.

The latter is called actuator or response page and must contain the appropriate code for manipulating the incoming data entered by user. Response page usually take care of presenting the responses and further manipulations.

MaxScript calls this methodology CGI model.
CGI mode an be adopted either in Classic or ASP style: in this case the resulting style takes name of Mixed mode.

Within this document we will cover almost only the mixed mode, which is generally considered to be more productive.

Creating a Web Application

Within this approach - the Mixed mode - creating a web application consists mainly into creating a web site (the Front End) and then providing the necessary automation (the Back End logic).

Mind you, this way the development workflow you are used to for creating a web site remains the same while creating web applications. The step of turning an existing website into a MaxScript application is basically a matter of copy and paste. DBFree is an all-made container that will just swallow your web site: once that the pages look as you wanted (including hyperlinks and images) you can start inserting the necessary program logic (i.e. writing the actuator pages).

For those who have used WampServer, Xamp or EasyPhp, it won’t be a problem to understand the concept. When you are using these local servers, you usually create your projects into a particular folder called www, htdocs, or localweb. It differs from one server to another, but the concept remains the same. That particular folder helps your web server to know where to run your application (website) from.
For DBFree this folder, referred from now on as the WEB Root, is: <drive>\maxsis\dbfreev41\web

So, to start developing your web application just start creating files and build your web site into this folder.

Of course this is just a simplified presentation of the topic for which we address you to specific publications which can be found in other sections of this site
Top of page