PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
<?Data:DataName.RowNumber[.ColumnNumber]> |
This symbol provides a simple mechanism to retrieve the information previously saved using the #data command. The rexx function DataInfo() can also be used.
This command can return the following types of information:
The "DataName" parameter simply defines the name of #data collection.
The second and third parameters determine the type of query as follows (checked in order):
If both "RowNumber" and "ColumnNumber" are "" (empty or missing) then the symbol returns "" (empty string) if the structure does not exist. If it exists the location where it was defined is returned.
If "RowNumber" is "?" then the number of rows in the structure is returned.
If "ColumnNumber" is "?" then the number of columns per row in the structure is returned.
Note that it is possible for this value to be 0 if no rows of data existed and you did not specify the correct count on the #data command.
Both "RowNumber" and "ColumnNumber" should be integers or rexx variables containing integers. The specified item is returned. PPWIZARD aborts if it does not exist.
If the data can contain symbols requiring expansion then you probably need to use <?RestartLine> for the expansion to occur.
This is a Standard Definition which always exists (you don't need to #define it). Note that you can create your own variations or completely new ones (see the examples).
Example - #Import to a Table |
In this example the data comes from a database (#import):
;--- Import the information (store in memory) --- #NextId #define IMPORT_#DATA TmpCsv ;;Import to memory #( #import "SomeCommaSeparatedFile.CSV" CMA "" "EmailAddress" ;;CSV Field #1 "Name" ;;CSV Field #2 "HomePage" ;;CSV Field #3 #) ;--- Start a table and output heading line ------ <table border=1> <tr> <th>Name</th> <th>Email<br>Address</th> <th>Home<br>Page</th> </tr> ;--- Output the imported records ---------------- #{ FOR @@Record = 1 to <?Data:TmpCsv.?> ;--- Is this an EVEN or ODD row? ------------- #if @@Record // 2 = 0 ;;Can use CSS (stylesheet) to alternate background color etc #define+ TrClass EVEN #elseif #define+ TrClass ODD #endif ;--- Start row (set class to "EVEN/ODD") ----- <tr class='<$TrClass>'> ;--- Output Name -------------------------- <td><?Data:TmpCsv.@@Record.2></td> ;--- Output email address ----------------- <td><a href="mailto:<?Data:TmpCsv.@@Record.1>"><?Data:TmpCsv.@@Record.1></a></td> ;--- Output homepage ---------------------- <td><a href="<?Data:TmpCsv.@@Record.3>" target="_blank"><?Data:TmpCsv.@@Record.3></a></td> </tr> #} ;--- End the table ------------------------------ </table>
Example - #Data |
In this example the data comes via the #data command:
;--- Define three rows --- #data Fred 3 ;--- Row 1 --- "1a" "1b" '1c' ;--- Row 2 --- #( ' ' ~2a~ @2b@ /2c/ #) ;--- Row 3 --- #if [1 = 1] '3a t' '3b t' \ "3c t" #elseif '3a f' '3b f' \ "3c f" #endif ;--- "import" some more rows --- #include "MoreRows.DB" #data ;--- Use the values (PPWIZARD) --- #if ['<?Data:Fred>' = ''] There is no #data structure called "Fred"! #elseif There are <?Data:Fred.?> rows of data each with <?Data:Fred.*.?> columns. <?NewLine> "Fred" was defined at <?Data:Fred>. #{ FOR @@X = 1 to <?Data:Fred.?> <?NewLine> === Row <??@@X> of <?Data:Fred.?> === <?Space> * Col 1 = <?Data:Fred.@@X.1> <?Space> * Col 2 = <?Data:Fred.@@X.2> <?Space> * Col 3 = <?Data:Fred.@@X.3> #} #endif ;--- Display the values (REXX) --- #DefineRexx '' do @@X = 1 to Fred.0 call Say '' call Say '=== Row ' || @@X || ' of ' || Fred.0 || ' ===' call Say ' * Col 1 = ' || Fred.@@X.1 call Say ' * Col 2 = ' || Fred.@@X.2 call Say ' * Col 3 = ' || Fred.@@X.3 end; #DefineRexx
Example - #Import (one HTML page per record) |
In this example the data comes from a database (#import):
;--- Import the information (store in memory) --- #NextId #define IMPORT_#DATA TmpCsv ;;Import to memory #( #import "SomeCommaSeparatedFile.CSV" CMA "" "EmailAddress" ;;CSV Field #1 "Name" ;;CSV Field #2 "HomePage" ;;CSV Field #3 #) ;--- Create a HTML page per CSV record --- #{ FOR @@Record = 1 to <?Data:TmpCsv.?> ;--- Collect Information to be passed to the #included file --- #define+ CSV_NAME <?Data:TmpCsv.@@Record.2> #define+ CSV_EMAIL <?Data:TmpCsv.@@Record.1> #define+ CSV_WEBPAGE <?Data:TmpCsv.@@Record.3> ;--- Now create the HTML page (inline - would normally use #include) --- #output "out\CSV_<$CSV_NAME>.htm" ASIS <html> <head> <title>BASIC page for "<$CSV_NAME>"</title> </head> <body> ;--- Heading ------------------ <center><h1>BASIC page for "<$CSV_NAME>"</h1></center> ;--- Page body ---------------- <p><$CSV_NAME> has an email address of "<$CSV_EMAIL>" and a web address of "<$CSV_WEBPAGE>". ;--- Footer ------------------- <hr size=1 color=red> <center><?CompileTime><br><$CSV_NAME></center> </body> </html> #output #}