fRequEnCy Posted January 30, 2010 Share Posted January 30, 2010 Hello all. I have mixed results using ControlSetText. What happens is sometimes it doesn't always work. Perhaps a timing issue? Here is a simple example script: $var = "C:\testfile.txt" WinWait("Open", "") If Not WinActive("Open", "") Then WinActivate("Open", "") WinWaitActive("Open", "") Sleep(500) ControlSetText("Open", "", "Edit1", $var, 1) ControlSend("Open", "", "Edit1", "{ENTER}") This is an open dialog. What I want is to pass the file name to the control and then press enter so it will load that file. I get mixed results though. I didn't always use a sleep function but stated to and seems it works fine but worry about it not working on other systems as the timing may just work well for my system. Any suggestions on a better way to tackle this? Link to comment Share on other sites More sharing options...
fRequEnCy Posted January 30, 2010 Author Share Posted January 30, 2010 Where does the open dialog come from? If you are trying to open "C:\Test.txt", then these are probably the best two ways to do it.ShellExecute("C:\Test.txt", "", "", "open") will open the file with it's default program.Run("notepad.exe " & "C:\Test.txt") will open the file with notepad.The Open Dialog is from various programs which is why I have mixed results. I'm not actually trying to open a txt file. Was just using as an example. So thanks for the reply but doesn't solve my problem in that case. Link to comment Share on other sites More sharing options...
fRequEnCy Posted February 24, 2010 Author Share Posted February 24, 2010 Bump. Sorry but never got a fix for this issue. It is definitely a timing issue as if I put a longer sleep then it will work. But I don't want to have to use a long sleep if I don't have to. So must I use a sleep in this case or is there a better way of coding this? I find that a sleep(500) works about 9 out of 10 times give or take. I tested many times as I'm writing a script that will be used publicly and don't want the timing to be off. Just wanting it to be perfect is all and not have the occurrence of it not sending the text to the control before I send {ENTER}. 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