Problem Creating a Variable in xlate

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Problem Creating a Variable in xlate

  • Creator
    Topic
  • #52877
    Tim Pashon
    Participant

      I’m having a problem creating a variable in my xlate.  I put the @ in from of the word and when I go to use it in the next statement, it isn’t in the variable list when I right click in the source box.

      Help?

    Viewing 8 reply threads
    • Author
      Replies
      • #75760
        Jim Kosloskey
        Participant

          Tom,

          Even though it is not in the pull down it is probably usable (you just have to type it in).

          Certain Cloverleaf releases had that issue that when you are in the same Xlate configuration session and build a temp variable then try to use it the pull down list is not imeediately updated.

          I have found that if you save and close the Xlate then open it again the temp variable will be in the pull-down (or you can just type it n or copy/paste it as I indicated earlier).

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #75761
          Tim Pashon
          Participant

            It worked.  Thanks Jim.

            I had another issue that was causing an error that I thought the variable was causing.  I need to truncate a field to 10 characters and that field may contain a space.  I know the xlateInVals, xlateOutVals is a list but I’m new enough that I don’t know how to manipulate that list.

            Input – Milk Products

            Desired Output – Milk Produ

            How can I do this?

          • #75762
            Jim Kosloskey
            Participant

              Tim,

              I think I have a proc you can use for that and if you email me we can discuss your situation.

              email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

            • #75763
              Robert Kersemakers
              Participant

                This should do the trick (I put in some extra comments to make it understandable):

                Code:

                # assign all the incoming values to a variable;
                # here only one variable is assigned: ‘field’
                lassign $xlateInVals field
                # truncate ‘field’ to first 10 characters
                set field [string range $field 0 9]
                # set the outgoing values; make sure it’s a list of values
                # even if there’s only one value!
                set xlateOutvals [list $field]

                Or if you want it all in one line:

                Code:

                set xlateOutVals [list [string range [lindex $xlateInVals 0] 0 9]]

                Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

              • #75764
                Robert Denny
                Participant

                  in this example can you explain what the 0 after the $xlateInVals mean?

                • #75765
                  bill bearden
                  Participant

                    There is a [lindex $xlateInVals 0] or something like that.

                    The 0 tells the lindex command which list element to return. It is saying, give me the first element of the list, xlateInVals.

                    Something that is not obvious, and much (almost all?) of the time doesn’t matter, is that xlateInVals is a list. It can have multiple values. It is a very good habit to get into to always use lindex to get the input value in a Tcl frag in an xlate. You’ll eventually learn the hard way, if you don’t. Sooner or later, you’ll tear your hair out trying to figure out what the heck your Tcl frag is doing.

                    xlateOutVals is also a list. It is also a good idea to always set xlateOutVals with the list command.

                  • #75766
                    Robert Denny
                    Participant

                      by first element do you character in the string or is the element considered the whole string.

                      I was able to get to work, but I was curious about if tha 0 means the first element in as string. i.e. 12324 does the 0 represt the 1 or all five digits?

                      So if I want to skip the 1 of the string I could start with at setting a 1 instead of 0.

                    • #75767
                      Chris Williams
                      Participant

                        In a tcl list the first element is referred to as “0”. Think of it not as the element number, but rather as the OFFSET from the beginning of the list. The first list item is not offset from the beginning. The second list item is offset from the beginning of the list by 1.

                        Code:

                        given the list tclList “{color red} {color green} {color blue}”
                        [lindex $tclList 0] –> color red
                        [lindex $tclList 1] –> color green
                        [lindex $tclList 2] –> color blue

                      • #75768
                        Robert Denny
                        Participant

                          thanks that helps clear up the confusion I was having with those commands.

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