Bl1 Posted February 26, 2021 Share Posted February 26, 2021 Hi. New to the forum here. It seems string variables are not accepted in the controlID parameter in control functions, such as ControlClick. It works with a numeric variable, or literal text, but I want to use CLASSNN with a variable containing the instance. Has anybody done a workaround for this? As it is I'm using a conditional if-then statement including a ControlClick for each possible instance. It works, but it's not elegant, and it places a limit on the number of useful instances. I appreciate any suggestions, or if there is something in the scripting language that I'm unaware of, please enlighten me. I can provide my code if necessary. Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted February 26, 2021 Moderators Share Posted February 26, 2021 How about posting the code that is not working for you, so we can see what you're trying? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Bl1 Posted February 26, 2021 Author Share Posted February 26, 2021 OK, I thought that might help. I'm trying to automate re-arrangement of channels in n-track studio, which is a daw. So, this works because $directionID contains a numeric variable that refers to the control: ControlClick ("Track properties", "", $directionID ) The problem is here, because there are a whole group of controls (FlapsCheckbox) with the same ID number. This works: ControlClick ( "Mixer", "", "[CLASSNN:FlapsCheckbox57]") where 57 is the instance, but this does not work: Global $controlInstance = ($trackNum+2) * 3 Global $controlInstanceString = String($controlInstance) Global $classNNString = '"[CLASSNN:FlapsCheckbox' & $controlInstanceString & ']"' ControlClick ( "Mixer", "", $classNNString ) Return from this is exactly what it should be: MsgBox(0, "$classNNString", $classNNString) Link to comment Share on other sites More sharing options...
SEuBo Posted February 26, 2021 Share Posted February 26, 2021 8 minutes ago, Bl1 said: Global $classNNString = '"[CLASSNN:FlapsCheckbox' & $controlInstanceString & ']"' I am not sure if I am reading that correctly, but shouldn't be there less quotes? Global $classNNString = "[CLASSNN:FlapsCheckbox" & $controlInstanceString & "]" AutoIt Examples/UDF's:Generate Function at Runtime using IRunningObjectTable / AutoItObjectVery Simple Inter-Process Communication (using AutoItObject Pure AutoIt) Link to comment Share on other sites More sharing options...
Bl1 Posted February 27, 2021 Author Share Posted February 27, 2021 I don't know, when it's provided as a literal string it has to be in quotes. I might have tried it without quotes, I don't recall. I can try that when I'm on the other machine. But really there should be a definitive answer to this in the documentation. Either the controlID parameter supports string variables, or it doesn't. Link to comment Share on other sites More sharing options...
Bl1 Posted February 27, 2021 Author Share Posted February 27, 2021 By the way, you are correct that this is wrong: Global $classNNString = "[CLASSNN:FlapsCheckbox" & $controlInstanceString & "]" but that's not actual the result. Link to comment Share on other sites More sharing options...
SEuBo Posted February 27, 2021 Share Posted February 27, 2021 24 minutes ago, Bl1 said: I don't know, when it's provided as a literal string it has to be in quotes. I might have tried it without quotes, I don't recall. I can try that when I'm on the other machine. But really there should be a definitive answer to this in the documentation. Either the controlID parameter supports string variables, or it doesn't. It does, and it's mentioned in the Help File under "Controls". I would be delighted if you could check if the quotation is correct when you're on the other machine. Here's an working example with paint, so the error lies probably within the Window Title ("Mixer"), which could find the wrong window - or your $controlInstance value. $iPID = Run("mspaint") $hWnd = WinWait("[CLASS:MSPaintApp]") ControlSend($hWnd,"","","^e") $hPopup = WinWait("[CLASS:#32770]") ControlClick($hPopup, "", "[CLASS:Button; INSTANCE:6]") Sleep(1000) ControlClick($hPopup, "", "[CLASSNN:Button7]") Sleep(1000) ControlClick($hPopup, "", "[CLASSNN:Button"& 8 &"]") Sleep(1000) $ten = 10 ControlClick($hPopup, "", "[CLASSNN:Button"& $ten &"]") Sleep(1000) $eleven = '11' ControlClick($hPopup, "", "[CLASSNN:Button"& $eleven &"]") Sleep(1000) ControlClick($hPopup, "", "Button"& "6") Sleep(1000) ControlClick($hPopup, "", "Button"& '7') Sleep(1000) ProcessClose($iPID) AutoIt Examples/UDF's:Generate Function at Runtime using IRunningObjectTable / AutoItObjectVery Simple Inter-Process Communication (using AutoItObject Pure AutoIt) Link to comment Share on other sites More sharing options...
Nine Posted February 27, 2021 Share Posted February 27, 2021 (edited) BTW, you do not need to specify CLASSNN. When you provide a string in Control* functions, it is by default a CLASSNN. Also you do not need to convert a number to string when used with the string & operator, it will be done for you automatically. Run("Notepad") $hWnd = WinWait("[CLASS:Notepad]") $sCtrlID = "Edit1" ; by default it is CLASSNN ControlSend($hWnd, "", $sCtrlID, "Test 1" & @LF) $iInst = 1 ; integers are converted automatically if used in strings $sCtrlID = "Edit" & $iInst ControlSend($hWnd, "", $sCtrlID, "Test 2" & @LF) $iInst = 1 ; there is no harm though to specify CLASSNN $sCtrlID = "[CLASSNN:Edit" & $iInst & "]" ControlSend($hWnd, "", $sCtrlID, "Test 3" & @LF) $iInst = 1 ; if you like typing long statement $sCtrlID = "[CLASS:Edit; INSTANCE:" & $iInst & "]" ControlSend($hWnd, "", $sCtrlID, "Test 4" & @LF) ; easiest way is to use it directly in the Control* functions ControlSend($hWnd, "", "Edit" & $iInst, "Test 5" & @LF) Edited February 27, 2021 by Nine “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Bl1 Posted March 5, 2021 Author Share Posted March 5, 2021 Thanks for those suggestions. I'll try to see if any of that works for me. Link to comment Share on other sites More sharing options...
Bl1 Posted March 5, 2021 Author Share Posted March 5, 2021 Thanks for the help. I did in fact get to work with a variation on this: $iInst = 1 ; there is no harm though to specify CLASSNN $sCtrlID = "[CLASSNN:Edit" & $iInst & "]" ControlSend($hWnd, "", $sCtrlID, "Test 3" & @LF) And in fact I did originally have extraneous quote marks. It was a mental error, because I didn't realize that when the variable was interpreted, it would not need for a string to be in quotations. Other than that everything was working. It recognizes the correct window by name. I could not use just a simple instance number alone as the variable, because there are controls in the same window of different classes with the same instance number. So this will make the script more compact and should be more efficient. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now