Making HTML documents

From CometWiki

(Difference between revisions)
Jump to: navigation, search
Badge (Talk | contribs)
(New page: '''Making HTML documents''' Signature Systems recently added HTML output capability to The Reporter and the Comet Print Spooler. This tip shows how to add the same capability to your Come...)
Newer edit →

Revision as of 11:04, 26 May 2009

Making HTML documents

Signature Systems recently added HTML output capability to The Reporter and the Comet Print Spooler. This tip shows how to add the same capability to your Comet applications.

In the following steps, we explain the details of how to make and launch an HTML document from an MTB program. Here’s a quick summary of these steps:

·         Create a text file with an extension of “HTM”
·         Write the basic HTML tags to the text file
·         Write your output data to the text file
·         Launch the text file (which is interpreted by the Windows as an HTML file)
·         Erase the text file

Here is a detailed description of these steps, along with the matching MTB code:

Description MTB code
Create a text file where you will be writing the HTML tags and your lines of data.

In this example, we’ve named the file SAMPLE.HTM. The HTM extension is essential; when your program launches this file, Windows uses that extension to run the default web browser.

FILENAME$ = “SAMPLE.HTM”

DIR$ = “TMP”

CREATE FILENAME$,DIR=DIR$

Open the text file. OPEN (20) FILENAME$,DIR=DIR$
Write the initial HTML tags to the text file. These tags define the document type, the heading section, and the start of the document title. PRINT (20) “<HTML>”

PRINT (20) “<HEAD>”

PRINT (20) “<TITLE>”

Write a title line to the text file (when the HTML document is launched, this text is displayed as the title line in the web browser window). PRINT (20) “Sample title line”
Write these tags to the text file. They conclude the title and head section of the HTML document. PRINT (20) “</TITLE>”

PRINT (20) “</HEAD>”

Write the BODY tag to the text file. This marks the start of the main section of the document.


Note: the BODY tag can also include a parameter to specify background color or background graphic if desired. Refer to some HTML documentation for more information

PRINT (20) “<BODY>”
Write the PRE tag to the text file. This tag begins a section of pre-formatted text in the HTML document (i.e., when the web browser sees this tag, it will not apply word wrap to the following lines of text). This can be ideal for displaying data from an MTB program. PRINT (20) “
”
|- 
|Write your data lines, as desired, to the text file.
 .

.

.

|PRINT (20) DATA$

.

.

.
 
|When your data has been written, write the concluding HTML tags to the text file.

 

Your text file is now a complete HTML file.
| PRINT (20) “

PRINT (20) “</BODY>”

PRINT (20) “</HTML>”

Close the text file. CLOSE (20)
Construct the full HTML document name by appending the filename to the path.


Then, launch the HTML document.

HTMLDOC$ = PATH(DIR$) + FILENAME$


PRINT (0) (LAUNCH=HTMLDOC$)

Wait to make sure that the HTML document has been launched (in this example, we pause 2 seconds), and then erase the text file.


Note: If you erased the HTML file immediately after launching it, it’s possible that the file would be erased before the web browser was able to display it. Therefore, it makes sense to wait before erasing the file.

PAUSE(36)


ERASE FILENAME$,DIR=DIR$



Launching on a CometAnywhere system


The above example assumes that your program is running on the same machine where the web browser is located. But, what about a remote Comet Anywhere user? How can you launch an HTML document on a remote system?


The solution is easy. You can use the VerifyFile mnemonic to send the HTML document from the host system to the remote system, and then use the Launch mnemonic to launch the file on the remote system.


The following MTB code demonstrates how to do this. By the way, this code segment is contained in The Reporter’s ~RPGUSE usefile, starting at line 36200.


Description

MTB code

Construct the full HTML document name by appending the filename to the path (same as above).

HTMLDOC$ = PATH(DIR$) + FILENAME$

Determine if the session is a CometAnywhere session by examining the 21st byte in the DSTAT for TERM$.


If this is not a CometAnywhere session, skip ahead to the LAUNCHFILE label.

FLAG$=SUB(DSTAT(TERM$),21,1)


IF SUB(BINARY(FLAG$),8,1) NE "1" THEN GOTO LAUNCHFILE

Construct the name for the HTML file on the remote system. This name consists of the directory alias $(CATOOLS), the subdirectory HTMLTEMP, and the text filename.

REMOTEDOC$="$(CATOOLS)\HTMLTEMP\"+FILENAME$

Use the VerifyFile mnemonic to transfer the text file from the host system to the remote system.


The 3rd parameter is a flag whose value is the sum of the chosen options. In this example, 24 is the sum of “always send file” (8) and “create alias if required” (16).

PRINT(0) (VerifyFile=HTMLDOC$,REMOTEDOC$,24)

Move the remote filename to the HTMLDOC$ variable.

HTMLDOC$ = REMOTEDOC$

Launch the HTML document.

LAUNCHFILE:

PRINT (0) (LAUNCH=HTMLDOC$)

Wait to make sure that the HTML document has been transferred to the remote system (in this example, 6 seconds) and launched, and then erase the text file.


Note: The ERASE statement erases the file on the host system only. There is no Comet instruction to erase the file on the remote system. Therefore, the remote user will have to manually erase the HTML file when it is no longer needed.

PAUSE(108)


ERASE FILENAME$,DIR=DIR$




Here is the complete MTB source program for this example.

Personal tools