This example shows the extraction of data from MEMOx variables in an FS file generated by the CopiaFacts SMTP Gateway.  These memo fields normally contain the body text of the e-mail.

The example loops through up to 30 MEMOx fields in sequence, placing the variable name currently being processed into the variable CURVAR.  This value is then double-referenced to obtain the contents of the body text line in variable MDATA.

In this example, the memo fields contain a data code (one or two digits) followed by one space and then some text.  The text value is to be assigned to a variable FLDn where n is the data code.  The data code n is not necessarily the same as the MEMOx field number x.

You can replace the center section of this example with whatever processing you need for your own text lines.  The purpose of the example is really to demonstrate the use of loop variables and the extraction of data from a variable of which the name is formed by the script.  In this example the data is then placed into a different variable of which the name is also dynamically created in the script.

; Infobox getmemo

$type decision


$set_var MINDEX 1           ; index starts with 1

$repeat                     ; begin loop

  $set_var CURVAR "MEMO"    ; start with the field name base

  $set_var CURVAR |@MINDEX  ; append number to create MEMOx

  $set_var MDATA @^CURVAR   ; @^ gets content of the MEMOx variable

  $if @MDATA != @EMPTY      ; skip empty data lines

    $if @MDATA != " "       ; and those with just one blank space

      ; now process each text line in variable MDATA

      $set_var FLDNAME "FLD"      ; start with the field name base

      $set_var TMP @MDATA 2 1     ; get the second character of the line

      $if @TMP = " "              ; it's a single-digit data code

        $set_var NUM @MDATA 1 1   ; place single digit n value in NUM

        $set_var TXT @MDATA 3 50  ; and remainder in TXT

      $else                       ; it's a two-digit data code

        $set_var NUM @MDATA 1 2   ; place two-digit n value in NUM

        $set_var TXT @MDATA 4 50  ; and remainder in TXT


      $set_var FLDNAME |NUM       ; FLDNAME now contains "FLDn"

      $set_var @FLDNAME @TXT      ; note @FLDNAME assigns to var FLDn



  $set_var MINDEX +1        ; increment the number appended to MEMO

$until @MINDEX >= 30        ; loop for up to 30 MEMO items

$next_box usedata           ; go to use the data

Sample input and output

As a result of the processing above, an FS containing the variables:

$var_def MEMO1  " "

$var_def MEMO10 "5 Steve Hersee"

$var_def MEMO11 " "

$var_def MEMO12 "6 Copia International"

$var_def MEMO13 " "

$var_def MEMO14 "7 Steve Hersee"

$var_def MEMO15 " "

$var_def MEMO16 "8 11/15/2010"

$var_def MEMO17 " "

$var_def MEMO18 "9 Copia International"

$var_def MEMO19 " "

$var_def MEMO2  "1 Tim Frost"

$var_def MEMO20 "10 Hersee"

$var_def MEMO21 " "

$var_def MEMO22 "11 Steve"

$var_def MEMO23 " "

$var_def MEMO24 "12 A"

$var_def MEMO25 " "

$var_def MEMO26 "13 1302"

$var_def MEMO27 " "

can be converted into a different set of variables:

$var_def "FLD1" "Tim Frost"

$var_def "FLD10" "Steve Hersee"

$var_def "FLD11" "Steve"

$var_def "FLD12" "A"

$var_def "FLD13" "1302"

$var_def "FLD5" "Steve Hersee"

$var_def "FLD6" "Copia International"

$var_def "FLD7" "Steve Hersee"

$var_def "FLD8" "11/15/2010"

$var_def "FLD9" "Copia International"