Workaround for (lack of) variables

Workaround for (lack of) variables

3

    Apr 02, 2009#1

    Background: I have a file with a bunch of Debug MessageBoxes. Each is uniquely numbered so that, when it's displayed, if it isn't returning the right data, I can cancel and find the preceding code very easily. Problem is, as I add code, I need more DbgMsgs, so the numbering gets all out of whack. (And the potential arises for me to use the same number more than once.) I wanted a way to use a macro to find and renumber all of these, in order, but that appeared impossible with UE's macro language. Yes, it supports Loops, but those are of limited use without a variable that can be incremented and inserted.

    Solution:
    Pseudocode (actual code below)
    1. Go to top of page
    2. Create new file and insert sequential numbers, one per line
    3. Go to top of page
    4. Select to end of line and cut
    5. delete line (so next number is at top of file)
    6. Go to previous document and find DbgMsg text (preceding the number to be replaced)
    7. Deselect using right arrow key, then select number to be replaced, then paste
    8. Go to next document (i.e. new document with sequential numbers)
    Loop 4-8 until search text isn't found and script aborts.

    Code: Select all

    Top
    NewFile
    "10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69"
    Top
    Loop 60
    StartSelect
    Key END
    EndSelect
    Cut
    Key DEL
    PreviousDocument
    Find "d := dbgmsg"
    Key RIGHT ARROW
    StartSelect
    Key Ctrl+RIGHT ARROW
    EndSelect
    Paste
    NextDocument
    EndLoop
    ExitMacro
    

      Apr 02, 2009#2

      With a little creativity, this technique could be very robust. For example, if you needed to replace a bunch of random blocks of text with specific other text, you could...

      Pseudocode:
      1. list out the "replace me" variables in a document
      2. at the end of each line, insert a tab, followed by the "replace with" variable
      3. Go to the top of the document, find the first tab
      4. delete the tab character and select to the beginning of the line
      (You now have the text to search for)
      5. Switch to the target document and send keys Ctrl+F then Ctr+V then enter
      6. Switch back to the "variables" document
      7. Select to the end of the line, cut, delete line
      8. Switch back to the target document and paste
      9. Switch back to the "variables" document
      Loop 3-9 until done
      (Once all the variable pairs have been used, the tab character won't be found in variables document.)

      Hope this helps some people deal with the limitations of the UE macro language. It sure worked for me!

      6,681583
      Grand MasterGrand Master
      6,681583

        Apr 02, 2009#3

        For renumbering something and Column - Insert Number in column editing mode can't be used, I first have used the method like you posted here. Later I developed the macro CountUp posted at counter which works with the number as string in active clipboard. When you use the forum search and search in the macro forum for CountUp you will find some examples.

        The workaround for replacing one string with another is also well known (for me) and my version is faster because it avoids document switching which decreases the speed of the macro a lot. There are some examples in the macro forum, for example:

        Replace text in file A with info from file B
        Replace line after line, is this somehow possible ?
        Remove contents of one file from another
        and so on.

        Search in the macro forum for IfCharIs to find more examples. Unfortunately it is not possible anymore to search for ^c or ^s with the forum search. (MySQL search engine has some limitations the full text search engine does not have.)

        But nevertheless interesting that you came to the same solutions as I as I started writing UE macros.
        Best regards from an UC/UE/UES for Windows user from Austria

        3

          Apr 02, 2009#4

          I should have guessed the Grand Master already had a good workaround. (Good to have this topic, though, so more people can find your scripts.) Thanks for the pointers; I'll check out those scripts!

          One suggestion: A mention that a workaround for the lack of variables exists would be good to mention (maybe even links) in the HTML file in Mofi's Macro Examples. I searched that first before developing my workaround.

          32
          Basic UserBasic User
          32

            lack of variables

            Apr 19, 2010#5

            I see a lot of workarounds on this forum to get around UE's lack of variables. I have one question - why don't they add at least a few to the program??

            Even if you use scripts, I believe you are unable to set persistent variables - i.e. that keep their value from one script to another. In macros, I see the use of clipboards 8 and 9 for this, which does work, but not for numeric counters, etc (at least I don't think so).

            I suppose people have requested it, but actually I haven't found any requests on the forum for it. Everybody just seems to accept it as a given. I mean, would it kill them to build in a few?? Any thoughts on this issue?

            901
            MasterMaster
            901

              Re: lack of variables

              Apr 27, 2010#6

              RAH wrote:I see a lot of workarounds on this forum to get around UE's lack of variables...
              I suppose people have requested it, but actually I haven't found any requests on the forum for it...
              If you have a feature that you would like to see implemented, please send your ideas directly to IDM via email.
              The higher the request count is for an enhancement idea, the more likely it is that it will be implemented.

              32
              Basic UserBasic User
              32

                Re: lack of variables

                May 29, 2010#7

                Thanks for the feedback, Bulgrien. Yes, I should do that. It just seems that it is so desirable and is talked about so much, there almost has to be some really strong reason why they don't do it. But when you think about all the stuff the editor itself needs to keep track of and keep in its own internal variables, it does seem like it would be a simple thing to add a few for the use of macro writers. Of course, it's easy to say when you don't have to code it!

                6,681583
                Grand MasterGrand Master
                6,681583

                  Re: lack of variables

                  May 29, 2010#8

                  I think, the UltraEdit macro support will be never extended with support for variables. Reasons:
                  • There are already lots of powerful programming and scripting languages available to solve tasks with smart programs or scripts. So do we really need one more powerful scripting language with a different syntax? I wrote very complex UltraEdit macros. But whenever I need for myself a routine which do something on text files and need to be run often, I don't write an UltraEdit macro for such tasks. I code that with C/C++ as console application. Others use perhaps Python or VBS. The advantage is that such programs or scripts do not update the display on every command and therefore do things in milliseconds which would take seconds or even minutes with an UltraEdit macro.
                  • Just adding support for variables to be able to remember and re-use different strings in an UltraEdit macro would be just the first step. After implementing this the users would surely want more and request string functions (compare, manipulate, extract, ...) and variables for numbers with possibilities to calculate with them. And suddenly the IDM developers would be forced by the users to code one more powerful script interpreter.
                  • IDM has already recognized that support for a powerful scripting language is nowadays important for a text editor. But IDM did not want to invent just one more scripting language and extend their macro engine to a script interpreter. They looked what already existed and decided to integrate the powerful Javascript core engine which is available as open source.
                  • So nowadays UltraEdit supports:
                    • Simple macros for simple tasks with the support for recording user actions into a macro and redo these actions quickly by executing the recorded macro (command sequence). The recorded macros can be also edited for fine tuning in case the macro is needed in future from time to time again.
                    • Scripts written in Javascript for more complex tasks where variables, loops, conditions, arrays, string manipulation routines, dynamic memory usage, etc. is needed and which are supported by the Javascript interpreter.
                    • Calling of up to 50 tools (can be extended wit a special tool (batch file, VBS script, application) and a script to an unlimited number of tools) to do something on files which is better done with programs or an even more powerful scripting language than Javascript offers.
                  So I want to ask you, why do you really want to extend the macro engine of UltraEdit from a simple command sequencer to a script interpreter? Why do you not code and use a script when you need variables to fulfill a task?
                  Best regards from an UC/UE/UES for Windows user from Austria

                  32
                  Basic UserBasic User
                  32

                    Re: lack of variables

                    May 30, 2010#9

                    I come from a Vedit background. I was just trying to emulate in Ultraedit a very simple thing that Vedit allows - it's kind of a quick bookmark, without actually using a bookmark. You just press a hot-key which says "save this spot". Later, if you want to return to that spot, you hit another hot-key. So, it's just a simple "return to this place" holder.

                    I could not see how to do this in Ultraedit - store a line number and then use it later in another macro. I'm not at all proficient in UE macros, but without variables, I just couldn't see any method for even doing this simple thing. All you need for this type of thing is to be able to store a number and retrieve it later. The editor has this info, but you can't get at it.

                    I agree with you that people will be asking for more and more features for internal variables, but I don't really think that this is necessarily a good reason not to do something at all.

                    I agree that UE is not intended to be some kind of super script driver. But as we know, there are many things that you want to do within an editor environment just for use in that editor. Variables just make it easier.