Count open files and halt on error

Count open files and halt on error

2
NewbieNewbie
2

    Aug 15, 2008#1

    Hello All
    Is it possible using macros to count the number of open files? I am using the following macro to run some tools on each open file but I would like to be able to change the loop value to a dynamic value based on the number of open files.
    Loop 39
    RunTool "Compiler"
    RunTool "Encryption Common Output"
    NextDocument
    EndLoop

    Also the above tools run DOS based programs and are set to capture output. Is there any way of checking the received output and halting on an error? For example the returned value when compiled correctly is;
    Compiler V1.01
    Is it possible to catch the returned value with the macro code and if it does not match the above then exit the loop?

    Thanks in advance

    Regards

    Phil

    6,682583
    Grand MasterGrand Master
    6,682583

      Aug 16, 2008#2

      No, in the macro environment you can't easily execute code on every open file. The techniques I use are either mark the first file with a special string and search inside the loop for this string after NextDocument to find out, if the first document has again the focus, or close every file after macro code execution and run the loop until no file is open anymore.

      With a script you could run your 2 user tools much easier on every open file because you can use for example:

      Code: Select all

      var FileCount;
      var NumberOfFiles = UltraEdit.document.length;
      for (FileCount = 0; FileCount < NumberOfFiles; FileCount++) {
         UltraEdit.document[FileCount].setActive();
         UltraEdit.RunTool("Compiler");
         RunTool "Encryption Common Output"
      }
      The output from the compiler can be captured to the output window, or to an edit window, or it replaces a selection in the current file depending on the capture settings of the user tool. With a macro you can't access data in the output window. So to exit the macro on an error reported by the compiler it would be necessary to capture the output to an edit window or make a dummy selection in a comment at bottom of the current file and let this selection being replaced by the captured output. Then you could use a find to check if the compiler returned the success message or an error and after cleanup in all cases exit the loop on error.

      In the script environment you have the possibility to copy the content of the output window to clipboard and further analyze it. In the script environment you could also capture the output to an edit window or replace a selection and analyze it. But the script environment supports writing to the output window. So you could not only break the loop on error, you could also transfer the captured output as is or reformatted from wherever you have analyzed it to the output window.

      If you capture the output to an edit window for analyzing, you have to take care not to compile this capured output on next compile step - close the file with the captured data without saving.
      Best regards from an UC/UE/UES for Windows user from Austria

      2
      NewbieNewbie
      2

        Sep 09, 2008#3

        Hello Mofi
        Thanks for the suggestions. When I posted here I did not realize that UltraEdit was capable of running scripts. I have now converted the macro to script and I have just one small bug to work out and it will do everything I wanted. Thank you again.

        Regards

        Phil