SteveR Posted March 18, 2016 Report Share Posted March 18, 2016 I have a situation where I would like to check if a window title contains the string contained in one of the text variables. I have tried doing this with an if window running or if window on top specifying %T1% as the text, but it does not seem to work. Is this possible? Am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
acantor Posted March 19, 2016 Report Share Posted March 19, 2016 Maybe something like this? Variable Set String %T1% to "Macro"Variable Set String %T2% to topmost window title If Variable %T2% Contains "%T1%" Text Box Display: YESElse Text Box Display: NOEnd If Quote Link to comment Share on other sites More sharing options...
SteveR Posted March 19, 2016 Author Report Share Posted March 19, 2016 Sounds like a great solution, however I have not got it to work. I have the following code Set Variable String %T5% from Window Title If Variable %T5% contains variable %T1% Macro Run:xxxx End If I set a breakpoint and look at the variable window T1 = "P4H" T5 = "P4H.vnm - Gravo........ However the Macro Run command does not execute. What am I missing? Actual macro attached OpenSpec.mex Quote Link to comment Share on other sites More sharing options...
acantor Posted March 19, 2016 Report Share Posted March 19, 2016 It's not easy to debug remotely, but the first things I would check are: Is there a problem with the IF statement? Is the Macro Run statement doing anything? Consider displaying a message box after the IF statement to confirm it is being evaluated as expected. I seem to recall that the "contains" option is case sensitive. "Hello there" contains "Hello" but not "hello". Quote Link to comment Share on other sites More sharing options...
SteveR Posted March 19, 2016 Author Report Share Posted March 19, 2016 I have added a message box before the if statement showing both T1 and T5 variables and a message box between the if and end if so I can see what path is taken. The message box before clearly shows that the T1 string is identical (including case) to the first characters in T5 however the if T1 contained in T5 never comes up true. I also tried checking the ignore case box but that made no difference. Other than this test, the macro runs to completion without error. Quote Link to comment Share on other sites More sharing options...
rberq Posted March 19, 2016 Report Share Posted March 19, 2016 I have added a message box before the if statement showing both T1 and T5 variables ... The message box before clearly shows that the T1 string is identical (including case) to the first characters in T5 OK, this is a shot in the dark, but it is a situation that has caught me a couple times. Are you sure there are no trailing blanks in the T1 string? For example, if I code these commands: Variable Set String %T1% "abc " Text Box Display: ...%T1% the value of T1 is abc and three blanks, but the text box display only shows abc with no indication of the trailing blanks. In your message box, display something like this: ---%T1%--- and when it is displayed you will see ---abc --- so the trailing blanks (if any) are "visible". Another way is, in your debugging code, Variable Set Integer %N1% from Length of Variable %T1% and Include %N1% in the message box along with %T1%. Quote Link to comment Share on other sites More sharing options...
acantor Posted March 20, 2016 Report Share Posted March 20, 2016 I can see no fault in the logic of your script. My guess is that there is an error of some kind, but it's subtle. So try recreating the macro entirely from scratch, using a different name, different variable names, etc. Quote Link to comment Share on other sites More sharing options...
SteveR Posted March 20, 2016 Author Report Share Posted March 20, 2016 I want to thank everyone who helped me on this. The problem was indeed non printable characters in the variable. It contained a CR or CR LF or something to that effect. Once I understood this, I was able to use the trim operations to remove the offending characters and then everything worked exactly as it should. Quote Link to comment Share on other sites More sharing options...
rberq Posted March 20, 2016 Report Share Posted March 20, 2016 Feels great when you finally discover the problem, doesn't it? Thanks for the feedback. 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.