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

Re: Writing Subroutines in Notetab.

Expand Messages
  • Bob Gorman
    Don, At Wednesday 04:07 PM 3/8/2006, you wrote: ... I ve also been experimenting with this, but I m not quite successful as yet. I may be missing something
    Message 1 of 7 , Apr 12, 2006
      Don,
      At Wednesday 04:07 PM 3/8/2006, you wrote:

      Charles M. Raine wrote:
      > Hi All:
      >
      > It was suggested in a recent post, that writing subroutines in Notetab was
      > awkward and difficult, which it is NOT! Below is a routine I wrote to
      > create passwords of various types and lengths, which can be called by one
      > instruction: ^!Clip "Create Password"
      > The following instruction displays the password and format
      > created: ^!Info ^%Password%^p^%format%

      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 :-(

      Here are some of my experiments:
      with:
      ^!Set %rARS%=^!Clip "Me --> you"
      I got:
      Original:
      I love my life.
      Reversed:
      ^!Clip "Me --> you"

      Some others I've tried:
      ^!Set %rARS%=^!Clip "Me --> you" ^%Ans%
      and
      ^!Set %rAns%=^!Result ^!Clip "Me --> you"
      I get:
      Original:
      I love my life.
      Reversed:
      ^!Result ^!Clip "Me --> you"

      Any thoughts or even better explanations of what I'm missing would be
      appreciated, since I want to use this ability in a variety of places.

      Thanks,
      Bob

      'I am only one; but I am still one.
      I cannot do everything, but still I can do something.
      I will not refuse to do the something I can do.'
      -- Helen Keller


      [Non-text portions of this message have been removed]
    • Don - htmlfixit.com
      Hi Bob, I am not sure the caption on this is correct. This is about replace on a variable ... and I don t think you can do that. There are two solutions: 1.
      Message 2 of 7 , Apr 12, 2006
        Hi Bob,

        I am not sure the caption on this is correct.

        This is about replace on a variable ... and I don't think you can do that.
        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?

        > 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 :-(
        >
        > Here are some of my experiments:
        > with:
        > ^!Set %rARS%=^!Clip "Me --> you"
        > I got:
        > Original:
        > I love my life.
        > Reversed:
        > ^!Clip "Me --> you"
        >
        > Some others I've tried:
        > ^!Set %rARS%=^!Clip "Me --> you" ^%Ans%
        > and
        > ^!Set %rAns%=^!Result ^!Clip "Me --> you"
        > I get:
        > Original:
        > I love my life.
        > Reversed:
        > ^!Result ^!Clip "Me --> you"
        >
        > Any thoughts or even better explanations of what I'm missing would be
        > appreciated, since I want to use this ability in a variety of places.
        >
        > Thanks,
        > Bob
        >
        > 'I am only one; but I am still one.
        > I cannot do everything, but still I can do something.
        > I will not refuse to do the something I can do.'
        > -- Helen Keller
        >
        >
        > [Non-text portions of this message have been removed]
        >
        >
        >
        > Fookes Software: http://www.fookes.us, http://www.fookes.com
        > Fookes Software Mailing Lists: http://www.fookes.us/maillist.htm
        >
        > Yahoo! Groups Links
        >
        >
        >
        >
        >
        >
        >
      • 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 3 of 7 , Apr 12, 2006
          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 4 of 7 , Apr 12, 2006
            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 5 of 7 , Apr 12, 2006
              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 6 of 7 , Apr 12, 2006
                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 7 of 7 , Apr 13, 2006
                  --- 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.