Jump to content

Making a program more efficient


Recommended Posts

Hi guys!

Take a look at the program below:

While 1
    Sleep(5000)
    $v = PixelChecksum(160,30, 390,40)
    if $u <> $v then
        Send("{ESC}")
        MSgbox(0, "Terminated", "Program was terminated")
        $coor = PixelSearch( 670, 270, 800, 300, 0xFFEFD5, 10, 2 )
        If @error then 
            Run("builder.exe")
        Elseif Not @error Then
            Run("Fixer.exe")
        Else
            Exit
        EndIf
    Endif
WEnd

Now, the part that I would like to bring to your attention is the if statement that I have embedded into the code. If you take a look at it, I have an @ error, and a NOT @error and then and Else. The reason that I have done this is because if I have the code that looks like below (all above loops are the same, only the nested loop is changed):

If @error then 
            Run("builder.exe")
        Else
                                                Run("Fixer.exe")
        EndIf
    Endif
WEnd

Two things must be done to make this loop work. First of all, the second Endif statement must be removed, because for some reason, it seems to cause a problem with the while loop I was running. Secondly, autoit believes that this else statement is part of the while loop and NOT the embedded if statement, causing this program to actually run Fixer.exe

Any ideas on how to fix this, apart from using the code I've just used?

Thanks guys!

Link to comment
Share on other sites

Didn't quite get you, but here?

While 1
    Sleep(5000)
    $v = PixelChecksum(160,30, 390,40)
    if $u <> $v then
        Send("{ESC}")
        MSgbox(0, "Terminated", "Program was terminated")
        $coor = PixelSearch( 670, 270, 800, 300, 0xFFEFD5, 10, 2 )
        If @error then
            Run("builder.exe")
        Else
            Exit
        EndIf
    Endif
WEnd
Link to comment
Share on other sites

The second part of the code is the correct one.

Reason? Let's take a look at your first code:

If @error Then

Elseif Not @error

Else

@error and Not @error is ALL you can have - you can't have anything else because either you have @error <>0 or you have @error = 0

And you don't have anything else to fix, your code looks fine.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Hey guys!

Thanks a lot for your replies!

@generator: The code works perfectly thanks! But if you take a look at the second bit of code in my first post, I have the same loop as you do, but I got an error when I tried it for some strange reason...

@enaiman: yeah, I understood the fact about the @error while I was making up the code, and knew that it really didn't make sense. For some reason, I had typed in the code what Generator gave me before making this post, and got an error.

Oh well!

Thanks guys!

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