Jump to content
Macro Express Forums

Check if Window title contains Text Variable


SteveR

Recommended Posts

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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".

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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%.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...