Jump to content

String variable in controlID parameter


Bl1
 Share

Recommended Posts

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

  • Moderators

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

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

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 & "]"

Link to comment
Share on other sites

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

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)

 

Link to comment
Share on other sites

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 by Nine
Link to comment
Share on other sites

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...