Jump to content

code works then stops working?


jben
 Share

Recommended Posts

Hi everyone. I've got this piece of code that i've finally got working.(sort of). But it seems like it works on and off. One minute it will work and the next minute it does nothing Any ideas why?. Code is below

shellexecute ("c:\winzip111.exe")

dim $ReturnValue

dim $ReturnedValue

$ReturnValue = ControlClick("WinZip® 11.1 Setup","", "&Setup","Button1")

If $ReturnedValue = 0 Then MsgBox(0, "", "Failure")

If $ReturnedValue = 1 Then MsgBox(0, "", "Success")

The above code clicks the setup button. It did work but now it just stopped working. I just get a "failure" message box

Edited by jben
Link to comment
Share on other sites

A couple of other things you can try.

Opt("WinTitleMatchMode", 2)

Then change the line

ControlClick("WinZip® 11.1 Setup","", "&Setup","Button1")

to

ControlClick("WinZip","", "&Setup")

Also try adding a WinWaitActive("WinZip","", 10) into your code in place of, or in addition to, Garys WinWait()

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The setup button might not be ready for a click the instant that it appears:

Dim $ReturnedValue
ShellExecute("c:\winzip111.exe")

Do
    Sleep(99)
Until ControlCommand("WinZip® 11.1 Setup", "", "&Setup", "Button1", "IsEnabled", "")

$ReturnedValue = ControlClick("WinZip® 11.1 Setup", "", "&Setup", "Button1")
If $ReturnedValue = 0 Then
    MsgBox(0, "", "Failure")
    Exit
EndIf

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Notice...

$ReturnedValue = ControlClick("WinZip® 11.1 Setup","", "&Setup","Button1")

If $ReturnedValue = 0 Then MsgBox(0, "", "Failure")

...in your original code is the reason the wrong MsgBox popped up...

Edit: my fault for using different variable names in my PM replies...

and you don't really want/need a MsgBox for when it does not fail...

and I like single line If statements :-)

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Notice...

$ReturnedValue = ControlClick("WinZip® 11.1 Setup","", "&Setup","Button1")

If $ReturnedValue = 0 Then MsgBox(0, "", "Failure")

...in your original code is the reason the wrong MsgBox popped up...

Edit: my fault for using different variable names in my PM replies...

and you don't really want/need a MsgBox for when it does not fail...

and I like single line If statements :-)

Nice catch!!

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Hey everyone,

Sorry for the delay in getting back. My heads all over the place at the moment with VB and AutoIT :-)

2 different languages confuses me beyond belief. Its really strange looking at this code now after i've spent a little while with VB haha.

Thanks alot I will try this out

oh and i'm just wondering. What is the purpose of $ReturnedValue

Is that some sort of binary, that tells the program if something is succesfull. Like if its not succesful then its 0, hence its failed.

Also is there any way I can initiate a failure. Tried renaming the winzip file but that didn't work.

I'm not overly worried if the file doesn't exist as the primary use of this will be in VB and I will proceed to error checking if stuff exists in VB (probably)

Also I was talking to a software guy at work who had a similar idea of creating a VB app that contains buttons which link to automated scripts. The only issue he had was the fact that if I create several automated scripts that run one after another and one fails then there would be an issue with the automation. (Reason for running one after another is to make life easy, so you can pop in the disk and walk away)

Edited by jben
Link to comment
Share on other sites

...oh and i'm just wondering. What is the purpose of $ReturnedValue

Is that some sort of binary, that tells the program if something is succesfull. Like if its not succesful then its 0, hence its failed...

Yes, and it can be named any variable name that you like.

...Also is there any way I can initiate a failure. Tried renaming the winzip file but that didn't work...

'cuz there was no error checking for the ShellExecute line of code:
$ReturnedValue = ShellExecute("c:\winzip111.exe")
If $ReturnedValue = 0 Then
    MsgBox(0, "", "Failure")
    Exit
EndIf

Do
    Sleep(99)
Until ControlCommand("WinZip® 11.1 Setup", "", "&Setup", "Button1", "IsEnabled", "")

$ReturnedValue = ControlClick("WinZip® 11.1 Setup", "", "&Setup", "Button1")
If $ReturnedValue = 0 Then
    MsgBox(0, "", "Failure")
    Exit
EndIf

...The only issue he had was the fact that if I create several automated scripts that run one after another and one fails then there would be an issue with the automation. (Reason for running one after another is to make life easy, so you can pop in the disk and walk away)

That is what error logs are for... or the Beep() function... or any number of ways to deal with that.

[size="1"][font="Arial"].[u].[/u][/font][/size]

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...