Jump to content
Macro Express Forums

paul

Members
  • Posts

    1,049
  • Joined

  • Last visited

Posts posted by paul

  1. I didn't show the code but I briefly mentioned it here:

    "Then in the individual macros under discussion add code at their start to read and test that value, continuing as appropriate."

     

    Here's the typical logic code I'm adding at the start of the individual macros:

     

    Read Registry Value "HKEY_CURRENT_USER\Terry Work Area\Text\Mem-MapSwitch" into %MemMapSwitch%

    If Variable %MemMapSwitch% Equals "ON" // Macro was opened via menu, not hotkey.

    Text Box Display: Initial Instructions

    End If

    // Main part of macro continues here.

    ...etc.

    Why not take advantage of MEP variables - there's no need for the registry at all?

    In your menu macro, add a boolean variable called, say, %bMenuCalled%, and set it to True.

    Now insert lines at the top of all your macros, as in:

      If Variable %bMenuCalled% Equals "True"
     CalledFromMenu Processing Logic
     Else
     NotCalledFromMenu Processing Logic
     End If

    Voila - Nothing else required.

  2. Edit: Hmm - not so simple after all! The menu activation etc all appears to work just fine. But I've hit an obstacle that may kill the approach dead in its tracks. A pop-up menu will 'run' for ever if you leave the option 'Wait for this macro to terminate before proceeding' checked (the default). I switched it off but have now discovered that my logic test after the Macro Run command is then ignored...

    What logic test? I didn't see any logic tests in any of the examples you showed!

  3. Edit: I've thought of a solution that I'll try shortly. I'll amend the main menu to include code that writes a switch value ON to the registry. Then in the individual macros under discussion add code at their start to read and test that value, continuing as appropriate. And then switch it OFF.

    What am I missing here? How are you going to add any code to your popup menu? I've not actually used popup menus, so I just created one, but was unable to find any code to modify or insert.

  4. No, where is it? I enquired about it in an email to Joe 12th March 2009, because the link to it http://www.pgmacros.com/members/book in his book didn't work. But apart from confirming that, he gave me no new link!

     

    I'm at http://pgmacros.invisionzone.com, where the only non-private link that looks relevant is 'Professional Grade Macros / Macros LLC'. But that doesn't appear to include a summary describing the library, its cost and ordering process.

    Although it converts to MEP without error, I'm not convinced that all the functionality works, and we've never spent the time and effort needed to ensure 100% compatibility.

    I'll take a look at the macro timing functions tomorrow and see if anything can be resuscitated.

  5. BTW, do I take it from your example that you've standardised on 'd' to prefix Date/Time variables and 'e' for Decimal? Or do you revert to 'd' for Decimal when there are no D/Ts around? I'm thinking of using 'd' and 'dt' respectively.

    I hardly use date/time variables, so, realizing I'd already used d for date/time, I simply used the next relevant letter for decimal, i.e. the 2nd letter instead of the first!

    Curiously, in VB I always use 3-letter mnemonics, e.g. int, dbl, str. But I seem to prefer single letters in ME, presumably because you always have to type the full name (whereas VB has all sorts of IDE tricks to avoid having to type stuff in).

  6. Here's my macro for converting the current time into seconds and milliseconds, i.e: SSSSS.sss. It ignores the date, as it's intended principally for calculating the duration of fairly short events, typically seconds or minutes, or at a maximum 24 hours (OK, 86399.000 seconds).

    Did you ever purchase the PGM Library? I wrote a set of functions, invoked by a hotkey, which would do this and more:

    - you can time the entire macro currently being edited

    - you can time an entire macro from Explorer

    - you can time any subset of selected contiguous lines within the currently edited macro

    Its precision is milliseconds.

  7. Convert Date/Time to Decimal: %StartTime% => %dStartTime%

    Convert Date/Time to Decimal: %EndTime% => %dEndTime%

    But why are you converting to decimal? Date/time variables support arithmetic. Displaying a date/time variable displays a readable result.

    And if you set dtv1 to now, dtv2 to now + 7 seconds, dtv3 to dtv2 - dtv1, and display all 3 variables, you get 30/12/1899 00:00:07 as the value of dtv3 (which confirms that MEP's starting date and time is midnight on 30/12/1899).

     

    MEP lacks quite a lot of date/time functions, e.g. DateDiff which would allow you to return the difference between 2 date/time variables in a time unit of your choice (days, hours, seconds, etc.).

     

    So, in order to make your function work, I'd do as follows:

    Use date/time variables to record your start and end times
    Subtract start time from end time into a 3rd date/time variable (dRes)
    Convert dRes to decimal (eRes)
    Convert result to seconds (eRes * 86400) into a decimal variable (eResConv)
    Truncate eResConv to integer (nRes), OR round eResConv to integer (more complex)
    nRes should not hold your answer (in seconds)

    I haven't thought about this too much, so there may be a more elegant solution.

  8. I have to disagree with Paul's comment about self-documenting programs. There goes a programmer v user! My experience has been, without exception, that reviewing and using custom applications is a nightmare if undocumented properly. Looking back at the work posted by Floyd in this forum, it is so easy to follow what is going on. Writing a program in a logical fashion may help, but code is only "obvious" to the author. The companies I've worked for, you would get no return business relying on code to explain everything. It would be moot since proper documentation including commenting would be in the contract. You pay for it but it's worth the money. Some poor employee down the road is going to have to figure out how the program works.

    Sorry, I should have made the context clear. I was talking about documenting a macro for myself only. If documenting for other people, then I agree 100% with JohnS.

  9. Convert Date/Time to Decimal: %StartTime% => %dStartTime%

    Convert Date/Time to Decimal: %EndTime% => %dEndTime%

     

    I don't understand the result:

     

    dEndTime = 40254.9264879861

    dStartTime = 40254.9264107639

     

    What units are these?

    The number of days and part days since some particular starting point - usually something like Midnight on 1st January 1900. This is a very standard way to represent time.

    Microsoft itself can't seem to agree on a universal starting point! Sometimes MS uses 1/1/1900, sometimes 1/1/1901, and sometimes 31/12/1899, depending on the product you're using.

  10. The Last Run Time column in ME Pro Explorer is a useful tool, such as when culling infrequently used macros. But it never gets updated if the macro is run via a Macro Run command. So many of my macros are misleadingly shown as Never having been run.

    Anyone able to confirm please?

    This has produced a bit of a can of worms!

    1) Right-clicking a macro and selecting Run Macro Now does update the Last Run Time, but only after I select the macro properties and change one, e.g. The macro is enabled

    2) Right-clicking a macro and selecting Run Macro Now does not update the Last Run Time if I then right-click the macro and select Disable Macro, followed by Enable Macro

    3) Running the macro with the Macro Run command in another macro does not update the Last Run Time if Wait for this macro to terminate before proceeding is ticked

    4) Running the macro with the Macro Run command in another macro does update the Last Run Time if Wait for this macro to terminate before proceeding is unticked (but only after changing a property as in 1 above), which is what I expected

  11. For registry names, there don't seem to be any naming standards that I've ever spotted. Given that you are not going to use these registry keys and values except from within your macros, I think the name immediately below the top level is the most important, so that you don't accidentally delete it and can easily remember what it signifies. Thus something like HKCU\TerryMEP\... is probably sufficient (and I'd exclude "Terry" if you're the only person doing this). Below that level, you might want to consider using "application" names (by which I mean a name describing which macro or set of macros), but probably only if you intend using many registry keys across a number of macros. Our PGM Library uses a section name "Professional Grade Macros", and subsections like Parameters, Pgm Functions, Swap, Variables, etc.

     

    I also like to use naming standards for my variables; %t...% for text variables, %n...% for integers, %b...% for boolean, etc., followed by as meaningful a name as possible (but shorter rather than longer) using camel case, as in %tFirstName%. I think this makes the macro a little clearer, and I'm all in favour of "self-documenting" code rather than copious comments littered throughtout the code.

  12. Re Desktop, definitely does not work for me in XP using "Create, Delete, Rename". I did not try terrypin's macro as that specified a particular file. As I mentioned, ME seems to respond to particular files (Move file etc) but not for monitoring new files. That could be a bug. I would treat it as "one of those ME things" and move on! Let's call it a Desktop Null issue for XP!!

    I tried this in XP (a VMWare sesssion running under W7), and it worked perfectly! So let's call it a Desktop Null issue for JohnS' XP!!

  13. i moved the activation from desktop to documents folder and it seems to trigger the macro fine. I took your original macro and just created the launch program c:\users\mts\documents\indeedjobs.xlsx

     

    If Not File Exists: "C:\Users\MTS\Documents\IndeedJobs.xlsx"

    Macro Stop

    Else

    Program Launch: "indeedjobs.xlsx" (Maximized)

    Parameters:

    End If

     

    the problem is that is continues to loop the macro when i close the excel file, when i close the indeedjobs.xlxs file it reopens again, which is correct: if file exists, program launch... any suggestions on how to correct this action?

    Your macro will run whenever your Documents folder changes - which is probably very often. Since your .xlsx file (presumably?) still exists, Excel will be reopened again and again and again....

    You need to find a way of informing the macro that you don't want it to run again on the current .xlsx file. You could use a different folder (one that changes infrequently, preferably under your direct control), OR you could change the .xlsx file's name once you've opened it once in Excel, OR you could store a value in the registry - but then you need to create a mechanism to erase the registry value when you do want the .xlsx file to be opened in Excel.

    I think you should change the file's name (or move it to a different folder) once you have opened it in Excel.

  14. I tried the Directory Modification last night. Only took a minute to write a macro. I found it worked fine when adding a file to a folder (using the Create, Rename, Delete). It does not work with the Desktop. Although ME can transfer files to and from the Desktop, it does not seem to include as a Folder as far as Directory Modification goes (Desktop is a special window rather than a folder). Perhaps some more expert comment is needed?

    Using Windows 7, where the Desktop folder is in C:\Users\username\Desktop, MEP's Directory activation feature works just fine.

    Mind you, this is a folder which usually has quite a lot of activity, so I'm not convinced it's a good target location for files!

  15. I have yet to find a good guide to setting file associations, which is highly relevant to the file opening issue. I'm sure most people do what I do - browse file types to see the variations. In Windows "File Types" you do not seem to be able to edit sub-types eg htm being a sub-type of html. In Directory Opus you can edit both separately.

     

    I have always had problems with new updates to Firefox changing the file association. I tried forever to correct htm/html in Windows "File Types". No matter what I entered I could not double-click on an htm file and get it to open. Most times, as soon as I unchecked DDE, it reset back again. Right-click and "Open With" worked OK. My second PC worked fine. It was only when I looked into types in Opus that it was clear that Firefox had set the Open action to "DDE Command" rather than "Run as an Application". Works a treat now, although I have to correct every Firefox update.

    I suggest you export the relevant Firefox keys in the registry to a .reg file which you can then simply double-click to add back into the registry when a new version arrives.

     

    As far as File Associations are concerned, you've got a real treat in store for you when you migrate to Windows 7. Many of the things you could do fairly easily in XP (e.g. all that horrid DDE stuff) appear to have disappeared from W7, though there are some 3rd party utilities that can help in this regard.

  16. again, when i double-click the file and i have excel already open then it just opens the file and NOT another instance of the program. So it is not excel itself that chooses to open another application when someone opens a file to be open. the issue is that ME doesnt open a file, it launches an application again... Excel is doing exactly what is being asked, "launch program: excel.exe with parameters c:\myfilename.xls", a ME should be able to handle a simple "open file" function and not use the "launch program" function.

    On my machine (Windows 7 Professional x64), if I have Excel open using File1.xls[m], and I double-click in Explorer on File2.xls[m], then a second instance of Excel is started. If I open File2.xls[m] from a command prompt, exactly the same behaviour occurs.

    In fact, if you do a Google search on

    excel open instance

    you will find many topics describing exactly the problem you experienced, where a second instance of Excel is always opened.

     

    So I don't understand how you manage to open a second .xls(m) file in the original instance of Excel.

     

    Just to clear this up completely, if I run a Macro that opens text files in my editor of choice (UtraEdit), then only a single instance of UltraEdit is run (as defined in my UltraEdit preferences).

  17. i have been using the Program Launch function to open an Excel File on an event. The problem is that the options are activate window (if available) or launch the program (with file location/name as a parameter). This does open the file BUT it causes another instance of Excel to open, so I have 2 instances of Excel running or however many if I continue to use this method... This is not only inefficient but it also evokes an error message for Excels personal.xls folder.

     

    What is the best way to open a file without needing to launch another instance of a program?

    You don't say which version of Excel you're using. Excel's behaviour appears to have changed in recent versions (e.g. Excel 2007), so that double-clicking on an Excel file causes a new instance of Excel to load, even when Excel is already open.

     

    Below is a description of a macro to launch and activate Excel if it's not already running, or to use Excel's Open File dialog to open the desired file if it is.

     

    Here's how to solve the problem, assuming that the Excel file you want to open is stored in %tExcelFile%:

    If Program "EXCEL.EXE" is running
     Window Activate: Microsoft Excel
     Text Type (Simulate Keystrokes): <CONTROL>o	 -- opens the Open File dialog
     Delay: 500 milliseconds
     Text Type (Simulate Keystrokes): %tExcelFile%<ENTER>
    Else
     Launch Program and Activate Window: Program "EXCEL.EXE", Parameters "%tExcelFile%", Window "Microsoft Excel"
    End If

  18. It presumably comes down to the difference between 'empty' and 'null'. But it's a distinction I still don't grasp. In particular, what is the command If Clipboard Equals "" testing for, null or empty?

    Sorry not to have responded earlier - I've been away.

    The above command is testing for a zero-length string, not a null string, nor an empty string (whatever that means).

    %tVar% = "this"

    The variable tvar contains a string of 4 characters.

    %tVar% = "thi"

    The variable tvar contains a string of 3 characters.

    %tVar% = "th"

    The variable tvar contains a string of 2 characters.

    %tVar% = "t"

    The variable tvar contains a string of 1 character.

    %tVar% = ""

    The variable tvar contains a string of 0 characters.

    Your If Clipboard command will return True to this, and only this, string (assuming this string is currently in the clipboard).

    As far as ME is concerned, forget about the word null, as it has no meaning. And the term Empty is not at all useful.

     

    String variables in ME always contain a string. The string can be from 0 to ? characters (I don't know what the upper limit is).

    Integer variables always contain a number. That number is 0 if the variable has not yet been used.

     

    Does that help?

     

    As far as Textpad is concerned, it looks as if it may append a linefeed (represented by Ascii13 followed by Ascii10) to a zero-length string on the clipboard. or perhaps it always appends CrLf to the last character in the clipboard. You should be able to establish that fairly easily.

  19. Strictly speaking the shortcuts I used are part of the Extended ASCII character set. I always use those shortcuts because I have a Post-It bookmark in my DOS manual - way quicker than finding my list of ANSI shortcuts. Sometimes the printed page is mightier than the mouse; no scrolling and absolutely no typing required! The ones you used are the Windows Character Set which is the ANSI preceded by 0, or something like that.

    What's wrong with \Windows\System32\Charmap(.exe)?

  20. Note to other forum readers: Per private email with Cory it was discovered that this user was not using the latest version. This will likely be resolved by upgrading.

    Yes, I must say I have not experienced the molasses problem with the latest release.

     

    Though I did have problems yesterday. I'm writing a macro which solicits the user for a folder, then types each fully qualified file name into a file common dialog box belonging to a 3rd-party program, followed by ENTER. During development I omitted to insert any delays, resulting in the fully qualified file name being entered without a drive letter, as in ":\dvds\VobOutput1.mpg". This caused the 3rd-party program to issue an error message, which my macro hadn't allowed for. The result was our old friend Molasses, but where I could only press Ctrl-Alt-Del and logoff to recover. I don't think it's worth reporting at this stage, since the addition of a 250ms delay solved the problem.

×
×
  • Create New...