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

Expand Messages
  • dandiebolt@yahoo.com
    The enclosed clip processes every line in a file and replaces each line with a newly calculated variable. To replace the text, I use the following commands:
    Message 1 of 4 , Apr 1, 2001
    • 0 Attachment
      The enclosed clip processes every line in a file and
      replaces each line with a newly calculated variable.
      To replace the text, I use the following commands:

      ^!SetClipboard ^%NewLine%^%NL%
      ^!Select LINE
      ^!Toolbar Paste

      Is there another way to do this not using the clipboard?
      What I am ideally looking for is the equivalent of

      ^!ReplaceCurrentLineWith ^%NewLine%^%NL%

      Regards,

      Dan

      ------------
      H="Replace Each Line"
      ;initialize
      ^!SetWordWrap OFF
      ^!Set %LastLine%=^$GetLineCount$
      ^!Set %FirstLine%=1
      ^!Jump TEXT_START
      ;start first pass of file
      ^!Set %CurrentLine%=1
      :Loop
      ;replace the curent line with ^%NewLine%
      ^!Set %NewLine%= <something goes here>
      ^!SetClipboard ^%NewLine%^%NL%
      ^!Select LINE
      ^!Toolbar Paste
      ;test if loop continutes
      ^!Inc %CurrentLine%
      ^!Jump ^%CurrentLine%
      ^!If ^%CurrentLine% <= ^%LastLine% Loop
    • Jody
      Hi Dan, ... Maybe I am missing something since you know how to write scripts, but all you need to do ^!Set %NewLine%= with something in it, Select Line, and
      Message 2 of 4 , Apr 1, 2001
      • 0 Attachment
        Hi Dan,

        > ^!SetClipboard ^%NewLine%^%NL%
        > ^!Select LINE
        > ^!Toolbar Paste
        >
        >Is there another way to do this not using the clipboard?
        >What I am ideally looking for is the equivalent of

        >^!Set %NewLine%= <something goes here>
        >^!SetClipboard ^%NewLine%^%NL%
        >^!Select LINE
        >^!Toolbar Paste

        Maybe I am missing something since you know how to write scripts,
        but all you need to do ^!Set %NewLine%= with something in it,
        Select Line, and then use InsertText:

        ^!Set %NewLine%=data
        ^!Select Line (or EOL - does not select the cr/lf)
        ^!InsertText ^%NewLine%^p

        You can do away with ^!InsertText in most cases or use an older
        command ^!Insert. The preset variable ^%NL% has to be used
        instead of ^p if you only use the variable:

        ^!Set %NewLine%=data
        ^!Select Line
        ^%NewLine%^%NL%

        Happy Clip'n!
        Jody

        http://www.notetab.net

        Subscribe, UnSubscribe, Options
        mailto:Ntb-Clips-Subscribe@yahoogroups.com
        mailto:Ntb-Clips-UnSubscribe@yahoogroups.com
        http://www.egroups.com/group/ntb-clips
      • dandiebolt@yahoo.com
        Jody, I like your method better. To backup, I needed a method to replace the current line with a calculated value. I couldn t find a command to do just this so
        Message 3 of 4 , Apr 1, 2001
        • 0 Attachment
          Jody,

          I like your method better. To backup, I needed a method to replace
          the current line with a calculated value. I couldn't find a
          command to do just this so I opted to select the line and then
          paste over it - just as I might do manually editing the file.
          It wasn't apparent to me when I was writing the clip that
          "^!InsertText" clobbers the selection. I knew I could get
          this result if I pasted the new line using "^!Toolbar Paste".
          I frequently get spurious errors wehn I attempt exact cursor
          control so I tend to fall into a patter of using a generic
          technique over and over once I know it works. What might
          be nice is a short faq that covered generic techniques such
          as:

          1) How do I do <something> to every line in the file?

          H="Process Each Line"
          ;initialize
          ^!SetWordWrap OFF
          ^!Set %LastLine%=^$GetLineCount$
          ^!Set %FirstLine%=1
          ^!Jump TEXT_START
          ;start first pass of file
          ^!Set %CurrentLine%=1
          :Loop
          ^!Set %NewLine%=<something>
          ^!Select LINE
          ^!InsertText ^%NewLine%^%NL%
          ;test if loop continutes
          ^!Inc %CurrentLine%
          ^!Jump ^%CurrentLine%
          ^!If ^%CurrentLine% <= ^%LastLine% Loop

          2) How do I create several files with the same base name
          but different file extensions and fill them up with
          some initial content?

          H="New *.xst1 & *.ext2"
          ^!Set %Directory%=^?[(T=D)Directory]
          ^!Set %BaseFileName%=^?[Base File Name]
          ^!Set %RootElement%=^?[Root Element=root]
          ^!TOOLBAR New Document
          <generate initial contents for first file>
          ^!Set %VariableName1%=^$GetDocIndex$
          ^!TOOLBAR New Document
          <generate initial contents for second file>
          ^!Set %VariableName2%=^$GetDocIndex$
          ^!IfFileExist ^%Directory%^%BaseFileName%.ext1 Leave
          ^!IfFileExist ^%Directory%^%BaseFileName%.ext2 Leave
          ^!SetDocIndex ^%VariableName1%
          ^!Save AS ^%Directory%^%BaseFileName%.ext1
          ^!SetDocIndex ^%VariableName2%
          ^!Save AS ^%Directory%^%BaseFileName%.ext2
          :Leave

          3) How do I do <something> to every file in a directory?

          I think you get the idea. Most of the questions on such a faq
          could easily fall into a generic category and would provide
          a good starting point for someone either new to clipping or
          who write clips infrequently. It is safe to say with my
          clip writing I repeatedly use the same techniques over and
          over always trying to utilize a general technique if possible.

          Regards,

          Dan
        • Stephen
          Hi Hans, I thought there was an assortment of things which labored together to keep your clip from working rightly. I ve fixed it (to what I think you wanted
          Message 4 of 4 , May 7, 2001
          • 0 Attachment
            Hi Hans,
            I thought there was an assortment of things
            which labored together to keep your clip from
            working rightly.
            I've fixed it (to what I think you wanted it doing) and
            annotated my changes.
            Hope it helps,
            Stephen



            H="hans'sline"
            ^!ClearVariables
            ; I added another variable to contain the value
            ; of the row number. I'm not sure it's necessary,
            ; but makes me feel better.
            ^!Set %linerow%=^$GetRow$

            :Loop
            ; The next line of code was:
            ; ^!Set %lines%=^&
            ; Using the function GetSelection creates a new value
            ; every time this line is iterated.
            ; The ^& function does not do this.
            ; I also moved this part of the code into the loop.
            ^!Set %lines%=^$GetSelection$
            ^!Set %x%=^$StrDelete("^%lines%";1;3)$
            ^!Append %s%=^%x%^%NL%
            ; The next couple of lines use the new variable,
            ; but otherwise don't do anything exciting.
            ^!Inc %linerow%
            ^!SetCursor ^%linerow%:1
            ^!Select LINE
            ; The next line of code was:
            ; ^!If ^%lines%<1 End
            ; What the original line did was check
            ; whether character position of the first
            ; letter of the string was less than that
            ; of the ascii character "1".
            ; I'm not sure what you need, but I
            ; used a function to see if the cursor
            ; was at the end of the document.
            ^!If ^%linerow%>=^$GetTextLineCount$ SKIP
            ; The nest line of code was:
            ; :GotoLoop
            ; There are two problems with it.
            ; The first is that it is a label and not a command
            ; so does not do anything.
            ; The second is that as a command, there needs
            ; to be one space before the label we are
            ; sending Note Tab to.
            ^!Goto Loop

            ^!StatusClose
            ^!TOOLBAR New Document
            ^!InsertText ^%s% ^p
            ^!Save As "c:\WINDOWS\Desktop\pos_1-3_^$GetDate(yyyymmddhhnnss)$.txt"


            interval@... wrote:
            >
            > Dear NTrs,
            >
            > The clip below does only process the first line with in a selection
            > made with ^&.
            >
            > Why is that ?
            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.