Loading ...
Sorry, an error occurred while loading the content.

Process variable versus document ^!Replace also is Writing Subroutines in Notetab.

Expand Messages
  • Alan_C
    ... [ . . ] ... As Don said, the find and replace command is for doc only, not works, not used, on a variable. [ . . ] ... AFAIK the ^!Clip must be it s own
    Message 1 of 7 , Apr 12, 2006
    • 0 Attachment
      On Wednesday 12 April 2006 08:49, Bob Gorman wrote:
      > Don,
      > At Wednesday 04:07 PM 3/8/2006, you wrote:
      >
      > Charles M. Raine wrote:
      [ . . ]
      > Originally, a long time ago, I wrote a clip which does exactly what I want
      > it to do, but it does it to text that is selected in a document. I now want
      > it to do it to the contents of a variable.
      >
      > Original Clip:
      > H="Me --> you"
      > ^!Replace "me" >> "you" HISA

      As Don said, the find and replace command is for doc only, not works, not
      used, on a variable.

      [ . . ]
      > My attempt to use this clip on a variable instead of selected text:
      > H="Reverse Ans"
      > ^!Set %Ans%=^?[(T=W)Answer=]
      > ^!Set %rAns%=^!Clip "Me --> you" ^%Ans%

      AFAIK the ^!Clip must be it's own command, thus:

      ^!Clip "my_called_clip"

      and it accepts no additional parameters (in the above, you have ^%Ans% as an
      additional parameter trying to pass to it)

      merely, all the ^!Clip does is launch another clip, a so called "child" clip
      if you will (really, probably its only purpose is to aid organization of
      code, reuse code as in similar to a function that might be called multiple
      times from within the same clip. modularity of design -- function here,
      function there, "plug" (not totally unlike "plugin") those various functions
      together as one using ^!Clip -- , not at all unlike the "glue" that binds
      various _______'s all together as one unit.

      if the same function is used in 7 different clips in a clip library, why
      enclose that function's code repeatedly 7 times in the library when you can
      instead have it only once in the library and use ^!Clip to call it from
      within each of the 7 clips that need that particularprocess/functionality.

      it's not really a child clip but child is merely a term since it is a so
      called "called up" clip, a clip that is called from within the main clip.

      ^!Append holds, ^!Set executes

      that is to say you can append to var and then later on, set the var which in
      turn executes

      (you were executing because you used set)

      but read help on append! be sure to use clearvariable(s) !!!

      it's rare that, append a command and then later on, set it

      looks like, what you want to do, you'll need to temporarily dump to scratch
      doc like Don mentioned.

      --
      Alan.
    • Bob Gorman
      Don & Alan, Thank you both. I knew I could as you both suggest create a new document and do the work there, but it just seemed like there might be a more
      Message 2 of 7 , Apr 12, 2006
      • 0 Attachment
        Don & Alan,

        Thank you both.
        I knew I could as you both suggest create a new document and do the work
        there, but it just seemed like there might be a more elegant way.

        Oh, well, I guess the most elegant solution is the one that actually works!

        Thanks,
        Bob

        >As Don said, the find and replace command is for doc only, not works, not
        >used, on a variable.


        >^!Append holds, ^!Set executes
        >that is to say you can append to var and then later on, set the var which
        >in turn executes
        >
        >(you were executing because you used set)
        >but read help on append!

        I will.

        Don,
        >There are two solutions:
        >1. create a scratch document and paste the variable to it, perform the
        >search on that and then replace the variable with the result, or
        >2. use string replace:
        >^$StrReplace("SubStr";"ReplaceStr";"Str";CaseSensitive;WholeWord)$
        >Returns a new string with all occurrences of SubStr replaced with
        >ReplaceStr according to the settings of the CaseSensitive and WholeWord
        >parameters. Tab and line-break tokens are automatically converted to
        >their real characters since version 4.6. Example:
        >^$StrReplace("o";"?";"NoteTab Pro";True;False)$ -> N?teTab Pr?

        Thanks,
        Bob

        You need only two tools in Life: WD-40 and Duct Tape.
        If it doesn't move and it should, use WD-40.
        If it moves and shouldn't, use the duct tape.


        [Non-text portions of this message have been removed]
      • Bob McAllister
        ... Bob What you are hoping to do is certainly possible using a custom function so long as you switch from Replace to StrReplace. Here are your clips reworked.
        Message 3 of 7 , Apr 12, 2006
        • 0 Attachment
          On 4/13/06, Bob Gorman <bgorman@...> wrote:
          >
          > I've also been experimenting with this, but I'm not quite successful as yet. I may be missing something very basic about Clips, and what they operate on.
          >
          > Originally, a long time ago, I wrote a clip which does exactly what I want
          > it to do, but it does it to text that is selected in a document. I now want
          > it to do it to the contents of a variable.
          >
          > Original Clip:
          > H="Me --> you"
          > ^!Replace "me" >> "you" HISA
          > ^!Replace "I was" >> "you were" HISA
          > ^!Replace "I'm" >> "you're" HISA
          > ^!Replace "I" >> "you" HISA
          > ^!Replace "myself" >> "your self" HISA
          > ^!Replace "my" >> "your" HISA
          > ^!Replace "mine" >> "yours" HISA
          > So if I select:
          > I love my life.
          > it changes it to:
          > you love your life.
          > Perfect!
          >
          > My attempt to use this clip on a variable instead of selected text:
          > H="Reverse Ans"
          > ^!Set %Ans%=^?[(T=W)Answer=]
          > ^!Set %rAns%=^!Clip "Me --> you" ^%Ans%
          > Original:
          > ^%Ans%
          > Reversed:
          > ^%rAns%
          >
          > The first command works fine and assigns the text to %Ans%.
          > The second line sets the variable %rAns% to the text of my clip :-(
          >

          Bob

          What you are hoping to do is certainly possible using a custom
          function so long as you switch from Replace to StrReplace.

          Here are your clips reworked.

          H="m2y"
          ^!Set %trans%=^$StrReplace("me";"you";"^&";0;1)$
          ^!Set %trans%=^$StrReplace("I was";"you were";"^%trans%";0;1)$
          ^!Set %trans%=^$StrReplace("I'm";"you're";"^%trans%";0;1)$
          ^!Set %trans%=^$StrReplace("I";"you";"^%trans%";0;1)$
          ^!Set %trans%=^$StrReplace("myself";"yourself";"^%trans%";0;1)$
          ^!Set %trans%=^$StrReplace("my";"your";"^%trans%";0;1)$
          ^!Set %Result%=^$StrReplace("mine";"yours";"^%trans%";0;1)$

          H="Call m2y"
          ^!Set %Ans%=^?{Text to be manipulated}
          Original:
          ^%Ans%
          Reversed:
          ^$m2y(^%Ans%)$

          Note that when a custom function (in this case m2y) is called by
          another clip, any parameters passed come in identified as ^&. So that
          is the string on which the first StrReplace acts. The variable %trans%
          is one i created to make the cascade through seven string replacements
          manageable. If you are better at counting brackets than I am, you
          could put them all in a single line nested seven deep (and avoid the
          use of %trans% entirely). The 0;1 parameters at the end of the line
          are to make the replacement case insensitive but whole words only.

          The key to using a custom function is to assign the output to the
          special variable %Result%.

          When calling the custom function (or sub-routine) you do not need to
          use the ^!Clip command (even though you are calling a clip). When
          NoteTab does not recognise the function name ^$m2y()$ it looks for a
          clip m2y in your current library and starts it.

          So the line ^$m2y(^%Ans%)$ is doing all the work. It takes the current
          value of %Ans% and passes it to the m2y clip (as ^&). Then when the
          subroutine ends, that line has the value held in %Result% which is
          printed into the current document.

          So you get
          Original:
          I was lost but now I'm found.
          Reversed:
          you were lost but now you're found.

          I hope this helps. Custom Functions really do give you enormous power
          to create sub-routine-like structures in clips. It is certainly worth
          persevering.

          Bob McAllister
        • Bob McAllister
          ... While continuing to tinker with my two clips, I thought it might be useful to show how they work as one and so demonstrate the advantages of converting a
          Message 4 of 7 , Apr 12, 2006
          • 0 Attachment
            On 4/13/06, Bob McAllister <fortiter@...> wrote:
            >
            > Note that when a custom function (in this case m2y) is called by
            > another clip, any parameters passed come in identified as ^&. So that
            > is the string on which the first StrReplace acts. The variable %trans%
            > is one i created to make the cascade through seven string replacements
            > manageable. If you are better at counting brackets than I am, you
            > could put them all in a single line nested seven deep (and avoid the
            > use of %trans% entirely). The 0;1 parameters at the end of the line
            > are to make the replacement case insensitive but whole words only.
            >
            > The key to using a custom function is to assign the output to the
            > special variable %Result%.
            >

            While continuing to tinker with my two clips, I thought it might be
            useful to show how they work as one and so demonstrate the advantages
            of converting a complex "function" that is likely to be re-used into a
            custom function that sits in another clip.

            H="Transform Me--->You"
            ^!Set %Ans%=^?{Text to be manipulated}
            Original:
            ^%Ans%
            Transformed:
            ;Everything after this is one LONG LINE
            ^$StrReplace("mine";"yours";"^$StrReplace("my";"your";"^$StrReplace("myself";"yourself";"^$StrReplace("I";"you";"^$StrReplace("I'm";"you're";"^$StrReplace("I
            was";"you were";"^$StrReplace("me";"you";"^%Ans%";0;1)$
            ";0;1)$";0;1)$";0;1)$";0;1)$ ";0;1)$ ";0;1)$

            Cheers

            Bob
          • abairheart
            ... work ... I m not sure what NoteTab versions y all are using, but Pro has a string repace function, which will search the string for a substring, and
            Message 5 of 7 , Apr 13, 2006
            • 0 Attachment
              --- In ntb-clips@yahoogroups.com, Bob Gorman <bgorman@...> wrote:
              >
              > Don & Alan,
              >
              > Thank you both.
              > I knew I could as you both suggest create a new document and do the
              work
              > there, but it just seemed like there might be a more elegant way.


              I'm not sure what NoteTab versions y'all are using, but Pro has a
              string repace function, which will search the string for a substring,
              and replace it. You CAN use a variable for each of these arguments:

              ^$StrReplace("long string";"short string";"very long string";0;0)$

              I.e.

              ^!Set %VLS%=Very long string
              ^!Set %ls%=long string; %ss%=short string
              ^!Set %VLS%=^$StrReplace("^%ls%";"^%ss%";"^%vls%";0;0)$
              ^!Info ^%vls%

              Abair
            Your message has been successfully submitted and would be delivered to recipients shortly.