calee Posted April 12 Report Share Posted April 12 I am trying to create a macro to activate upon window title to trigger based upon a ID number that is included in the title of a window. Unfortunately the ID number is towards the end of the window title and there seems to be a character limit on how far the window title is searched. When searching open window titles, it is cut off at the first digit of the ID number I am looking for. Is there any way to expand the character limit searched? Quote Link to comment Share on other sites More sharing options...
rberq Posted April 12 Report Share Posted April 12 Can you give an example of a window title that is not working, and show where the character limit falls within the title? Quote Link to comment Share on other sites More sharing options...
acantor Posted April 12 Report Share Posted April 12 I'm not aware of a maximum number of characters that Macro Express inspects when activating a script based on a window title. However, Windows limits the number of characters in a file name to 256. The title bar text for applications usually includes the file name, so if I had to guess what Macro Express is doing, I would say 256 is the maximum. You can display the full title of a window using this script: Variable Set String %Title% to topmost window title Text Box Display: Title is %Title% Quote Link to comment Share on other sites More sharing options...
rberq Posted April 12 Report Share Posted April 12 I know these aren't real lengths, but: If for example the window title is ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 and you are concerned with 56789 but Macro Express will only activate on the first 20 characters ABCDEFGHIJKLMNOPQRST then specify those 20 characters to activate it. Then as the first few lines of the macro say something like IF WINDOW ABCDEFGHIJKLMNOPQRST IS FOCUSED AND IF WINDOW 56789 IS FOCUSED ELSE MACRO RETURN END IF In other words, the macro will be activated on any window title containing ABCDEFGHIJKLMNOPQRST but the logic of the macro will immediately terminate it except in the cases where you want it to continue. I don't know if this will work for your windows, but it's easy to try with a test macro. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 12 Report Share Posted April 12 I created a WinForm app and set the windows title to "This is a super long window title and I can't imagine any developer making it longer than this This is a super long window title and I can't imagine any developer making it longer than this This is a super long window title and I can't imagine any developer making it longer than this 1234321" And made the activation for a window title containing text 1234321 and it works fine. I suspect you're jumping to conclusions that MEP is limiting it depth of characters searched. I believe your problem is something else. As rberg said it would be more helpful if you provided the actual text. One though I had is perhaps the title contains unicode characters. MEP processes unicode data as if it's ASCII and is difficult when the character is an extended one. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 12 Report Share Posted April 12 I found an answer that WinForms support Unicode. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 12 Report Share Posted April 12 Testing. Using the Set Variable from Window Title did not truncate the long window title. I used Repeat With Windows command and the long window title was not truncated as you described. Again... GIve us an sample of the title which is failing. I also recommend you make a small macro to grab the text of the top window and display it in a message box to see for yourself. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 12 Report Share Posted April 12 If anyone wants, I can create a simple WinForm program which will set the window title to whatever they specify in a text box for testing macros. Quote Link to comment Share on other sites More sharing options...
calee Posted April 12 Author Report Share Posted April 12 Ok after further testing, it appears to be related to the program I am using. Although I can see the full title on the window title bar in the program, Macro Express will only pick up the title up to the first digit Full title: ABC Processing Database ABCFrog User ZXCZX General ID 9876543 Macro picks up: ABC Processing Database ABCFrog User ZXCZX General ID 9 - \\ Remote It cuts off the ID which is what is the most important part of what I am trying to use the macro for. I am trying to have a big text box display as a caution upon a specific ID # that is pulled up. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 12 Report Share Posted April 12 That is strange. I'm sure it's not an MEP militation, but it's odd that it can't get the whole title. Like I said, it might be that the 8 is a unicode character or something like that. Are there any other controls on the window? Like a status bar at the bottom? THen you could do as rberg suggested and have it invisibly check that for the ID you want to have trigger. Quote Link to comment Share on other sites More sharing options...
acantor Posted April 12 Report Share Posted April 12 Perhaps the way forward is to set the activation to a partial match of the first part of the window title, e.g., "ABC Processing Database" The first thing the macro does is capture the window title as a string variable. (I've captured window titles using Macro Express that have up to 400 characters.) Then parse the string to extract the ID. Maybe something like this: Variable Set String %Title% to topmost window title Variable Set Integer %StartPositionOfID% to 20 Variable Set Integer %LengthOfID% to 7 Variable Modify String: Copy part of text in %Title% starting at %StartPositionOfID% and %LengthOfID% characters long to %ID% Text Box Display: ID = %ID% Quote Link to comment Share on other sites More sharing options...
rberq Posted April 13 Report Share Posted April 13 8 hours ago, calee said: ... I can see the full title on the window title bar in the program ... Can the macro highlight the entire screen (Ctrl-a) or part of it, copy it into the clipboard and then into a variable, and parse out the information from there? It looks a little sloppy to the user but I have been able to use the technique successfully a number of times. Generally I click in an unused but relevant part of the screen, type Ctrl-a to highlight, copy to clipboard, and click a second time to clear the highlighting. Quote Link to comment Share on other sites More sharing options...
calee Posted April 13 Author Report Share Posted April 13 So the only other place (other than the window title) the ID I am looking to search for pops up for a second is when it is scanned by a barcode reader. A barcode from a paper is scanned, it pops up momentarily on the screen before the order comes on the screen. Can a macro somehow capture what is scanned (it probably pops up on the screen for 1 second before the order pops up. Quote Link to comment Share on other sites More sharing options...
acantor Posted April 13 Report Share Posted April 13 If the barcode pops up for a second, it may be possible to capture it via a macro. If the barcode appears as text, Macro Express may be able to parse it. But if the barcode appears as an image, I don't think Macro Express will be much help. Extracting and analyzing text from the window title still seems like the best bet. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 13 Report Share Posted April 13 If it's a normal Winform window one can probably get all the text easily using the Windows Controls commands in MEP and launch a warning if the control text contains the code. You could also use the control as the activation. This would all happen in a few milliseconds and invisible to the user if one didn't pop up a message. I could also imagine one could save a graphic with the clipboard and do something with it. Quote Link to comment Share on other sites More sharing options...
rberq Posted April 13 Report Share Posted April 13 8 hours ago, calee said: Can a macro somehow capture what is scanned (it probably pops up on the screen for 1 second before the order pops up. Is the scanned data recorded in a file on the PC -- ideally, a txt file log? If so, a macro triggered by the order screen could read the last record of the file and check its contents. Does the scanned-data pop up screen have a title that could trigger a macro? Quote Link to comment Share on other sites More sharing options...
calee Posted April 14 Author Report Share Posted April 14 9 hours ago, acantor said: If the barcode pops up for a second, it may be possible to capture it via a macro. If the barcode appears as text, Macro Express may be able to parse it. But if the barcode appears as an image, I don't think Macro Express will be much help. Extracting and analyzing text from the window title still seems like the best bet. The barcode does appear as text and is highlighted for a second before it opens. I can definitely test extracting and analyzing text from the window title to see if this might work. Variable Set String %Title% to topmost window title Variable Set Integer %StartPositionOfID% to 20 Variable Set Integer %LengthOfID% to 7 Variable Modify String: Copy part of text in %Title% starting at %StartPositionOfID% and %LengthOfID% characters long to %ID% Text Box Display: ID = %ID% Where in this script would I place the actual ID I am looking for? Quote Link to comment Share on other sites More sharing options...
acantor Posted April 14 Report Share Posted April 14 Here's how it "works." Variable Set String %Title% to topmost window title Extract the title from the window and place it in string variable %Title%, e.g., "Hello Drink Tea Bye1234567 and Etcetera" Variable Set Integer %StartPositionOfID% to 20 Assume the ID always starts at the 20th character within the window title, e.g., "Hello Drink Tea Bye1234567 and Etcetera" Variable Set Integer %LengthOfID% to 7 Assume the ID is always seven characters long, e.g., "Hello Drink Tea Bye1234567 and Etcetera" Variable Modify String: Copy part of text in %Title% starting at %StartPositionOfID% and %LengthOfID% characters long to %ID% Copy seven characters starting at the 20th character and assign to string variable %ID% Text Box Display: ID = %ID% Display the ID! If the starting position of the ID and its length vary, you'd need other methods to zero-in on the ID. You gave this as an example of the title text: "ABC Processing Database ABCFrog User ZXCZX General ID 9876543" In this case, my starting point is that the ID begins immediately after the word "ID " (note the space after ID). If this is how the ID is always displayed, and the User name can be any length, you can calculate the start position this way: Variable Set Integer %StartPosition% to the position of "ID " in %Title% Variable Modify Integer: %StartPosition% = %StartPosition% + 4 Quote Link to comment Share on other sites More sharing options...
calee Posted April 16 Author Report Share Posted April 16 Thanks so much, I will give it a shot and report back. Quote Link to comment Share on other sites More sharing options...
calee Posted April 16 Author Report Share Posted April 16 On 4/12/2024 at 11:31 AM, calee said: Ok after further testing, it appears to be related to the program I am using. Although I can see the full title on the window title bar in the program, Macro Express will only pick up the title up to the first digit Full title: ABC Processing Database ABCFrog User ZXCZX General ID 9876543 Macro picks up: ABC Processing Database ABCFrog User ZXCZX General ID 9 - \\ Remote It cuts off the ID which is what is the most important part of what I am trying to use the macro for. I am trying to have a big text box display as a caution upon a specific ID # that is pulled up. So it looks like when I run the variable script, the text box title only displays "7 - \\ R" For some reason, it does not pick up the rest of the title at all. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 16 Report Share Posted April 16 Is it unicode? Quote Link to comment Share on other sites More sharing options...
acantor Posted April 16 Report Share Posted April 16 Paste your Macro Express script here so we can have a look. (Select the relevant lines of your script, and to copy them, choose "Copy Command Text" from the Script Editor's "Edit" menu.) P Quote Link to comment Share on other sites More sharing options...
calee Posted April 16 Author Report Share Posted April 16 Variable Set String %Title% to topmost window title Variable Set Integer %StartPositionOfID% to 62 Variable Set Integer %LengthOfId% to 7 Variable Modify String: Copy part of text in %Title% starting at %StartPositionOfID% and %LengthOfId% characters long to %ID% Text Box Display: %ID% Quote Link to comment Share on other sites More sharing options...
acantor Posted April 16 Report Share Posted April 16 Can you also provide two or three examples of typical window titles? Cory might be correct that this is a Unicode issue, but let's make sure this is not a coding issue. Quote Link to comment Share on other sites More sharing options...
Cory Posted April 16 Report Share Posted April 16 5 minutes ago, acantor said: Cory might be correct that this is a Unicode issue, but let's make sure this is not a coding issue. I doubt it as the break is happening in the middle of a string of numerals. But there are some. Like a zero with a slash through it. Also unicode extended characters just use two bytes where MEP decodes them one byte at a time. So one typically sees two garbage characters then it continues. Aside: I have successfully used MEP with Unicode by employing some replacements as a workaround. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.