Jump to content
Sign in to follow this  
devtester

Strange behavior with SetEnv & GetEnv and ControlClick

Recommended Posts

devtester

Greetings,

I am placing my control ID definitions in an external .vbs file. They are defined using the SetEnv global environmental function. However, after loading all my variables into memory, I can read the values in the calling code, but the values aren't affecting the ControlClick functionality. The project is using MS Calculator. Here's my code:

Calc_Obj.vbs

>>>>> MS Calculator Control IDs <<<<<

EnvSet("seven", 131)

EnvSet("plus ", 92)

EnvSet("three", 127)

EnvSet("equals", 112)

Calc_Code.au3

>>>>> Begin Calculator Code <<<<<

#include "C:\Calc_Obj.vbs"

; sample script to demonstrate using the contols within Window's Calculator application

run("calc.exe")

WinWait("Calculator")

; perform: 7+3=

ControlClick ( "Calculator", "", EnvGet("seven")) ; seven

ControlClick ( "Calculator", "", EnvGet("plus")) ; plus

ControlClick ( "Calculator", "", EnvGet("three")) ; three

ControlClick ( "Calculator", "", EnvGet("equals")) ; equals

---------------------------------

The above code doesn't run. I can do a message box on EnvGet("seven") within the Calc_Code.au3 file and it displayes 131. One interesting thing to note, I can have a variable assignment such as $var = EnvGet("seven")+0 and use ControlClick ( "Calculator", "", $var). This code will work! Very strange behavior.

Any suggestions appreciated.

Share this post


Link to post
Share on other sites
evilertoaster

What's the reason for using VB in this case?

Also sometimes the control ID's can change watch for that.

Finally, you may want to add soe debugging to see if the script does read the control ID's correctly and if doing so matches the action you get when you hardcode them.

Share this post


Link to post
Share on other sites
devtester

I am looking for a solution as to why this code doesn't work...not to redesign the script. With regard to debugging...I used msgbox and the control ID is being read in the au3 file. Much thanks for your consideration.

Share this post


Link to post
Share on other sites
evilertoaster

I am looking for a solution as to why this code doesn't work...not to redesign the script.

I said nothign of redesign...

Obviously somthing WILL have to be chaned as it isn't working atm though...

Can you verify, like i said above, that the control ID's are staying the same and match up with what you want them to be? And can you send these controlclick's ok if you hardcode the controlIDs in?

Another thing to try is coding the first part in autoit also if the situation allows and see if that helps any... does it require VB in this case?

Edited by evilertoaster

Share this post


Link to post
Share on other sites
Jos

I am looking for a solution as to why this code doesn't work...not to redesign the script. With regard to debugging...I used msgbox and the control ID is being read in the au3 file. Much thanks for your consideration.

Remarks

A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist.

the environment changes made in the VBS CMD session will only exist in the CMD program and no other program.

Edited by JdeB

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
evilertoaster

I had suspected such a problem between AU and VB, however he is SETTING the variables in VB, unless it had the same restriction on it as the AutoIt version it should work in thoery. Also he has already said he is able to read the variables in the end. However i am still wary of mixing the two seemingly unnecessarily...

Edit: saw your edit.... perhaps he was wrong about being able to read the variables in the end then...

Edited by evilertoaster

Share this post


Link to post
Share on other sites
Jos

I had suspected such a problem between AU and VB, however he is SETTING the variables in VB, unless it had the same restriction on it as the AutoIt version it should work in thoery. Also he has already said he is able to read the variables in the end. However i am still wary of mixing the two seemingly unnecessarily...

Edit: saw your edit.... perhaps he was wrong about being able to read the variables in the end then...

Here is a simple demo of what i stated:

Run(@ComSpec & " /k Set test=something")
Sleep(2000)
ConsoleWrite(EnvGet("test") & @LF)

The Env changes are not for other running programs... only for the shelled commandprompt.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
devtester

AutoIT sees my global assignments as strings in my script. You must cast the string variables using the int method. Works fine now. Interesting that no one caught this...

Share this post


Link to post
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
Sign in to follow this  

×