11.1 Writing a Module

Let's create a module to see how they work. In a large application, the most common task is generating the common look and feel HTML for each page. Since many applications need to share such code, and it may change over time, it's a good candidate for a module:


  <SCRIPT LANGUAGE=vortex>

  <A NAME=look EXPORT title>
    <HEAD><TITLE>$title</TITLE></HEAD>
    <BODY BGCOLOR=white>
    <H1>$title</H1><P>
  </A>

  <A NAME=/look EXPORT>
    <P><HR>
    Back to <A HREF="$url/">home page</A>
    </BODY>
  </A>

  </SCRIPT>

We declared a look function to generate the entry HTML for a page. It takes a title as a parameter. Similarly, the /look function generates the bottom or exit HTML, with a link back to the home page.

The first thing to note about this script is the absence of a main function. We don't need one because this script won't be run as a standalone application: its functions will be included into other scripts. Indeed, if we try to run this script as usual, we'll get an error saying there's no main function. We left it out because this is not our main application.

Also, we've declared the scope of these functions as EXPORT . This means that other scripts can see them, but the user (from the browser) cannot directly call these functions; they are private to the application. We want to control when and how these functions are called: since they're only used by other functions, the user should never directly call them.

We can turn this script into a module by inserting it into the library (next page):

Back: Vortex Library Modules Next: Inserting a Module
Copyright © 2024 Thunderstone Software LLC. All rights reserved.