Jump to content
Macro Express Forums

rberq

Members
  • Posts

    989
  • Joined

  • Last visited

  • Days Won

    44

Everything posted by rberq

  1. Yes it will work. I don't know that it is more elegant than your solution, but it is simple and straightforward, and has lots of possibilities beyond simply reporting folder size. I used the technique to automate processing on a server which contained extremely large individual backup files. The DIR commands were in .bat files that were scheduled by Windows. Then ME would schedule subsequent scripts to process the DIR output and generate additional .bat commands to compress the backup files and send the compressed files off to long-term tape storage. A few simple batch files and ME scripts replaced an expensive commercial system that didn't work worth sh*t anyway. 😋
  2. Here's a different technique, which I have used extensively in the past to develop lists of files with various attributes: The macro can issue a DOS-style command directing its output to a file. For this problem, the command would be DIR DIRPATH /S >C:\Temp\filelist.txt, which lists all files in the specified folder and in all subfolders. The macro can then read and process filelist.txt, whose next-to-last line contains the cumulative number and size of the files. It is fairly simple to find the line and extract the totals.
  3. I object. That is not the least bit cringe-worthy, no more than my appending a garbage string of characters to denote the end of the text. Something like that can greatly simplify the convoluted logic that otherwise might be needed. As long as you document it so the next programmer won't be confused by the technique, it's praise-worthy rather than cringe-worthy. I like your solution better than mine -- my whole difficulty was special treatment of punctuation, and you avoided that issue. Sometimes I can make complex problems simple, and other times I can make simple problems complex.🙃
  4. That's my invention that goes back 50+ years for syncing multiple sequentially-sorted tape files, where category breaks occurred every so often requiring totals processing and resetting of counters for the next category. It can save a lot of convoluted logic otherwise needed, especially with three or more tapes. I'm sure I was not the first nor the last to discover the technique -- with account numbers the "garbage" was generally just a string of 9999999....
  5. OK, this seems to be working. There are punctuation marks that are not in the text used for testing, and they are not accounted for in the macro. I think to improve the macro, I would try a slightly different technique for punctuation and things like TAB characters -- perhaps replace each punctuation character with ESC and a digit. For example, ESC1=period, ESC2=comma, etc. Then in the result change the ESC sequences back to period, comma, and so on. // Log Errors to "C:\Temp\MacroExpressProLogFiles\MacroExpressPro_Macro_Log_File.txt" Log Messages to "C:\Temp\MacroExpressProLogFiles\MacroExpressPro_Macro_Log_File.txt" "Macro executed: Temp_Extract_First_Letters" Log Errors to Default Macro Log // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Keystroke Speed: 10 milliseconds Mouse Speed: 30 milliseconds // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx // // Null character ascii 0 Variable Set to ASCII Char 0 to %NULL% // BEL character ascii 7 Variable Set to ASCII Char 7 to %BEL% // Escape character ascii 9 Variable Set to ASCII Char 27 to %ESC% // Tab character ascii 9 Variable Set to ASCII Char 9 to %TAB% // Line Feed (New Line) character ascii 10 Variable Set to ASCII Char 10 to %LINEFEED% // Carriage Return character ascii 13 Variable Set to ASCII Char 13 to %CARRIAGERETURN% // Carriage Return / Line Feed combination characters ascii 13 + ascii 10 Variable Set to ASCII Char 13 to %CRLF% Variable Modify String %CRLF%: Append Text String Variable (%LINEFEED%) // STX character ascii 2 Variable Set to ASCII Char 2 to %STX% // ETX character ascii 3 Variable Set to ASCII Char 3 to %ETX% // DC1 character ascii 17 Variable Set to ASCII Char 17 to %DC1% // DC2 character ascii 18 Variable Set to ASCII Char 18 to %DC2% // // Variable Set String %text% to " Once upon a time, there was an ogre named Sandor. Sandor lived in a 1000-room "castle" made of ice! Change all punctuation marks to "blank punctuation blank". Change CR-LF to a single character BEL that is unused elsewhere (surrounded by blanks). Insert one dummy blank at the beginning of the text. Change all multiple consecutive blanks to single blanks. Remove first character from text (must be a blank). Repeat until done: Extract first character into result, remove from text. Locate first blank in text, remove all characters up to that position. Repeat end Change all punctuation marks from "blank punctuation blank" to "punctuation". Change selected punctuation marks to "punctuation blank" (periods, commas, etc.) " Text Box Display: Diagnostics -- show text If Variable %text% Contains "%CRLF%" Text Box Display: Diagnostics End If // Insert one blank at beginning of text Variable Set String %temptext% to " " Variable Modify String %temptext%: Append Text String Variable (%text%) Variable Modify String %text%: Copy Whole Text (%temptext%) Text Box Display: Diagnostics -- text with extra blank at beginning // Change all multiple consecutive blanks to single blanks. Repeat Start (Repeat 20 times) Variable Modify String: Replace " " in %text% with " " End Repeat Text Box Display: Diagnostics -- text with multi blanks compressed to single blanks // Surround punctuation marks with blanks Variable Modify String: Replace "." in %text% with " . " Variable Modify String: Replace "," in %text% with " , " Variable Modify String: Replace "-" in %text% with " - " Variable Modify String: Replace "!" in %text% with " ! " Variable Modify String: Replace "(" in %text% with " ( " Variable Modify String: Replace ")" in %text% with " ) " Variable Modify String: Replace " "" in %text% with " %DC1% " // change left double-quote to DC1 Variable Modify String: Replace """ in %text% with " %DC2% " // change right double-quote to DC2 (all remaining double-quotes) Variable Modify String: Replace "%CRLF%" in %text% with " %BEL% " // Change two-character sequence CRLF to single character BEL Text Box Display: Diagnostics -- text after punctuation expansion // Remove first character from text Variable Modify String %text%: Delete a substring starting at 1 and 1 characters long Text Box Display: Diagnostics -- text after deleting leading blank // Extract first character of each word -- punctuation marks count as words Variable Set String %result% to "" // Clear result text Variable Modify String %text%: Append Text ( !@#$%^&*()) // Append garbage to end of text to identify where the end is Repeat Until %text% Equals " !@#$%^&*()" Variable Modify String: Copy a substring in %text%, starting at 1 and 1 characters long to %onechar% // One character from text into temporary area Variable Modify String %result%: Append Text String Variable (%onechar%) // Append extracted character to result Variable Modify String %result%: Append Text ( ) // Append one blank to result Variable Set Integer %index% to the position of " " in %text% Variable Modify String %text%: Delete a substring starting at 1 and %index% characters long // Delete from text up to and including next blank space End Repeat Text Box Display: Diagnostics -- text after processing to end Text Box Display: Diagnostics -- result text with one character per word // Change all multiple consecutive blanks to single blanks. // Adjust selected punctuation marks Repeat Start (Repeat 20 times) Variable Modify String: Replace " ." in %result% with ". " // period Variable Modify String: Replace " ," in %result% with ", " // comma Variable Modify String: Replace " -" in %result% with "-" // hyphen Variable Modify String: Replace "- " in %result% with "-" // hyphen Variable Modify String: Replace " !" in %result% with "! " // exclamation point Variable Modify String: Replace "!" in %result% with "! " // exclamation point Variable Modify String: Replace "( " in %result% with " (" // left paren Variable Modify String: Replace "(" in %result% with " (" // left paren Variable Modify String: Replace " )" in %result% with ")" // right paren Variable Modify String: Replace "%DC1% " in %result% with " "" // left double-quote Variable Modify String: Replace " %DC2% " in %result% with """ // right double-quote Variable Modify String: Replace "%BEL% " in %result% with "%CRLF%" // Change BEL characters back to CRLF End Repeat Repeat Start (Repeat 20 times) Variable Modify String: Replace " " in %result% with " " // double space to single space End Repeat If Variable %result% Contains "%CRLF%" Text Box Display: Diagnostics End If Text Box Display: Diagnostics -- final result after punctuation adjustment // // Macro Return // // . . . . <COMMENT Value=" "/> <LOG ERRORS Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Hide_Errors="TRUE"/> <LOG MESSAGES Filename="C:\\Temp\\MacroExpressProLogFiles\\MacroExpressPro_Macro_Log_File.txt" Message="Macro executed: Temp_Extract_First_Letters" Stamp="TRUE"/> <LOG ERRORS Hide_Errors="FALSE" _ENABLED="FALSE"/> <COMMENT Value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/> <KEYSTROKE SPEED Delay="10"/> <MOUSE SPEED Delay="30"/> <COMMENT Value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/> <COMMENT Value=" "/> <COMMENT Value="Null character ascii 0"/> <VARIABLE SET TO ASCII CHAR Value="0" Destination="%NULL%"/> <COMMENT Value="BEL character ascii 7"/> <VARIABLE SET TO ASCII CHAR Value="7" Destination="%BEL%"/> <COMMENT Value="Escape character ascii 9"/> <VARIABLE SET TO ASCII CHAR Value="27" Destination="%ESC%"/> <COMMENT Value="Tab character ascii 9"/> <VARIABLE SET TO ASCII CHAR Value="9" Destination="%TAB%"/> <COMMENT Value="Line Feed (New Line) character ascii 10"/> <VARIABLE SET TO ASCII CHAR Value="10" Destination="%LINEFEED%"/> <COMMENT Value="Carriage Return character ascii 13"/> <VARIABLE SET TO ASCII CHAR Value="13" Destination="%CARRIAGERETURN%"/> <COMMENT Value="Carriage Return / Line Feed combination characters ascii 13 + ascii 10"/> <VARIABLE SET TO ASCII CHAR Value="13" Destination="%CRLF%"/> <VARIABLE MODIFY STRING Option="\x07" Destination="%CRLF%" Variable="%LINEFEED%" NoEmbeddedVars="FALSE"/> <COMMENT Value="STX character ascii 2"/> <VARIABLE SET TO ASCII CHAR Value="2" Destination="%STX%"/> <COMMENT Value="ETX character ascii 3"/> <VARIABLE SET TO ASCII CHAR Value="3" Destination="%ETX%"/> <COMMENT Value="DC1 character ascii 17"/> <VARIABLE SET TO ASCII CHAR Value="17" Destination="%DC1%"/> <COMMENT Value="DC2 character ascii 18"/> <VARIABLE SET TO ASCII CHAR Value="18" Destination="%DC2%"/> <COMMENT Value=" "/> <COMMENT Value=" "/> <VARIABLE SET STRING Option="\x00" Destination="%text%" Value=" Once upon a time, there was an ogre named Sandor.\r\n\r\nSandor lived in a 1000-room \"castle\" made of ice! \r\n\r\nChange all punctuation marks to \"blank punctuation blank\".\r\nChange CR-LF to a single character BEL that is unused elsewhere (surrounded by blanks).\r\nInsert one dummy blank at the beginning of the text.\r\nChange all multiple consecutive blanks to single blanks. \r\nRemove first character from text (must be a blank).\r\nRepeat until done: \r\n Extract first character into result, remove from text.\r\n Locate first blank in text, remove all characters up to that position.\r\nRepeat end\r\nChange all punctuation marks from \"blank punctuation blank\" to \"punctuation\". \r\nChange selected punctuation marks to \"punctuation blank\" (periods, commas, etc.) " NoEmbeddedVars="TRUE"/> <TEXT BOX DISPLAY Title="Diagnostics -- show text" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <IF VARIABLE Variable="%text%" Condition="\x06" Value="%CRLF%" IgnoreCase="FALSE" _ENABLED="FALSE"/> <TEXT BOX DISPLAY Title="Diagnostics" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 text contains crlf\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <END IF _ENABLED="FALSE"/> <COMMENT Value="Insert one blank at beginning of text "/> <VARIABLE SET STRING Option="\x00" Destination="%temptext%" Value=" " NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x07" Destination="%temptext%" Variable="%text%" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x08" Destination="%text%" Variable="%temptext%" NoEmbeddedVars="TRUE"/> <TEXT BOX DISPLAY Title="Diagnostics -- text with extra blank at beginning" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <COMMENT Value="Change all multiple consecutive blanks to single blanks. "/> <REPEAT START Start="1" Step="1" Count="20" Save="FALSE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace=" " ReplaceWith=" " All="TRUE" IgnoreCase="TRUE" NoEmbeddedVars="FALSE"/> <END REPEAT/> <TEXT BOX DISPLAY Title="Diagnostics -- text with multi blanks compressed to single blanks" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <COMMENT Value="Surround punctuation marks with blanks "/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="." ReplaceWith=" . " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="," ReplaceWith=" , " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="-" ReplaceWith=" - " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="!" ReplaceWith=" ! " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="(" ReplaceWith=" ( " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace=")" ReplaceWith=" ) " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace=" \"" ReplaceWith=" %DC1% " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="change left double-quote to DC1"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="\"" ReplaceWith=" %DC2% " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="change right double-quote to DC2 (all remaining double-quotes)"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%text%" ToReplace="%CRLF%" ReplaceWith=" %BEL% " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="Change two-character sequence CRLF to single character BEL"/> <TEXT BOX DISPLAY Title="Diagnostics -- text after punctuation expansion" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value="Remove first character from text "/> <VARIABLE MODIFY STRING Option="\x0A" Destination="%text%" Start="1" Count="1"/> <TEXT BOX DISPLAY Title="Diagnostics -- text after deleting leading blank" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <COMMENT Value="Extract first character of each word -- punctuation marks count as words"/> <VARIABLE SET STRING Option="\x00" Destination="%result%" NoEmbeddedVars="FALSE" _COMMENT="Clear result text"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%text%" Value=" !@#$%^&*()" NoEmbeddedVars="FALSE" _COMMENT="Append garbage to end of text to identify where the end is"/> <REPEAT UNTIL Variable="%text%" Condition="\x00" Value=" !@#$%^&*()"/> <VARIABLE MODIFY STRING Option="\x09" Destination="%onechar%" Variable="%text%" Start="1" Count="1" NoEmbeddedVars="TRUE" _COMMENT="One character from text into temporary area"/> <VARIABLE MODIFY STRING Option="\x07" Destination="%result%" Variable="%onechar%" NoEmbeddedVars="TRUE" _COMMENT="Append extracted character to result"/> <VARIABLE MODIFY STRING Option="\x06" Destination="%result%" Value=" " NoEmbeddedVars="FALSE" _COMMENT="Append one blank to result"/> <VARIABLE SET INTEGER Option="\x0E" Destination="%index%" Text_Variable="%text%" Text=" " Ignore_Case="TRUE"/> <VARIABLE MODIFY STRING Option="\x0A" Destination="%text%" Start="1" Count="%index%" _COMMENT="Delete from text up to and including next blank space"/> <END REPEAT/> <TEXT BOX DISPLAY Title="Diagnostics -- text after processing to end" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %text%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <TEXT BOX DISPLAY Title="Diagnostics -- result text with one character per word" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %result%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value="Change all multiple consecutive blanks to single blanks. "/> <COMMENT Value="Adjust selected punctuation marks "/> <REPEAT START Start="1" Step="1" Count="20" Save="FALSE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" ." ReplaceWith=". " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="period"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" ," ReplaceWith=", " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="comma"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" -" ReplaceWith="-" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="hyphen"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="- " ReplaceWith="-" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="hyphen"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" !" ReplaceWith="! " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="exclamation point"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="!" ReplaceWith="! " All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="exclamation point"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="( " ReplaceWith=" (" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="left paren"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="(" ReplaceWith=" (" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="left paren"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" )" ReplaceWith=")" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="TRUE" _COMMENT="right paren"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="%DC1% " ReplaceWith=" \"" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="left double-quote"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" %DC2% " ReplaceWith="\"" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="right double-quote"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace="%BEL% " ReplaceWith="%CRLF%" All="TRUE" IgnoreCase="FALSE" NoEmbeddedVars="FALSE" _COMMENT="Change BEL characters back to CRLF"/> <END REPEAT/> <REPEAT START Start="1" Step="1" Count="20" Save="FALSE"/> <VARIABLE MODIFY STRING Option="\x0F" Destination="%result%" ToReplace=" " ReplaceWith=" " All="TRUE" IgnoreCase="TRUE" NoEmbeddedVars="FALSE" _COMMENT="double space to single space"/> <END REPEAT/> <IF VARIABLE Variable="%result%" Condition="\x06" Value="%CRLF%" IgnoreCase="FALSE" _ENABLED="FALSE"/> <TEXT BOX DISPLAY Title="Diagnostics" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 result contains crlf\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0" _ENABLED="FALSE"/> <END IF _ENABLED="FALSE"/> <TEXT BOX DISPLAY Title="Diagnostics -- final result after punctuation adjustment" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 %result%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="1079" Height="409" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value=" "/> <COMMENT Value=" "/> <MACRO RETURN/> <COMMENT Value=" "/> <COMMENT Value=" "/>
  6. Here's the text I'm converting, followed by the result. Part of the text is yours, part of it is my notes as to how the macro should operate. There are still some problems with double-quotes and with parentheses. TEXT: Once upon a time, there was an ogre named Sandor. Sandor lived in a 1000-room "castle" made of ice! Change all punctuation marks to "blank punctuation blank". Change CR-LF to a single character BEL that is unused elsewhere (surrounded by blanks). Insert one dummy blank at the beginning of the text. Change all multiple consecutive blanks to single blanks. Remove first character from text (must be a blank). Repeat until done: Extract first character into result, remove from text. Locate first blank in text, remove all characters up to that position. Repeat end Change all punctuation marks from "blank punctuation blank" to "punctuation". Change selected punctuation marks to "punctuation blank" (periods, commas, etc.) RESULT: O u a t, t w a o n S. S l i a 1- r" c" m o i! C a p m t" b p b" . C C- L t a s c B t i u e (s b b). I o d b a t b o t t. C a m c b t s b. R f c f t (m b a b). R u d E f c i r, r f t. L f b i t, r a c u t t p. R e C a p m f" b p b" t" p" . C s p m t" p b" (p, c, e. )
  7. Almost there. The problem I am having is punctuation marks like quotes and parentheses that may or may not be preceded/followed by a blank space. I may have to use a cringe-worthy brute force approach, but still working on other ideas....
  8. Get Mouse Position into (x_coordinate, y_coordinate) Relative to Screen
  9. That's the first thing I discovered when testing out Quick Search. But yes, your neutral area technique works. The biggest problem I have had with either one is, if the words being searched for appear more than once on the page -- how to get the right one.
  10. That's neat! Didn't know that! I just tried it out. There are a few places where that will let me clean up my navigation.
  11. This command sequence works for me in Firefox, on several web sites, to log off. The ESC keystroke is necessary. Easy to test by doing it manually before incorporating it in a macro. Text Type (Simulate Keystrokes): <CTRLD>f<CTRLU> Delay: 100 milliseconds Text Type (Simulate Keystrokes): log off Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ESC> Delay: 100 milliseconds Text Type (Simulate Keystrokes): <ENTER>
  12. Still fun for me, because I don't HAVE to do it.😉 I have a web page I parse every day, to update a spreadsheet. But between the page publisher and Firefox, subtle differences appear every few weeks. At least adjusting to the changes keeps me familiar with the macros ....
  13. If non-header lines ALWAYS contain a comma, you could detect a header by
  14. Getting familiar with the ME commands is something of a project. You almost have to go through them one by one and look at all the options of each command, and use the Help file in conjunction with that. It's often not obvious how the low-level commands can fit together to do a general function like "Parse".
  15. To delete the page numbers, find the position of the first comma and delete everything from there to the end of the line. (The first image below should have % signs around the variable names -- my error, sorry.)
  16. Not so far-fetched. I have a macro that is sort of a panic-button to kill runaway macros. (I use it more often than you might think!) It simulates typing the clumsy Macro Express key sequence to abort running macros, and does it multiple times "just in case", logging each time. In fact what actually happens, almost always, is that the runaway, plus this abort macro itself, are both cancelled on the very first pass. One odd thing is: if there are no other macros running, the ME box pops up telling me the abort macro itself has been halted; if there ARE other macro(s) running, everything is aborted but no pop-up appears. // Repeat abort sequence until this macro itself is aborted // Keystrokes defined in Macro Express Options | Preferences to abort macros Variable Set Integer %countr% to 0 Repeat Start (Repeat 100 times) Variable Modify Integer %countr%: Increment Log Messages to "C:\Temp\MacroExpressProLogFiles\MacroExpressPro_Macro_Log_File.txt" "Macro Kybd_Abort_Running_Macros issuing abort %countr% time(s)" Text Type (Simulate Keystrokes): <WIN>` Delay: 500 milliseconds, without ability to halt End Repeat
  17. That's "progress" a la Microsoft! Or should I call it "random violence"?
  18. That's what my "kill" macro does -- courtesy of a previous post where you pointed out that method, thank you. But I find that to be a clumsy key combination to press. Maybe like the piano it would get easier with practice. It's also pretty simple logic in a macro to locate the upper right corner of a window and click the X. So the problem is not how to kill the application; the problem is how to get the macro to run in the first place when Windows blocks hotkey use. Since Windows apparently does NOT block Macro Express from seeing the mouse, and since I often am using the mouse anyway, making use of it's movements is convenient. It's a bit like flicking an app away on my wife's iPad or on the Android phone. I wonder if there are others distinctive movements I could use for other functions ....
  19. OK, nothing earthshaking here, but this project was kind of fun. I have a hot key macro that closes whatever application/window is focused, by entering keystrokes <ALTD><SPACE>c<ALTU>. If Firefox or Chrome is focused with one or more tabs open, it types <CTRLD>w<CTRLU> instead, to close the current tab. Anyhow, I was frustrated because many Windows 10 applications block ME from seeing the hot key, so the "close application" macro doesn't run when I would like it to. The macro below runs in a continuous loop, sampling the mouse location frequently. If I flick the mouse to the right, then back to the left, the macro recognizes that pattern and runs the "close application" macro. Seems to work fine in Windows 10 screens where hotkeys are blocked. The macro is handier than I thought it would be -- I seldom reach for my hot key any more. I'm still tinkering with the timing and distance of the mouse moves, to avoid accidentally reacting to normal mouse movements. Also there are a few other macros that have been caught because they themselves do mouse movements that fit the pattern -- still weeding out a few of those. The macro running continuously uses about six percent of the CPU, but the darned processor is so fast it's just loafing most of the time anyway. // Track mouse, cancel application for rapid movement left to right and back // This macro is intended to run virtually all the time, in a continuous loop // Variable Set Integer %movement% to 150 // Set minimum distance that qualifies as a mouse movement // Variable Set String %repeater% to "0" Repeat Until %repeater% Equals "1" If Window "Program Manager" is focused Delay: 1000 milliseconds, without ability to halt Else // Clear previous mouse positions Variable Set Integer %left1% to 0 Variable Set Integer %left2% to 0 Variable Set Integer %right1% to 0 Variable Set Integer %spanright1% to 0 Variable Set Integer %spanleft1% to 0 // Check for first right/left movement Get Mouse Position into (%left1%, ypos) Relative to Screen Delay: 150 milliseconds, without ability to halt Get Mouse Position into (%right1%, ypos) Relative to Screen Variable Modify Integer: %spanright1% = %right1% - %left1% If Variable %spanright1% Is Greater Than "%movement%" // Did mouse move right? Delay: 400 milliseconds, without ability to halt Get Mouse Position into (%left2%, ypos) Relative to Screen Variable Modify Integer: %spanleft1% = %right1% - %left2% If Variable %spanleft1% Is Greater Than "%movement%" // Did mouse move left? Macro Run: 1_Close_Application_or_Browser_Window End If End If // End If End Repeat // Macro Return // <COMMENT Value="Track mouse, cancel application for rapid movement left to right and back"/> <COMMENT Value="This macro is intended to run virtually all the time, in a continuous loop"/> <COMMENT Value=" "/> <VARIABLE SET INTEGER Option="\x00" Destination="%movement%" Value="150" _COMMENT="Set minimum distance that qualifies as a mouse movement\r\n"/> <COMMENT Value=" "/> <VARIABLE SET STRING Option="\x00" Destination="%repeater%" Value="0" NoEmbeddedVars="FALSE"/> <REPEAT UNTIL Variable="%repeater%" Condition="\x00" Value="1"/> <IF WINDOW Option="\x00" Title="Program Manager" Partial="TRUE" Wildcards="FALSE"/> <DELAY Flags="\x13" Time="1000"/> <ELSE/> <COMMENT Value="Clear previous mouse positions "/> <VARIABLE SET INTEGER Option="\x00" Destination="%left1%" Value="0"/> <VARIABLE SET INTEGER Option="\x00" Destination="%left2%" Value="0"/> <VARIABLE SET INTEGER Option="\x00" Destination="%right1%" Value="0"/> <VARIABLE SET INTEGER Option="\x00" Destination="%spanright1%" Value="0"/> <VARIABLE SET INTEGER Option="\x00" Destination="%spanleft1%" Value="0"/> <COMMENT Value="Check for first right/left movement "/> <GET MOUSE POSITION Option="\x00" X="%left1%" Y="ypos"/> <DELAY Flags="\x13" Time="150"/> <GET MOUSE POSITION Option="\x00" X="%right1%" Y="ypos"/> <VARIABLE MODIFY INTEGER Option="\x01" Destination="%spanright1%" Value1="%right1%" Value2="%left1%"/> <IF VARIABLE Variable="%spanright1%" Condition="\x03" Value="%movement%" IgnoreCase="FALSE" _COMMENT="Did mouse move right?"/> <DELAY Flags="\x13" Time="400"/> <GET MOUSE POSITION Option="\x00" X="%left2%" Y="ypos"/> <VARIABLE MODIFY INTEGER Option="\x01" Destination="%spanleft1%" Value1="%right1%" Value2="%left2%"/> <IF VARIABLE Variable="%spanleft1%" Condition="\x03" Value="%movement%" IgnoreCase="FALSE" _COMMENT="Did mouse move left?"/> <MACRO RUN Use_ID="FALSE" Name="1_Close_Application_or_Browser_Window" ID="-1" Wait="TRUE"/> <END IF/> <END IF/> <COMMENT Value=" "/> <END IF/> <END REPEAT/> <COMMENT Value=" "/> <MACRO RETURN/> <COMMENT Value=" "/>
  20. For a black/white split area, where left and right margins are known and black is on the left, this script will find the dividing line within two or three pixels. It only retrieves 13 pixels. 13 may be one or two more than necessary -- I haven't done the exact math. For an area bigger than 1900 you might have to increase the Repeat count to 14 or 15. To get the exact dividing line a little more code would have to be added, to step through the last two or three pixels one at a time. I moved the mouse, and inserted a half-second delay during each Repeat, so I could watch it run. Get rid of the delay and it runs very quickly. // xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Variable Set Integer %left% to 1 Variable Set Integer %right% to 1900 // Repeat Start (Repeat 13 times) Variable Modify Integer: %midpoint% = %left% + %right% // midpoint of area to search is left margin plus right margin divided by 2 Variable Modify Integer: %midpoint% = %midpoint% / 2 // Mouse Move: %midpoint%, 400 Relative to Screen // move mouse to midpoint, get pixel color Get Pixel Color from Beneath the Mouse into %color% // If Variable %color% Equals "0" Variable Modify Integer set %left% to the contents of %midpoint% Else Variable Modify Integer set %right% to the contents of %midpoint% End If Delay: 500 milliseconds End Repeat // Text Box Display: Diagnostics // Macro Return <COMMENT Value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"/> <VARIABLE SET INTEGER Option="\x00" Destination="%left%" Value="1"/> <VARIABLE SET INTEGER Option="\x00" Destination="%right%" Value="1900"/> <COMMENT Value=" "/> <REPEAT START Start="1" Step="1" Count="13" Save="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x00" Destination="%midpoint%" Value1="%left%" Value2="%right%" _COMMENT="midpoint of area to search is left margin plus right margin divided by 2"/> <VARIABLE MODIFY INTEGER Option="\x03" Destination="%midpoint%" Value1="%midpoint%" Value2="2"/> <COMMENT Value=" "/> <MOUSE MOVE Option="\x01" X="%midpoint%" Y="400" _PROMPT="0x000A" _COMMENT="move mouse to midpoint, get pixel color"/> <GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%color%"/> <COMMENT Value=" "/> <IF VARIABLE Variable="%color%" Condition="\x00" Value="0" IgnoreCase="FALSE"/> <VARIABLE MODIFY INTEGER Option="\x06" Destination="%left%" Variable="%midpoint%"/> <ELSE/> <VARIABLE MODIFY INTEGER Option="\x06" Destination="%right%" Variable="%midpoint%"/> <END IF/> <DELAY Flags="\x12" Time="500"/> <END REPEAT/> <COMMENT Value=" "/> <TEXT BOX DISPLAY Title="Diagnostics" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs20 Black/White margin is at %midpoint%\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/> <COMMENT Value=" "/> <MACRO RETURN/>
  21. Binary search, of sorts. This would work extremely well to find the dividing line between two colors. Even a full-screen search 1920 pixels wide would only require retrieving about a dozen pixels. But for more than two colors it gets sketchy.
  22. If the macro is working, you must not have corrupted it enough to worry about. Here's a suggestion, somewhat related to your question: If you have to change the text with any frequency, you could maintain it in a Notepad document, where it is easy to edit. Your macro could open the Notepad text file, copy all to the clipboard, put clipboard contents into a variable, and type the variable. You would "never" have to touch the macro again.
  23. P.S. Getting pixel relative to window, I wanted to use the Windows clock as a timer. So I started the macro, then within a second or so I clicked down in the lower right of the screen to open up the calendar and clock display. As soon as I clicked and took focus away from the original window, the macro would complete almost instantly. I displayed the Repeat counter in a text box at the end of the repeats, so I know it was completing "normally". I would guess that when the window loses focus, ME bypasses whatever system interaction that otherwise would take all the time. If getting pixel relative to screen, then taking focus away didn't make a difference in timing.
  24. Yes, your macro runs painfully slowly on my PC, also. About 12 to 15 seconds. Doesn't matter whether I get colors relative to screen or relative to window. Windows 10 Pro, ME Pro 4.9.1.1
  25. I use that technique a lot. It looks like your code should work. If the macro isn't ending, are you sure the pixel is really changing to the color you want? Since you are checking for location relative to the screen (not the window), a slightly different window position or a different screen resolution (different computer?) could cause this. Also, sometimes certain shades on my screen will be made up of alternating pixel colors -- for example, getting a gray color by intermixing black and white pixels -- so if you are only one pixel off in location the test won't be reliable. For debugging purposes, put a Text Box Display inside the Repeat loop, right after the Get Pixel, displaying the N[2] value. Incidentally, I like to Repeat a set number of times -- then Repeat Exit when the desired color is detected -- rather than Repeat indefinitely like you are doing. For example, Repeat 100 Times, with a delay of 100ms on each pass through the loop, allows a nominal 10 seconds for the color to appear, then ends the loop no matter what. You can then check the color one more time, and display a message if it was not found. Here's an example: when the Repeat loop ends, either successfully or because the attempts are exhausted, the last color found is checked again to determine whether the search was successful or not. // Wait for "See Times" button to change color with mouse hovering over it Mouse Move: 957, 270 Relative to Screen Repeat Start (Repeat 100 times) Get Pixel Color from Beneath the Mouse into %N[1]% If Variable %N[1]% Equals "11355650" Repeat Exit Else Delay: 100 milliseconds End If End Repeat If Variable %N[1]% Equals "11355650" Mouse Left Click Macro Return Else Text Box Display: Error Macro Return End If
×
×
  • Create New...