![]() |
KnowBrainer Speech Recognition | ![]() |
Topic Title: Function to differentiate windows Topic Summary: Created On: 05/09/2020 08:15 AM Status: Post and Reply |
|
![]() |
![]() |
- Alan Cantor | - 05/09/2020 08:15 AM |
![]() |
![]() |
- R. Wilke | - 05/09/2020 08:57 AM |
![]() |
![]() |
- Alan Cantor | - 05/09/2020 10:05 AM |
![]() |
![]() |
- Alan Cantor | - 05/09/2020 10:23 AM |
![]() |
![]() |
- R. Wilke | - 05/09/2020 11:01 AM |
![]() |
![]() |
- Rapp | - 05/09/2020 10:39 AM |
![]() |
![]() |
- speechpro | - 05/11/2020 11:03 AM |
![]() |
![]() |
- Edgar | - 05/11/2020 01:23 PM |
![]() |
![]() |
- Ag | - 05/10/2020 08:15 PM |
![]() |
![]() |
- Edgar | - 05/11/2020 10:12 AM |
![]() |
![]() |
- monkey8 | - 05/11/2020 02:22 PM |
![]() |
![]() |
- Ag | - 05/11/2020 04:58 PM |
![]() |
![]() |
- Alan Cantor | - 05/11/2020 07:24 PM |
![]() |
|
I have revived an archived script for differentiating windows within an application. (I think Lindsay originally posted the code on this forum.)
In this example the script is application specific for Microsoft Outlook. It decides whether the window is the main Outlook user interface; an HTML message; or something else.
The script is not recognizing the first two cases.
I'm using Windows 10 and Outlook 2019. I wonder whether something has changed since I last needed this script in Windows 7 and Outlook 2010. |
|
|
|
![]() |
|
I am not sure about Outlook 2019, and I would assume that the title of the window is actually longer, but you can always do: -------------------------
|
|
|
|
![]() |
|
My memory is that this method worked with partial matches and exact matches, but I'll confirm.
|
|
|
|
![]() |
|
That's it! The script expects exact matches. Thank you!
There does not appear to be a built-in way to test whether a string contains another string, but partial matches can be detected this rather inelegant way: Sub Main () If InStr (ActiveWindowTitle$, "- Outlook") > 0 Then MsgBox "This is the main Outlook user interface" Exit Sub End If If InStr (ActiveWindowTitle$, "- Message") > 0 Then MsgBox "This is an email message" Exit Sub End If MsgBox "This is something else!" End Sub If someone knows a "pretty" way to do this, please share! |
|
|
|
![]() |
|
This is why we can't have pretty things!
A simple rewrite of the Select Case switch would look like that, in its generic form:
If ... Elseif ... Else ... End If
-------------------------
|
|
|
|
![]() |
|
I believe that the Case function works only with a complete match with the title. You might consider using and "If ... Then" statement using Instr() to find a partial match.
|
|
|
|
![]() |
|
If you prefer the structure of Select Case to multipart If, you can use it in combination with other functions to create classes based on the variable you're processing. Suppose you have a variable like LNAME. It might be upper, lower, mixed case, or even questionable data (not alpha). Say you want to handle A-H as group#1, I-P as group#2, Q-Z as group#3 and anything else as group#4 (possible error/investigate). - use various operators (like, >, <, "") to assign the input to GROUPNUM {"GROUP1", "GROUP2", "GROUP3", "GROUP4"} Then use Select Case on the group# - select case GROUPNUM ..."GROUP1" ..."GROUP2" etc.
|
|
|
|
![]() |
|
Don't forget you can also "stack" cases: Select Case UCASE (firstLetter) Case "A", "B", "C", "D", "E" folder = "G:\" Case "F", "G", "H", "I", "J" folder = "I:\" Case "K", "L", "M", "N", "O", "P" folder = "K:\" Case "Q", "R","S", "T", "U", "V", "W", "X", "Y", "Z" folder = "M:\" Case Else Exit All End Select ------------------------- -Edgar |
|
|
|
![]() |
|
I feel like an idiot asking this, but where do you place this function so that it can be called by more than one KnowBrainer command?
------------------------- DPG15.6 (also DPI 15.3) + KB, Sennheiser MB Pro 1 UC ML, BTD 800 dongle, Windows 10 Pro, MS Surface Book 3, Intel Core i7-1065G7 CPU @ 1.3/1.5GHz (4 cores, 8 logical, GPU=NVIDIA Quadro RTX 3000 with Max-Q Design. |
|
|
|
![]() |
|
You asked this question in another thread, I answered but I suspect that you did not see the answer. It is always a good idea to start a new topic when you want to ask an off-topic question. The short answer is, create a text file somewhere convenient then use this convention: '#Uses "C:\Program Files (x86)\KnowBrainer\KnowBrainer Professional 2017\WindowsAPI.txt" Look here for a longer answer: http://www.knowbrainer.com/forums/forum/messageview.cfm?catid=11&threadid=34338&enterthread=y ------------------------- -Edgar |
|
|
|
![]() |
|
Alan the script should just be checking the end of the window title which you have already worked out and a completed version as shown below with comments, not so sure I did original though:
'Declare three Windows functions
' Use functions to obtain a string with the title of the current window.
Function ActiveWindowTitle$()
Sub Main ()
Ag you can put the text file with the declared functions and subs anywhere you like as long as you specify in the script.
Lindsay
EDIT: you should really use the Mid$ function or InStr$ with index to work out the exact end of the string. Or maybe even use Right$ ------------------------- |
|
|
|
![]() |
|
Thanks, Edgar. Textual include. No shared state (which I also asked elsewhere, and you answered). ------------------------- DPG15.6 (also DPI 15.3) + KB, Sennheiser MB Pro 1 UC ML, BTD 800 dongle, Windows 10 Pro, MS Surface Book 3, Intel Core i7-1065G7 CPU @ 1.3/1.5GHz (4 cores, 8 logical, GPU=NVIDIA Quadro RTX 3000 with Max-Q Design. |
|
|
|
![]() |
|
you should really use the Mid$ function or InStr$ with index to work out the exact end of the string. Or maybe even use Right$ Or a combination. In recent years Microsoft has blurred lines between Outlook and Outlook.com. In the past, the title bars were quite distinct; but now there is enough overlap that I'm needing to rewrite old scripts that differentiate Outlook windows from Outlook.com windows. For example, the string "outlook.com" used to appear on the title bar of (you guessed it) outlook.com; now it's " - Outlook - ". Regular Outlook used to contain " - Microsoft Outlook" but now it's " - Outlook". Although it's not hard to determine which is which by analyzing title bar text, the similarities make it a bit trickier. |
|
|
FuseTalk Standard Edition v4.0 - © 1999-2021 FuseTalk™ Inc. All rights reserved.