Selecting a block (range) to the end of file in macro

Selecting a block (range) to the end of file in macro

6
NewbieNewbie
6

    Mar 14, 2007#1

    I am new to UltraEdit. I think I am missing something simple. I am trying to select a specified range (start on Line 1, Column 21-24) on every line in a file, regardless of text, and Copy it to another place in the file. I can't find the command to go to the end of the file without losing the selection. Here is my macro section.

    InsertMode
    ColumnModeOn
    HexOff
    UnixReOn
    GotoLine 1 21
    Key SHIFT
    Key RIGHT ARROW
    Key RIGHT ARROW
    Key RIGHT ARROW

    Any help would be great as this is the last piece I need to complete a larger macro. Thanks.

    6,605548
    Grand MasterGrand Master
    6,605548

      Mar 14, 2007#2

      When working with selections in column mode it is normally better to temporarily delete all blanks lines at bottom of the file, so the last line of the file has no line termination and Bottom or SelectToBottom moves the cursor to end of content of last line with content.

      However, in your case it is better to select from last line of the file column 25 to first line of the file column 21.

      Please note: The first versions of UE/UES supporting GotoLine with a column number have a bug. If the file is an ASCII file and not a Unicode file, and GotoLine or GotoLineSelect is used with line number 1 or at line 1, the cursor is always positioned to specified column number + 1 (BOM of Unicode files also taken into consideration for ASCII/ANSI files).

      To solve this problem I always insert at top of the file an empty line and delete it when I don't need it anymore when I'm using the GotoLine or GotoLineSelect with a column number at first line. The following macro contains the same workaround. So delete the inserted blank line at top of the file, if you don't need it anymore and no selection is active with command DeleteLine.

      This bug was fixed with UE v13.00+2 and UES v6.20+2 and so the workaround is not necessary anmore if you use this version or any higher.

      GotoLine and GotoLineSelect with line number 0 to move the cursor to the specified column in the current line is supported since UE v12.20a+2 and UES v6.10a+2. So this macro works only with this version of UE/UES or any higher version.

      InsertMode
      ColumnModeOn
      HexOff
      UnixReOn
      Top
      "
      "
      Bottom
      Loop
      IfColNum 1
      Key UP ARROW
      Key END
      Else
      ExitLoop
      EndIf
      EndLoop
      GotoLine 0 25
      GotoLineSelect 2 21
      Best regards from an UC/UE/UES for Windows user from Austria

      6
      NewbieNewbie
      6

        Mar 14, 2007#3

        Thanks so much. I actually had to tweak a few items. The below script worked. I also added in the rest of what I needed copy/paste, delete the extra row.

        Do you know if there is a way to Convert Columns Character to Delimited file in a macro? I see how to do it manually, but would like to automate this to if possible. Am trying to take the file, and make it loadable to an ERP system which requires each field to be at a designated column.

        InsertMode
        ColumnModeOn
        HexOff
        UnixReOn
        Top
        "
        "
        Bottom
        Loop
        IfColNum 1
        Key UP ARROW
        Key END
        Else
        ExitLoop
        EndIf
        EndLoop
        GotoLine 0 22
        Key SHIFT
        GotoLineSelect 2 25
        Copy
        GotoLine 2 2

        6,605548
        Grand MasterGrand Master
        6,605548

          Mar 15, 2007#4

          I'm quite sure Key SHIFT is useless in the macro and maybe command StartSelect is better.

          And command "Convert to Fixed Column" is not available in the macro environment. I think because of the user interactions necessary or large number of parameters.

          I have once written for myself a small 'C' program which does the same as "Convert to Fixed Column" with appropriate settings (is not a full equivalent) which could be run by a user tool. But this program was written for Filemon/Regmon/Portmon logs and so is not for general usage. My prog supports up to 16 columns with a max. line length of 512 bytes (without \r\n\0) and the separator character must be a tab char. The prog first analyzes the file to get width of every column (Scan button in UE dialog) and then writes the new file with spaces for alignment and 3 spaces instead of the tab. However, if you would need my program to make a "convert to fixed column width" via a user tool which can be used from within a macro, tell me what you need (number of columns, max line length after convert, separator character, file format ...) and I will adapt my prog for your need on weekend. Should be no problem because it is really simple.
          Best regards from an UC/UE/UES for Windows user from Austria

          6
          NewbieNewbie
          6

            Apr 04, 2007#5

            Mofi,

            The "ReviseA" macro causing the issue is below. I can modify any macro and run with no issues. I can also email the file to the other person, open the macro file and run any macro as is there too. The problem is ONLY if I try to modify "ReviseA" in any way on his PC. After that, pressing "Shift+1" only copies the macro text into the file starting at 1 1. Modifications to ReviseB or Split2 does not cause this issue.

            Specifically, I tried changing 1 39 to 1 38 and Replace FY07 with 2008 instead of 2007. Both resulted in the problem. Could you try it on your machine (Version 13.00+4) and see if it also happens to you? Thanks.

            InsertMode
            HexOff
            UnixReOn
            ColumnModeOn
            GotoLine 1 1
            Key HOME
            Find """
            Replace All ""
            Find ",TJU_Employee_Total,"
            Replace All ","
            Find ",Final,"
            Replace All ","
            Find "PROD_NONE"
            Replace All " "
            Find "PROD_"
            Replace All ""
            Find "FY07"
            Replace All "2007"
            Find "Jul"
            Replace All "001"
            Find "Aug"
            Replace All "002"
            Find "Sep"
            Replace All "003"
            Find "Oct"
            Replace All "004"
            Find "Nov"
            Replace All "005"
            Find "Dec"
            Replace All "006"
            Find "Jan"
            Replace All "007"
            Find "Feb"
            Replace All "008"
            Find "Mar"
            Replace All "009"
            Find "Apr"
            Replace All "010"
            Find "May"
            Replace All "011"
            Find "Jun"
            Replace All "012"
            GotoLine 1 1
            Key HOME
            ColumnInsert "B,Budget,"
            GotoLine 1 38
            ColumnInsert "USD,"
            Top
            "
            "
            Bottom
            Loop
            IfColNum 1
            Key UP ARROW
            Key END
            Else
            ExitLoop
            EndIf
            EndLoop
            GotoLine 0 22
            GotoLineSelect 2 25
            Key SHIFT
            Key LEFT ARROW
            Key LEFT ARROW
            Key LEFT ARROW
            Copy
            GotoLine 2 2
            Paste
            GotoLine 1 1
            DeleteLine
            Key HOME
            EndSelect
            Top
            "
            "
            Bottom
            Loop
            IfColNum 1
            Key UP ARROW
            Key END
            Else
            ExitLoop
            EndIf
            EndLoop
            GotoLine 0 25
            GotoLineSelect 2 29
            Key SHIFT
            Key LEFT ARROW
            Key LEFT ARROW
            Key LEFT ARROW
            Key LEFT ARROW
            Key DEL
            GotoLine 1 1
            DeleteLine
            Key HOME

            6,605548
            Grand MasterGrand Master
            6,605548

              Apr 05, 2007#6

              Okay, I found the horrible bug of the edit macro dialog of UE v13.00+? and UES v6.20+? which is causing all the problems you see. A string with an odd number of double quotes inside is not compiled anymore correct when closing the macro in the edit macro dialog.

              The code part

              Find """
              Replace All ""

              is correct recorded with the macro recorder. But if a user modifies the macro later in the editor, the compiler will interprete this as follows for your macro:

              Find """
              Replace All ""
              ...
              ...
              GotoLine 1 38
              ColumnInsert "USD,"
              Top

              "

              And the rest of the code of your macro is interpreted as simple text. If you look on the re-opened macro after editing you will find an additional double quote at end of the macro indicating that the macro code is interpreted as text.

              That is really a horrible bug. I run several tests and I have seen that this bug also exists with UE v13.00+5, UE v13.00+2 (I don't have anymore v13.00+1 and v13.00), but not with UE v12.20b+1 or any other v12.20.

              I will report this horrible bug also to IDM.

              And I will report also that GotoLineSelect with column number does not select the correct range from current cursor position to the specified line/column in column mode when selecting in reverse direction. I have seen that as I looked on your code:

              GotoLine 0 22
              GotoLineSelect 2 25
              Key SHIFT
              Key LEFT ARROW
              Key LEFT ARROW
              Key LEFT ARROW

              A selection with GotoLineSelect from line 2 column 22 to last line column 25 would work, but the line number of the last line is normally not known and so a fixed line number cannot be used.


              As I workaround for all the problems I have modified the macro now to this one which hopefully does the same as your one. The red highlighted part is the workaround for the double quote character problem inside a string. As you can see I insert at top of the file 2 double quote characters (only 1 is not possible because of the bug), delete the second one directly, select the first one and replace all double quote characters with nothing which deletes also the inserted double quote character.

              InsertMode
              HexOff
              UnixReOn
              ColumnModeOff
              Top
              """"
              Key BACKSPACE
              StartSelect
              Key LEFT ARROW
              Find "^s"
              Replace All ""
              EndSelect

              Find ",TJU_Employee_Total,"
              Replace All ","
              Find ",Final,"
              Replace All ","
              Find "PROD_NONE"
              Replace All " "
              Find "PROD_"
              Replace All ""
              Find "FY07"
              Replace All "2007"
              Find "Jul"
              Replace All "001"
              Find "Aug"
              Replace All "002"
              Find "Sep"
              Replace All "003"
              Find "Oct"
              Replace All "004"
              Find "Nov"
              Replace All "005"
              Find "Dec"
              Replace All "006"
              Find "Jan"
              Replace All "007"
              Find "Feb"
              Replace All "008"
              Find "Mar"
              Replace All "009"
              Find "Apr"
              Replace All "010"
              Find "May"
              Replace All "011"
              Find "Jun"
              Replace All "012"
              ColumnModeOn
              ColumnInsert "B,Budget,"
              Top
              "
              "
              GotoLine 2 38
              ColumnInsert "USD,"
              GotoLine 2 22
              ColumnCut 3
              GotoLine 2 2
              Paste
              GotoLine 2 25
              ColumnDelete 1
              Top
              DeleteLine

                Apr 08, 2007#7

                IDM has fixed the problem with odd numbers of double quote characters in a string on the same day as I have reported it. Update to hotfix 7 of UE v13.00 where this problem does not occour anymore and so the red highlighted workaround is not necessary anymore and you can enter again

                Find """
                Replace All ""

                instead in the edit macro dialog. I have also modified my macro because there is a ColumnCut command which makes it not necessary to select the 3 columns 22-24 which should be cut and inserted at column 2. Now the macro is really simple.

                  Jun 22, 2007#8

                  Mofi wrote:And I will report also that GotoLineSelect with column number does not select the correct range from current cursor position to the specified line/column in column mode when selecting in reverse direction.
                  That problem was fixed with UltraEdit v13.10+1 and UEStudio v6.30+1. Selecting a rectangular block in column mode in reverse direction (i.e. from higher line number to lower line number) now works in any case, independent if done from lower column number to higher column number or vice versa. So now it is possbible to select a rectangular block
                  1. from left upper corner to right lower corner, 2/8 to 5/11
                  2. from right upper corner to left lower corner, 2/11 to 5/8
                  3. from left lower corner to right upper corner, 5/8 to 2/11
                  4. from right lower corner to left upper corner, 5/11 to 2/8
                  3. and 4. did not work in previous versions.