Counter logic

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Counter logic

  • Creator
    Topic
  • #49049
    Manny Zachodin
    Participant

      Does anyone has a simple TCL code to initialize a counter file and then retrieve the next counter value (CtrNextValue).  I need to use the counter in xlate and believe that this is the only way to get a unique number by invoking a TCL proc from the pre-TCl box in xlate.

      Thank you for your generous contribution.

    Viewing 5 reply threads
    • Author
      Replies
      • #60562
        Rick Martin
        Participant

          Here’s the xlt script I use in an xlate; just pass in a counter name; it will create it if it doesn’t already exist.

          Code:


          # Name: xltCounter
          # Purpose:
          # UPoC type: xltp
          # Args: none
          # Notes: All data is presented through special variables.  The initial
          # upvar in this proc provides access to the required variables.
          #
          # This proc style only works when called from a code fragment
          # within an XLT.
          #

          proc xltCounter {} {
             upvar xlateId       xlateId
           xlateInList   xlateInList
           xlateInTypes  xlateInTypes
           xlateInVals   xlateInVals
           xlateOutList  xlateOutList
           xlateOutTypes xlateOutTypes
           xlateOutVals  xlateOutVals

             lassign $xlateInVals counterFileName

             set xlateOutVals [CtrNextValue $counterFileName]
          }

        • #60563
          Manny Zachodin
          Participant

            Rick. Thank you very much for the sample code.

          • #60564
            Manny Zachodin
            Participant

              Rick. I am getting this error in the test tool:

              Tcl callout error

              erroCode: NONE

              errorInfo:

              wrong # args: should be “upvar ?level? otherVar localVar ?otherVar localVar …?”

                 while executing

              “upvar xlateId       xlateId       “

                 (procedure “xltCounter” line 2)

                 invoked from within

              “xltCounter”

            • #60565
              Rick Martin
              Participant

                Are you running this in the XLT testing tool?  Should work fine.  The only thing different, is that I don’t pass the file extension (.ctr) to the proc, only the name portion (e.g. =siteCounter).

                Also, make sure there is no space after the backslash.

              • #60566
                Michael Hertel
                Participant

                  I’ve found with Xlate code in the past that you get into trouble cut n’ pasting from this forum into the proc.

                  The reason is that the “” at the end of those lines is really escaping a carriage return in the proc file and something is getting mangled during the cut n’ paste.

                • #60567
                  Manny Zachodin
                  Participant

                    Michael. You are absolutely right about the . I retyped the code and it works perfect. Thank to Rick for his code and you for your comments.

                Viewing 5 reply threads
                • The forum ‘Cloverleaf’ is closed to new topics and replies.