Jump to content
Macro Express Forums

stevecasper

Members
  • Posts

    570
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by stevecasper

  1. thanks! if i simply use %HOMEDRIVE% without the %HOMEPATH%, then it will put the file directly into C: drive right? is %HOMEDRIVE% always C: drive, even if I have multiple drives? is the file called "random number"?

    %HOMEDRIVE% is probably your C: drive, though it could be different. I honestly don't know how to change it... I just know that at home, it is my C: drive, but at work it is my H: drive.

     

    You're welcome to change the path to anything you want. The macro command itself has a Browse button so you can browse to the exact folder you want the file to be created in. I just used the %HOMEDRIVE%%HOMEPATH% text to make the macro immediately useable for anybody who copied the script directly into a new macro.

     

    The file name is Random Number, yes. Note that I did not add an extension (like .txt). So the file may not show up if you browse down the path. You can change the macro to create the file as Random Number.txt if you would like. It will not affect the macro's performance either way.

  2. I have several macros that open a text box and update its contents periodically. Whenever these text boxes are open, my other macros lag and hang, becoming inefficient.

     

    Has anybody else noticed similar problems?

     

    As an example:

     

    Macro 1:

    Read Registry Value to %TVariable%

    Text Box Display: %TVariable%

    Repeat Until %T1%<>%T1%

    Read Registry Value to %TVariable%

    __Update Text Box

    Delay: 5 seconds

    Repeat End

     

    Macro 2:

    //At some point there may be cause to write a different value to the Registry Value being read in Macro 1. While the text box from Macro 1 is displayed, Macro 2 drags and drags.

     

    The information in the Registry Value is important. It's useful to have it visible while processing my work. I have considered utilizing a notepad for this, but I can't make a Notepad stay visible.

     

    Of course, with the Text Box Update, I can keep it on top without keeping focus, but that doesn't stop it from regaining focus when it updates. So I'm having to deal with the little problems that that causes to some of my other processes, but I just really thought having the Text Box Display/Update would be more fun than a boring old notepad stuffed in a corner.

     

    I don't know if the problem is universal, or specific to my crappy work PC. I haven't tested it on my home PC, yet. I may do that tonight or maybe sometime over the weekend.

  3. Thanks! But what is the default folder of C: drive? Does running the macro leave a file behind?

     

    BTW: These are the commands to be removed if I want to remove prompts, etc. right?

     

    Variable Set Integer %N4% from Prompt
    
    Variable Set Integer %N3% from Prompt
    
    Text Box Display: This Text Box Represents The Rest of Your Macro

     

    Also, is it possible to have a lighter version of the macro without the non-zero correction? So that the minimum is always 0 but the max can be changed.

    Here is the Light Version. You can still choose what the Max will be (though I've removed the prompt, so you'll need to establish the maximum

    within the Variable Set Integer %N3% command).

     

    I don't know what your default folder is. It depends on your user profile, I believe. On my home computer %HOMEDRIVE%%HOMEPATH% is the "Steven" folder

    on my desktop; at work it is simply H:/ . It will be something different on your computer. You can figure out exactly where by building a simple macro like this one:

     

    (this is the Direct Editor text... that's how simple this macro is)

    <LAUNCHDEL2:0:01%HOMEDRIVE%%HOMEPATH%>

     

    This macro (the one that makes sure the random number does not repeat) does leave a file behind (it has to in order to make certain the comparisons

    are consistent). You can delete the file manually, or you can build a second macro with the following code to find it and delete it:

     

    Again, this is just Direct Editor script:

    <DOFILE:08:NN:%HOMEDRIVE%%HOMEPATH%/Random Number>>

     

    And now, what we've all been waiting for, the Light Version:

    // %N1% Random Number
    // %N2% Previously Generated Random Number
    // %N3% Maximum Value of Randomly Generated Number
    // %T1% Text Variable Used to Facilitate New and Old Number Comparisons
    // %HOMEDRIVE%%HOMEPATH% - Essentially represents C: Drive and your default folder.
    // This may be different for every computer, so I used these defaults because they should work for anybody.
    Variable Set Integer %N3% to 10
    Repeat Until %T1% <> %T1%
     If File Exists "%HOMEDRIVE%%HOMEPATH%/Random Number"
    Variable Set String %T1% from File: "%HOMEDRIVE%%HOMEPATH%/Random Number"
    Variable Modify String: Convert %T1% to integer %N2%
     Else
    Variable Set Integer %N2% to %N3%
    Variable Modify Integer: Inc (%N2%)
     End If
     Variable Set Integer %N1% with a Random Number
     If Variable %N1% <> variable %N2%
    Variable Modify Integer: Convert %N1% to text string %T1%
    Variable Modify String: Save %T1% to Text File
    Break
     End If
    Repeat End
    Text Box Display: This Text Box Represents The Rest of Your Macro

     

    <REM2:%N1% Random Number><REM2:%N2% Previously Generated Random Number><REM2:%N3% Maximum Value of Randomly Generated Number><REM2:%T1% Text Variable Used to Facilitate New and Old Number Comparisons><REM2:%HOMEDRIVE%%HOMEPATH% - Essentially represents C: Drive and your default folder.><REM2:This may be different for every computer, so I used these defaults because they should work for anybody.><IVAR2:03:01:10><REP3:08:000002:000001:0001:1:01:T1><IFOTH:01:2:%HOMEDRIVE%%HOMEPATH%/Random Number><TVAR2:01:04:%HOMEDRIVE%%HOMEPATH%/Random NumberT><TMVAR2:05:01:02:000:000:><ELSE><IVAR2:02:01:%N3%><NMVAR:08:02:0:0000001:0:0000000><ENDIF><IVAR2:01:06:%N3%><IFVAR2:5:01:2:N2><NMVAR:05:01:0:0000001:0:0000000><TMVAR2:17:01:00:000:000:%HOMEDRIVE%%HOMEPATH%/Random NumberF><BREAK><ENDIF><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:This Text Box Represents The Rest of Your MacroCurrent Number: %N1%>

     

    And yes, you may remove the final Text Box display... it's just there to let you know where to add the rest of your macro.

  4. But now, Scasper, you're damaging and starving my ego! How are you going to make amends for that?

     

    I'm a sucky lick-spittle, what can I say.

     

    Hmmm... You were quicker on the draw than I was (in fact I've noticed you to be quicker than me on a number of occasions) at the beginning of this thread. And after Cory's recent embarrassing admissions, I would dare-say you are now king of Macro Express.

     

    How's that?

     

    Probably too much sarcasm... I don't actually find Cory's admissions embarrassing. I could barely follow them. So if you at least could empathize with Cory on how overwhelming learning VB is/can be, then you are doing better than me.

     

    I believe VB stands for Visual Basic, but I honestly thought VB, VBA and VBScript were all just terms for the same basic thing.

     

    And PASCAL? Seriously? I mean, I learned a smattering of BASIC to make silly little Zork-style programs on my family's TI (closest thing we had to a home computer until the mid '90s) when I was 8 or 9 (Note: I had no idea what Zork was at that time). Then in Jr. Highschool I took a computer programming class (this was '89-'90) where we re-hashed the BASIC I already knew and nothing more, though I did learn about pixels and how to program frighteningly-archaic pictures by coloring pixels in specific points - Let's just say that PacMan had better graphics than anything I could have programmed at that point.

     

    Anyway, I figure if nothing else, everybody's ego can be boosted by comparing their skills to my remedial programming expertise.

  5. yes, you understand me correctly. it would be great to see how it can be done. :)
    I have what I believe to be a working model for your macro.
    BTW: it seems macro express' random integer generator might have a slight bug, and generates the same number twice in a row too often. even if i set the number range higher, the frequency of the problem occuring still seems the same.

    That is weird. I haven't noticed that, myself, but I don't work with randoms very often. My wife is a highschool Mathematics and Statistics teacher, and she

    has told me that not even computers have the capacity to generate completely random sequences. An underlying pattern always emerges.

     

    Of course, I argue that true randomness will always generate the appearance of a pattern. They say if you give a monkey a typewriter and infinite time, and he

    will eventually produce the complete works of Shakespear - I think that's false, because the monkey will likely develop a preference for a specific key. However,

    if you replace the monkey with a computer typing randomly for infinite time, you will end up with the complete works of Shakespear (and everything else ever

    written - or that ever will be written - by man... and probably some really good recipes, too).

     

    With that said, if you think there is a definite problem with the randomness of the program, I'd suggest contacting ISS support directly.

     

    Now, on to the fun.

     

    This macro is a bit longer than I had expected, but still very reasonable. The prompts at the beginning can be removed, as long as you know you will always use

    the same minimum and maximum numbers. Just set N4 to you standard minimum and N3 to your standard maximum and remove the prompts.

     

    // %N1% Random Number
    // %N2% Previously Generated Random Number
    // %N3% Maximum Value of Randomly Generated Number
    // %N4% Minimum Value of Randomly Generated Number
    
    // Note:  The Random Number Generator has a minimum default of 0 wich cannot be changed.
    // __Because of this, we have to manipulate the values of %N1% and %N3%
    // __I will set these manipulations apart in the body of the text with surrounding  *** Remarks
    // __When N1 is generated it could = 0.  If the min is set at 1, then N1 must be increased 
    // __by the value of N4 (in this case, 1) in order to ensure N1 >= 1.
    // __If the max (N3) is 10, then increasing N1, could result in N1 > N3 (which we must avoid.).  
    // __So we start by reducing N3 by the value of N4 to ensure that when N1 is increased, 
    // __N1 does not exceed N3.
    
    // %T1% Text Variable Used to Facilitate New and Old Number Comparisons
    // %HOMEDRIVE%%HOMEPATH% - Essentially represents C: Drive and your default folder.
    // This may be different for every computer, so I used these defaults because they should work for anybody.
    Variable Set Integer %N4% to 1
    Variable Set Integer %N4% from Prompt
    Variable Set Integer %N3% to 10
    Variable Set Integer %N3% from Prompt
    // ***
    Variable Modify Integer: %N3% = %N3% - %N4%
    // ***
    Repeat Until %T1% <> %T1%
     If File Exists "%HOMEDRIVE%%HOMEPATH%/Random Number"
    Variable Set String %T1% from File: "%HOMEDRIVE%%HOMEPATH%/Random Number"
    Variable Modify String: Convert %T1% to integer %N2%
     Else
    Variable Set Integer %N2% to %N3%
    Variable Modify Integer: Inc (%N2%)
     End If
     Variable Set Integer %N1% with a Random Number
     // ***
     Variable Modify Integer: %N1% = %N1% + %N4%
     // ***
     If Variable %N1% <> variable %N2%
    Variable Modify Integer: Convert %N1% to text string %T1%
    Variable Modify String: Save %T1% to Text File
    Break
     End If
    Repeat End
    Text Box Display: This Text Box Represents The Rest of Your Macro

    <REM2:%N1% Random Number><REM2:%N2% Previously Generated Random Number><REM2:%N3% Maximum Value of Randomly Generated Number><REM2:%N4% Minimum Value of Randomly Generated Number><REM2:><REM2:Note:  The Random Number Generator has a minimum default of 0 wich cannot be changed.><REM2:__Because of this, we have to manipulate the values of %N1% and %N3%><REM2:__I will set these manipulations apart in the body of the text with surrounding  *** Remarks><REM2:__When N1 is generated it could = 0.  If the min is set at 1, then N1 must be increased ><REM2:__by the value of N4 (in this case, 1) in order to ensure N1 >= 1.><REM2:__If the max (N3) is 10, then increasing N1, could result in N1 > N3 (which we must avoid.).  ><REM2:__So we start by reducing N3 by the value of N4 to ensure that when N1 is increased, ><REM2:__N1 does not exceed N3.><REM2:><REM2:%T1% Text Variable Used to Facilitate New and Old Number Comparisons><REM2:%HOMEDRIVE%%HOMEPATH% - Essentially represents C: Drive and your default folder.><REM2:This may be different for every computer, so I used these defaults because they should work for anybody.><IVAR2:04:01:1><IVAR2:04:02:FWhat is the minimum random value?FFCenter:Center><IVAR2:03:01:10><IVAR2:03:02:FWhat is the maximum random value?FFCenter:Center><REM2:***><NMVAR:02:03:1:0000003:1:0000004><REM2:***><REP3:08:000002:000001:0001:1:01:T1><IFOTH:01:2:%HOMEDRIVE%%HOMEPATH%/Random Number><TVAR2:01:04:%HOMEDRIVE%%HOMEPATH%/Random NumberT><TMVAR2:05:01:02:000:000:><ELSE><IVAR2:02:01:%N3%><NMVAR:08:02:0:0000001:0:0000000><ENDIF><IVAR2:01:06:%N3%><REM2:***><NMVAR:01:01:1:0000001:1:0000004><REM2:***><IFVAR2:5:01:2:N2><NMVAR:05:01:0:0000001:0:0000000><TMVAR2:17:01:00:000:000:%HOMEDRIVE%%HOMEPATH%/Random NumberF><BREAK><ENDIF><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:This Text Box Represents The Rest of Your MacroCurrent Number: %N1%>

  6. yes the 2nd code is more what im looking for. but how can i make the variable stay internal to the macro without showing or prompting for the text boxes?

     

    basically, i just want the variable to generate a random number and then end. but if it generates the same number as the previous macro run, i want it to generate a new one until it's different, before continuing...

    You can delete or disable the command lines you don't want (i.e. the Text Box Display commands).

     

    If I understand you correctly, you want the following:

    • You run the macro.
    • The macro generates a random number.
    • The macro does something with that number.
    • The macro ends.

    • You run the macro again.
    • The macro generates a new number which does not match the previous number.
    • The macro does the same thing it did the last time you ran the macro.
    • The macro ends.

     

    When I get a few minutes today, I'll tweak my macro above to do just this. In the mean time, I recommend you take my macros and play with them a bit. Tweak them on your own, and get a feel for how they work. It's really the best way to learn how to build your own.

     

    I'll be back in a little while with an example of how to do what I've understood you to need.

  7. I am trying to capture text from a particular field in a database program. The Get Control command identifies the name of the control, but not the data in it (All I get is a blank) . Is there some other way to capture data from a particular field without using the Get Control Command.

     

    Joe

     

    If the Control is recognized by Macro Express, then you can use the Mouse Click in Control command. Then you can use a Text Type: Ctrl+A to highlight the contents of the control (you could also probably double-click within the control, rather than use Ctrl+A). Clipboard Copy command. Set Variable to contents of clipboard.

     

    Unless the Control is a button, this should work.

  8. Well after all that work, I just realized you don't mind if numbers repeat. You just don't want them to repeat twice in a row. Whoops!

     

    Still, based on the macros I built, it should be simple enough to figure out how to make basic comparisons to make sure two numbers aren't

    provided twice in a row. Should also minimize lag :) Sorry about that!

     

    EDIT

    This is closer to what you wanted, I believe.

     

    Variable Set Integer %N1% to 10
    Variable Set Integer %N1% from Prompt
    Repeat with Variable using %N1%
     Variable Set Integer %N1% with a Random Number
     Variable Modify Integer: Convert %N1% to text string %T1%
     If Variable %T2% <> variable %T1%
    Variable Modify String: Copy %T1% to %T2%
    Variable Modify String: Append "%T1% " to %T3%
    Text Box Display: %T1%
     Else
     End If
    Repeat End
    Text Box Display: All Generated Numbers

    <IVAR2:01:01:10><IVAR2:01:02:FHow many numbers do you need generated?FFCenter:Center><REP3:05:000001:000001:0001:0:01:><IVAR2:01:06:10><NMVAR:05:01:0:0000001:0:0000000><IFVAR2:4:02:2:T1><TMVAR2:09:02:01:000:000:><TMVAR2:07:03:00:000:000:%T1% ><DIS:<TBOX4:T:1:CenterCenter000278000200:000:%T1%Your randomly generated number is:
    
    %N1%><ELSE><ENDIF><ENDREP><TBOX4:T:1:CenterCenter000278000200:000:All Generated Numbers%T3%>

  9. Anyone know to make a variable not repeat the same number twice in a row? Thanks.

    Ok, so I like a challenge. Here are two macros that both do what you want. The first one is very basic, so you can pick it apart easily and see how it's done.

     

    The second one is arguably better. It's much more complex, and allows you to select the maximum value of your random generator from a prompt.

     

    For both of these macros, I've set the default maximum to 10, and left the default minimum at 0. Mathematically, that leaves 11 possible numbers that could be generated.

     

    Please keep in mind, that as you start running out of numbers, the macro may lag as it ignores previous results and tries again. Theoretically, this lag could last forever.

    Because of that, the 2nd macro has a built-in "escape". After 100,000 failures, you'll get a pop-up asking you if you want to continue. If you say Yes, it will try again, up to

    100,000 more times, before prompting you again.

     

    With only 11 numbers to choose from, you'll see that pop up a surprising number of times when you get down to only 1 or 2 numbers left.

     

    I tested this macro with 101 possibilities. The 100,000 Failures error began in the early 70s and by 88 was happening very frequently.

     

    Anyway, here are the two macros. I'm providing both Scripting Editor and Direct for the simple one. The complex one will only have Direct Editor.

     

    Repeat Until %T1% <> %T1%
     Variable Set Integer %N1% with a Random Number
     Variable Modify Integer: Convert %N1% to text string %T1%
     If Variable %T2% does not contain variable %T1%
    Variable Modify String: Append "%T1% " to %T2%
    Text Box Display: %T1%
     Else
    Text Box Display: No Unique Number Generated
     End If
    Repeat End

    <REP3:08:000002:000001:0001:1:01:T1><IVAR2:01:06:10><NMVAR:05:01:0:0000001:0:0000000><IFVAR2:4:02:8:T1><TMVAR2:07:02:00:000:000:%T1% ><TBOX4:T:1:CenterCenter000278000200:000:%T1%Your randomly generated number is:
    
    %N1%><ELSE><TBOX4:T:1:CenterCenter000278000200:000:No Unique Number GeneratedNumbers generated so far:
    
    %T2%><ENDIF><ENDREP>

     

    Complex Macro:

    <IVAR2:02:01:10><IVAR2:02:02:FWhat is the maximum value?FFCenter:Center><TVAR2:04:01:all><REP3:08:000002:000001:0001:1:01:T1><NMVAR:01:06:1:0000002:2:0000001><IVAR2:01:06:%N2%><NMVAR:05:01:0:0000001:0:0000000><IFVAR2:4:02:8:T1><TMVAR2:07:02:00:000:000:%T1% ><TBOX4:T:1:CenterCenter000278000200:000:%T1%Your randomly generated number is:
    
    %N1%><IVAR2:07:01:0><ELSE><TMVAR2:09:03:02:000:000:><TMVAR2:21:03:01:000:000: ><IVAR2:03:12:3><IVAR2:04:12:2><NMVAR:02:03:1:0000004:1:0000003><REP3:01:000001:000001:10000:1:05:><IFVAR2:2:07:1:100000><IFMESS3:00000:1:1:%N7% FailuresYou've generated %N3% of %N6% possibilities.  Further unique selections from this sample may be delayed indefinitely.
    
    Would you like to continue?000529:000433><IVAR2:07:01:0><ELSE><IVAR2:07:01:%N3%><NMVAR:01:03:1:0000002:1:0000002><TVAR2:04:01:%N7%><BREAK><ENDIF><ENDIF><IFVAR2:2:05:1:10000><NMVAR:01:07:1:0000005:1:0000007><ENDIF><ENDREP><IFVAR2:5:03:4:N2><BREAK><ENDIF><ENDIF><ENDREP><TBOX4:T:1:001781Center000344000200:000:That Should Be ItYou've generated %T4% of the numbers between 0 and %N2%
    
    %T2%>

  10. Anyone know to make a variable not repeat the same number twice in a row? Thanks.

    I'm assuming you're using the Set Integer To A Random Value command.

     

    My first instinct is to tell you to modify the N variable (converting to Text String). Do this each time a random number is generated, and append each one to a separate text string (be sure to include a space after each number appended). Now use an If Variable Contains command to determine if the number has already been used. If so, you have the Set Integer command try again and again until it selects a value not yet used.

     

    There might be a simpler way, but this is what came to mind first.

  11. Your are correct Steve but my ego compels me to explain that I left out that bit on purpose. I often have a lot of checks and handling in my code for things like this but I often omit them for clarity so the audience can more easily grasp the essence of what I am suggesting. However your suggestion is one I had not considered before so I'll have to bear that in mind for the future. Usually I use some combined logic.

    I don't begrudge you your ego, as far as ME is concerned, I think you've earned it. Frankly, I was a little doubtful that I had discovered an actual flaw in your code. In fact, I didn't think it was a flaw, so much as a simplified version of what would actually be needed. Which you have just pointed out, in a sense, that it was.

     

    Your code was also much more in line with what Terry was actually trying to accomplish, so you offered up a more appropriate nugget to work with than Paul or I had.

     

    How's that for feeding your ego? Maybe I should stop encouraging you ;)

  12. I don't understand what Terry is trying to do. Is running a macro to run in the scripting editor? If so I think one can use an alternate symbol, for instance the pipe "|" and then replace it. Many macro variable commands cause an evaluation of variables but apparently the replace does not. I have a macro now that processes the titles of windows and in some cases one will get percents up there. I simply replace them with pips, do my thing, then put them back.

    That's what I would have done, too, but it doesn't work.

     

    You can replace the % with something else, make the macro do all it needs to, then change the "substitute" character(s) back to %s. This all works.

     

    But if you try to trim the variable containing the wayward %s, or if you try to save it to the clipboard, the macro fails. It causes a "Variable Not Set or Incorrect Variable Type" error.

  13. oh brother do I live in that world

     

    have you had any success getting others to adopt them and if so how

    Honestly, no. My company purchased about 10 licenses to be used exclusively in my department almost 2 years ago. I was tasked with building macros to distribute to the rest of my team.

     

    I was limited by a number of factors, however:

    • I was given absolutely no on-the-clock time to build macros. Forcing me to sacrifice personal time to build them (what I really ended up doing, was building the macros for myself while I should have been working, then utilizing those macros to play catch-up so my productivity didn't suffer - and then I tweaked them (read: dumbed them down) for distribution.
    • All macros I built had to be submitted to the guy who actually researched automation tools, but who had little-to-no experience actually building macros.
    • All macros submitted to him had to be approved by senior management for the department.
    • All macros had to be password protected to prevent fiddling (read: tweaking/improving) by other members of my team (I couldn't change their minds about that), despite the fact that no two computers in the department are even close to the same (the closest we get is that most PCs are HPs, and all are running XP Pro, but the rest of the specs vary widely)
    • Most of the people I work with range from technilogically challenged to technophobe, with one or two others whow are either "too good for automation" or so set in their ways, that learning to run a macro is just too much work... or something.

     

    So, thanks to the first 2 or 3 items above, distribution was a nightmare. Training on using them was a bear. And actually following-up with people to see if they were using them, and if they had any suggestions or problems was non-existent.

     

    Though I love the potential MEP has, as buggy and inconsistent as it is on my machine (I used to have the worst machine in the department, so any macro that worked on my machine would work on everybody's... my new machine is in the top 2-3, performance-wise, so if they don't run on mine, they won't run on anybody's), there is no chance I'll be able to ever convince management to upgrade our licenses. At least not in the near future.

  14. Sounds like you're using a laptop!

     

    BTW, I'm curious what your first steps are when replying to a forum post, without using the mouse. Do you tab several times to get to the Reply button, or what? Hotkey-activated macro? :rolleyes:

     

    --

    Terry, East Grinstead, UK

    Nope, not using a laptop. I have semi-bad joints, so a lot of repetitive motion gets to me quickly. The back-and-forth of going to and from the mouse all day long bothers my shoulder and my elbow in a hurry.

     

    I've also found that, for the most part, anything that can be done from the keyboard is considerably more efficient. I know people who use the mouse to highlight and r-click for copy and paste. I learned how to use Shift and Ctrl+Shift with Arrow keys for highlight so many years ago I can't recall, and I knew Ctrl+C and Ctrl+V for copy/paste before I knew you could use r-click for those functions.

     

    So, if it can be done on the keyboard, I do it on the keyboard. If not, I build a macro that will do it through the keyboard. If even that's too cumbersome, then I still use the mouse.

     

    When posting to the forum, I navigate with the mouse. Again, it's the repetitive motion of back and forth that is problematical. If my hand is already on the mouse, then it's not a problem. So for functions that leave my hand on the mouse for a few minutes, or for numerous consecutive functions, it isn't a problem. Clicking through websites, for example, is not usually a problem.

     

    It's when my job-function (or anything else, really) calls for: Type a word or two, mouse-move and click, Type a word or two, mouse-move and click, etc... that I get annoyed.

     

    When using the Variables button within an MEP function (like what we were discussing in this thread), I will usually tab to that button, and Enter to open it, but then the menus themselves can't be opened by any combination of keystrokes (to my knowledge), requiring me to use the mouse. And since the menus are not very efficiently built in the first-place, I hate that method... though I do use it when I really need to.

  15. - Prompts you with a full list of variables from which to choose those to display
    True, and I use it (occasionally)... but it's mouse-intensive and I hate using the mouse... ever.

     

    - Avoids typing
    I'd rather type than use the mouse :)

     

    - Eliminates spelling mistakes
    Also true. However I find I misspell more often when I'm worrying about typing % and [ and ]... I frankly hate the whole brackets concept with regard to variable arrays, but I accept them as a necessary evil. I just mis-type them very often. It's nice that the backspace key is located so close to the bracket keys.
  16. Thanks Paul. My intention was a bit more complex. The results had to go in the same box and had to work with real variables, in use within the same macro. Your method fails in practice because the variables get substituted. As discussed in that thread I referenced.

     

    ...

     

    Can anyone suggest a less obscure method please?

     

    --

    Terry, East Grinstead, UK

    Hey Terry,

     

    I think I may have skipped this thread, as my solution would have been what Paul suggested (about replacing the % with

    something else), but now that I've tied this thread together in my mind with the other one, I came back. And now that I'm

    home I can actually see the embedded images you've provided. And what you're trying to do is something that I would

    like to be able to do as well, but have been too lazy to bother working on it.

     

    Until now, apparently.

     

    From what I can see, you're putting the Variable name in first, and want the macro to copy the variable, duplicate it, and

    strip the % from the first instance but not the second. I would personally suggest a different method. Since I hate typing

    % signs around my variables, I would recommend typing out only the variable name without % signs, and then run

    the following macro (sans text boxes), which will do exactly what you need it to do.

     

    It is a very close representation of the macro Cory built and I modified, but now modified further for this particular case:

     

    Text Box Display: Copy text
    Delay: .25 seconds
    Variable Set String %topwindow% to topmost window title
    Variable Set to ASCII Char 10 to %LF%
    Variable Set to ASCII Char 13 to %CR%
    Variable Set String %Clip% from the clipboard contents
    Variable Modify String %Clip%: Append Text (%CR%%LF%)
    Variable Set Integer %Position% to the position of "%CR%" in %Clip%
    Repeat Until %Position% Equals "0"
     Variable Modify Integer %Position%: Decrement
     Variable Modify String: Copy a substring in %Clip%, starting at 1 and %Position% characters long to %Chunk%
     Variable Modify Integer: %Position% = %Position% + 2
     Variable Modify String %Clip%: Delete a substring starting at 1 and %Position% characters long
     Variable Set Integer %Position% to the position of "%CR%" in %Clip%
     Variable Modify String %Output%: Append Text (%Chunk% = %%Chunk%%%CR%%LF%)
    End Repeat
    Window Activate: %topwindow%
    Delay: .25 seconds
    Text Type (Use Clipboard and Paste Text): %Output%

    <TEXT BOX DISPLAY Title="Copy text" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Copy text to the clipboard, then click OK.\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="TRUE" Keep_Focus="FALSE" Mode="\x00" Delay="0"/>
    <DELAY Flags="\x01" Time=".25"/>
    <VARIABLE SET STRING Option="\x05" Destination="%topwindow%"/>
    <VARIABLE SET TO ASCII CHAR Value="10" Destination="%LF%"/>
    <VARIABLE SET TO ASCII CHAR Value="13" Destination="%CR%"/>
    <VARIABLE SET STRING Option="\x02" Destination="%Clip%"/>
    <VARIABLE MODIFY STRING Option="\x06" Destination="%Clip%" Value="%CR%%LF%"/>
    <VARIABLE SET INTEGER Option="\x0E" Destination="%Position%" Text_Variable="%Clip%" Text="%CR%" Ignore_Case="FALSE"/>
    <REPEAT UNTIL Variable="%Position%" Condition="\x00" Value="0"/>
    <VARIABLE MODIFY INTEGER Option="\x08" Destination="%Position%"/>
    <VARIABLE MODIFY STRING Option="\x09" Destination="%Chunk%" Variable="%Clip%" Start="1" Count="%Position%"/>
    <VARIABLE MODIFY INTEGER Option="\x00" Destination="%Position%" Value1="%Position%" Value2="2"/>
    <VARIABLE MODIFY STRING Option="\x0A" Destination="%Clip%" Start="1" Count="%Position%"/>
    <VARIABLE SET INTEGER Option="\x0E" Destination="%Position%" Text_Variable="%Clip%" Text="%CR%" Ignore_Case="FALSE"/>
    <VARIABLE MODIFY STRING Option="\x06" Destination="%Output%" Value="%Chunk% = %%Chunk%%%CR%%LF%"/>
    <END REPEAT/>
    <WINDOW ACTIVATE Title="%topwindow%" Exact_Match="FALSE" Wildcards="FALSE" _IGNORE="0x0006"/>
    <DELAY Flags="\x01" Time=".25"/>
    <TEXT TYPE Action="1" Text="%Output%"/>

     

    The problem I've been having is that it doesn't seem possible to Trim or Save to Clipboard if the contents of the

    %Output% variable contains undefined variables in quotes. Now the trick of switching % with something else is a fine

    idea, except that you have to switch it back before saving it to the clipboard, at which point the macro fails.

     

    So the solution I found and used above is simply to have the macro do a text type paste, requiring that you use some

    activate window commands. But all-in-all, it's fairly functional.

  17. I would copy the entire thing to a var and do it all in memory. Splitting into an array sounds like a good idea but one doesn't know how many elements one would have. And we would still need a loop to reassemble output so we might as well chew away at it. See the attached file.

     

    Variable Set to ASCII Char 10 to %LF% // Create a carrige return variable
    Variable Set to ASCII Char 13 to %CR% // Create a Line Feed varaible
    Text Box Display: Howdy! // Warn/prompt  user
    Variable Set String %Clip% from the clipboard contents // Get our source data from the clipboard
    Variable Set Integer %Position% to the position of "%CR%" in %Clip% // Find the first End of Line character (CR)
    Repeat Until %Position% Equals "0" // Repeat until there are no more EoLs.
    I get the positon of the next CR at the end of the loop. If there are none it will be zero and this controls the exit.
     Variable Modify Integer %Position%: Decrement // Move back one space so I don't copy the CR out
     Variable Modify String: Copy a substring in %Clip%, starting at 1 and %Position% characters long to %Chunk% // Copy out the first line w/o EoL
     Variable Modify Integer: %Position% = %Position% + 2 // Mov the pointer to the last EoL character
     Variable Modify String %Clip%: Delete a substring starting at 1 and %Position% characters long // Delete the entire line inclusing EoL
     Variable Set Integer %Position% to the position of "%CR%" in %Clip% // Get the position of the first EoL char.
    I put it here instead of the beginning to control the loop.
     Variable Modify String %Output%: Append Text (%Chunk% %Chunk%%CR%%LF%) // Append my outpur var with the chunks and an EoL
    End Repeat
    Variable Modify String: Save %Output% to the clipboard // Push output to the clipboard
    Text Box Display: Yup!

    I just tried this one, too, since it performs more exactly what Terry originally requested (creating files was offered by Paul and I, whereas Terry just wanted to modify a "live" notepad).

     

    I discovered a problem, however, that requires additional commands to rectify.

     

    This code assumes the text being copied ends with a line-break. If it does not, the macro will stop processing on the pen-ultimate line, and the last line will not be appended to the %Output% variable.

     

    The simple fix is to add this simple line just after setting the %Clip% variable from the clipboard contents.

     

    Variable Modify String %Clip%: Append Text (%CR%%LF%)

     

    This will ensure that the macro continues until all lines have been duplicated and placed in the Output variable.

     

    At this point you may want to add one or two more lines of code after the End Repeat command, depending on what you want.

     

    If the text copied did end with a CR/LF, then you'll end up with an extra one placed in your clipboard when the %Output% variable gets pushed.

     

    So you simply need to Trim the Output variable.

     

    This will get rid of all the ending line-breaks. At this point you might want to append one more %CR%%LF% to the Output variable (if you do want a final line-break).

  18. I could buy pro myself but why would I want to do that when I will become the only one that can use those macros?

     

    That is actually exactly what I did. I did it for a few reasons. Mainly, I did it in order to learn the MEP fuctionality so that if the company ever did decide to splurge, I would be prepared for it. However, I also tend to be the only person who uses Macros for most of my work (everybody else seems to fear them), so I figured I would at least be able to benefit from the enhanced product.

     

    Of course the few macros that everybody else uses are tried and true and they don't have to live with the bugs that are still being tweaked out of MEP the way I do.

  19. Consider the first time you enter the loop. As you haven't initialized %Snapshot%, its value is zero. So you're executing this command:

    Get Pixel Color from Beneath the Mouse into %N0%

     

    There's no such variable, since N variables go from N1 to N99.

     

    If you first set %Snapshot% to 1, it all works as expected.

    I second Paul's solution. You've got a few options, too.

     

    You could simply define %Snapshot% before beginning the repeat loop; however, my preferred method would be this:

     

    Repeat Start (Repeat 99 times) // Store counter in %Snapshot%
     Get Pixel Color from Beneath the Mouse into %N[%Snapshot%]%
     Text Box Display: 
     Delay: 100 milliseconds
    End Repeat
    Text Box Display:

     

    <REPEAT START Start="1" Step="1" Count="99" Save="TRUE" Variable="%Snapshot%"/>
    <GET PIXEL COLOR Option="\x00" Rel_To_Screen="TRUE" Destination="%N[%Snapshot%]%"/>
    <TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 Snapshot = \\f1 %Snapshot%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>
    <DELAY Flags="\x02" Time="100"/>
    <END REPEAT/>
    <TEXT BOX DISPLAY Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang2057{\\fonttbl{\\f0\\fnil Tahoma;}{\\f1\\fnil\\fcharset0 Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\f0\\fs16 %N[1]%\r\n\\par %N[\\f1 2\\f0 ]%\r\n\\par %N[\\f1 3\\f0 ]%\r\n\\par %N[\\f1 4\\f0 ]%\r\n\\par %N[\\f1 5\\f0 ]%\r\n\\par %N[\\f1 6\\f0 ]%\r\n\\par %N[\\f1 7\\f0 ]%\r\n\\par %N[\\f1 8\\f0 ]%\r\n\\par %N[\\f1 9\\f0 ]%\r\n\\par %N[\\f1 10\\f0 ]%\r\n\\par %N[1\\f1 1\\f0 ]%\r\n\\par %N[1\\f1 2\\f0 ]%\r\n\\par %N[1\\f1 3\\f0 ]%\r\n\\par %N[1\\f1 4\\f0 ]%\r\n\\par %N[1\\f1 5\\f0 ]%\r\n\\par %N[1\\f1 6\\f0 ]%\r\n\\par \r\n\\par }\r\n" Left="Center" Top="Center" Width="278" Height="200" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

     

    By using Repeat Start rather than Repeat Until, you still get to specify 99 iterations. But since you're storing the counter in %Snapshot%, you never have to define Snapshot = 1 and you never have to use the Modify Variable Increment command on Snapshot, as the Counter will increment it automatically. So you eliminate two steps by combining them all within the Repeat Start command.

     

    That's my suggestion.

  20. If you need to parse the content of each line into separate elements of an array use the ASCII File Begin/End Process commands. However, if, as seems to be the case here, you want each complete line, use the Text File Begin/End Process command. This would change Steve's macro to something like this (untested):
    Text File Begin Process: "C:\Documents and Settings\z051940\Desktop\Lines.txt" (Tab Delimited Text (.txt))
     Variable Set String %ModifiedProcess% to "%LineProcess% %LineProcess%"
     Variable Modify String: Append %ModifiedProcess% to text file, "C:\Documents and Settings\z051940\Desktop\Lines2.txt"
    Text File End Process
    Copy File/Files: "C:\Documents and Settings\z051940\Desktop\Lines2.txt" to "C:\Documents and Settings\z051940\Desktop\Lines.txt"
    Delete File/Files: "C:\Documents and Settings\z051940\Desktop\Lines2.txt"

    Yep, definitely better. I went with ASCII because I use it a lot, but Text File process is definitely better for a simple text file like this, i.e. no tabs to delimit.

     

    The primary difference is that there aren't any arrays to handle, so rather than worrying about %LineProcess[x]%, you just have %LineProcess%.

     

    Definitely prettier.

     

    I adjusted my macro to reflect Kevin's observation, and it tests true.

     

    <TEXT FILE BEGIN PROCESS Filename="C:\\Documents and Settings\\z051940\\Desktop\\Lines.txt" Start_Record="1" Process_All="TRUE" Records="1" Variable="%LineProcess%"/>
    <VARIABLE SET STRING Option="\x00" Destination="%ModifiedProcess%" Value="%LineProcess% %LineProcess%"/>
    <VARIABLE MODIFY STRING Option="\x12" Destination="%ModifiedProcess%" Filename="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" CRLF="TRUE"/>
    <TEXT FILE END PROCESS/>
    <COPY FILE/FILES Source="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" Dest="C:\\Documents and Settings\\z051940\\Desktop\\Lines.txt" Progress="FALSE" Recurse="FALSE"/>
    <DELETE FILE/FILES Path="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" Progress="FALSE" Recurse="FALSE" Permanent="FALSE"/>

  21. I built this macro for you, Terry. Tested it with 100% success.

     

    I took your test text and saved it into a .txt file on my desktop. The file name: Lines.txt

     

    I set each line of the process to variable %LineProcess[x]%. (Note that for this particular macro x will always be 1 - there are not Tabs to delimit)

     

    I then set variable %ModifiedProcess% as: %LineProcess[1]% %LineProcess[1]%

     

    At this point, I append the variable %ModifiedProcess% to a new text file (Line2.txt) with trailing CR/LF checked.

     

    The process repeats until all lines have been processed.

     

    I now copy file Lines2.txt to file Lines.txt (this effectively over-writes the original Lines.txt).

     

    For my coup de grâce I delete Lines2.txt leaving my desktop as it was before I ran the macro. But with a new and improved Lines.txt

     

    Here's the code:

    ASCII File Begin Process: "C:\Documents and Settings\z051940\Desktop\Lines.txt" (Tab Delimited Text (.txt))
     Variable Set String %ModifiedProcess% to "%LineProcess[1]% %LineProcess[1]%"
     Variable Modify String: Append %ModifiedProcess% to text file, "C:\Documents and Settings\z051940\Desktop\Lines2.txt"
    ASCII File End Process
    Copy File/Files: "C:\Documents and Settings\z051940\Desktop\Lines2.txt" to "C:\Documents and Settings\z051940\Desktop\Lines.txt"
    Delete File/Files: "C:\Documents and Settings\z051940\Desktop\Lines2.txt"

    <ASCII FILE BEGIN PROCESS Filename="C:\\Documents and Settings\\z051940\\Desktop\\Lines.txt" Format="Tab" Start_Record="1" Process_All="TRUE" Records="1" Variable="%LineProcess%" Start_Index="1"/>
    <VARIABLE SET STRING Option="\x00" Destination="%ModifiedProcess%" Value="%LineProcess[1]% %LineProcess[1]%"/>
    <VARIABLE MODIFY STRING Option="\x12" Destination="%ModifiedProcess%" Filename="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" CRLF="TRUE"/>
    <ASCII FILE END PROCESS/>
    <COPY FILE/FILES Source="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" Dest="C:\\Documents and Settings\\z051940\\Desktop\\Lines.txt" Progress="FALSE" Recurse="FALSE"/>
    <DELETE FILE/FILES Path="C:\\Documents and Settings\\z051940\\Desktop\\Lines2.txt" Progress="FALSE" Recurse="FALSE" Permanent="FALSE"/>

  22. <br /><br /><br />

     

    With apologies for straying OT, I'm curious to know what sort of things you (and others) do in your start-up macro please?

     

    --

    Terry, East Grinstead, UK

    I have about 10 different apps, utilites, inter- and intranet sites that all need to be opened and logged into; windows that need to be resized and repositioned, etc.

     

    So I have a "Start" short-key that starts the monotonous process. While it's running I can eat my breakfast, go through hard-copy files, run to the restroom, get a drink, whatever I need to do.

×
×
  • Create New...