Jump to content

Since "Goto" is "Evil"


texan
 Share

Recommended Posts

Why not simply:

Make("GOTO") = Evil

In Memoriam: Goto, Assign, Eval, Call()

1999. - 2003.

:)

Lolz.

Other languages use these things, perhaps more discreetly, bot nonetheless lets see some examples.

Actionscript:

for (i = 1;i<= 10;i++){

"theVar" + i = "variable #: " + i

}

trace(theVar8); //Should print "variable #: 8"

PHP:

$a = "c"

$b = "a"

echo $$b //Will output "c"

Link to comment
Share on other sites

  • 1 month later...

Here's my GOTO dilemma. When scripting installation screens I have the following windows in order:

Run ("source\setup.exe")

1- WinWaitActive ( "xyz", "Welcome" )

Sleep(1000)

Send ( "!n" );next

2- WinWaitActive ( "xyz", "License Agreement" )

Sleep(1000)

Send ( "!a" );i accept

Send ( "!n" ); next

3- WinWaitActive ( "xyz", "Customer Information" )

Sleep(1000)

Send ("{TAB 2}")

Send ( "xyz" );sn

Sleep(1000)

Send ( "!n" );next

Everything works great. However, I noticed that when the package gets ran a second time the windows change order. Window 2 (License Agreement) gets skipped. Now the script hangs. How can I write this so that if the condition of the &Modify window exists the script will skip down to window 3 and continue? Being a non-programmer type I dont understand how the function Call might work in my scenario.

Thanks,

Link to comment
Share on other sites

Here's my GOTO dilemma. When scripting installation screens I have the following windows in order:

Run ("source\setup.exe")

1- WinWaitActive ( "xyz", "Welcome" )

Sleep(1000)

Send ( "!n" );next

2- WinWaitActive ( "xyz", "License Agreement" )

Sleep(1000)

Send ( "!a" );i accept

Send ( "!n" ); next

3- WinWaitActive ( "xyz", "Customer Information" )

Sleep(1000)

Send ("{TAB 2}")

Send ( "xyz" );sn

Sleep(1000)

Send ( "!n" );next

Everything works great. However, I noticed that when the package gets ran a second time the windows change order. Window 2 (License Agreement) gets skipped. Now the script hangs. How can I write this so that if the condition of the &Modify window exists the script will skip down to window 3 and continue? Being a non-programmer type I dont understand how the function Call might work in my scenario.

Thanks,

Set the timeout Parameter on the affected Windows.

WinWaitActive ( "xyz", "License Agreement", 3 )

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

  • Developers

Something like this should work fine... just place the ExitLoop in the correct last window :

While 1
    Select
        Case WinExists("xyz", "Welcome")
            Sleep(1000)
            Send("!n");next

        Case WinExists("xyz", "License Agreement")
            Sleep(1000)
            Send("!a");i accept
            Send("!n"); next

        Case WinExists("xyz", "Customer Information")
            Sleep(1000)
            Send("{TAB 2}")
            Send("xyz");sn
            Sleep(1000)
            Send("!n");next
            ExitLoop
    EndSelect
    Sleep(20)
WEnd

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Set the timeout Parameter on the affected Windows.

WinWaitActive ( "xyz", "License Agreement", 3 )

Bad idea, because after the timeout occurs the various Send() etc. after it will be executed, what window will those key strokes go to? You can make that work by using the return value from WinWaitActive():

If WinWaitActive("xyz", "License Agreement", 3) Then ; Wait 3s, then move on
     Sleep(1000)
     Send ( "!a" );i accept
     Send ( "!n" ); next
EndIf

Or just go with what Jos posted.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Bad idea, because after the timeout occurs the various Send() etc. after it will be executed, what window will those key strokes go to? You can make that work by using the return value from WinWaitActive():

If WinWaitActive("xyz", "License Agreement", 3) Then ; Wait 3s, then move on
     Sleep(1000)
     Send ( "!a" );i accept
     Send ( "!n" ); next
EndIf

Or just go with what Jos posted.

:D

Or if we knew what installer it was then just go with a quiet install. :P

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

@PsaltyDS

Since I notice you've just posted in this thread and I read an earlier post you made, why do you rate Eval and Assign as evil? I can understand Goto (wash my mouth with soap and water), but there are times when I have seen no other way than to use Eval and even Assign.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

@PsaltyDS

Since I notice you've just posted in this thread and I read an earlier post you made, why do you rate Eval and Assign as evil? I can understand Goto (wash my mouth with soap and water), but there are times when I have seen no other way than to use Eval and even Assign.

It's gotten to be a kind of running gag now. It was only a petty personal prejudice before that. I came to AutoIt from NT Shell scripting ("Windows NT Shell Scripting" by Tim Hill was my bible). The substitute there for not having an "array" was variable substitution in a variable name:

REM 2D array of user data n_1 = name, n_2 = dept.
set USER_%x_1 = Bob
set USER_%x_2 = Accounting

Once I got into AutoIt and learned arrays (remember I didn't come here knowing any C, C++, PhP, Perl, Java, etc., only a little unix sh and Windows Shell), every time I saw a question about assign/eval, it was being used only because the person asking hadn't learned arrays yet. As an attempt at humor as a literary device in some replies, I started railing about the "evils" of Assign/Eval, and how it was supposedly only laziness that kept them from using arrays. Assign and Eval did seem to fit in as hold-hovers with "GOTO :LABEL" from the scary past. Encouraging other noobs like myself to learn arrays before resorting to them was the only real message.

I still think arrays fit the bill better in 90% of the cases (on this forum anyway) where Assign/Eval get asked about, but I have also had smarter people than me show examples of sticky logic flow problems that seem to require them. Even encountering such a problem implies more experience and coding knowledge that the intended audience for...

THE PLAIN SIMPLE FACT THAT ASSIGN and EVAL ARE PURE EVIL!!!

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

@PsaltyDS

Just keep up the good work, while maybe not actually "PURE EVIL" they are definitly prone to being over-used. I've successfully used both to solve a sticky problem but I always do that with some reservation.

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

It's gotten to be a kind of running gag now. It was only a petty personal prejudice before that. I came to AutoIt from NT Shell scripting ("Windows NT Shell Scripting" by Tim Hill was my bible). The substitute there for not having an "array" was variable substitution in a variable name:

REM 2D array of user data n_1 = name, n_2 = dept.
set USER_%x_1 = Bob
set USER_%x_2 = Accounting

Once I got into AutoIt and learned arrays (remember I didn't come here knowing any C, C++, PhP, Perl, Java, etc., only a little unix sh and Windows Shell), every time I saw a question about assign/eval, it was being used only because the person asking hadn't learned arrays yet. As an attempt at humor as a literary device in some replies, I started railing about the "evils" of Assign/Eval, and how it was supposedly only laziness that kept them from using arrays. Assign and Eval did seem to fit in as hold-hovers with "GOTO :LABEL" from the scary past. Encouraging other noobs like myself to learn arrays before resorting to them was the only real message.

I still think arrays fit the bill better in 90% of the cases (on this forum anyway) where Assign/Eval get asked about, but I have also had smarter people than me show examples of sticky logic flow problems that seem to require them. Even encountering such a problem implies more experience and coding knowledge that the intended audience for...

THE PLAIN SIMPLE FACT THAT ASSIGN and EVAL ARE PURE EVIL!!!

:D

Oh no, you've got it all wrong. Eval and Assign are lovely!

In this post in Nutsters thread I showed (to a totally uninterested audience) that my earlier suggestion of using Eval and Assign was at least 20 times faster than Nutster's hash table method. See here.

Also, supposing you have a script where you want to be able to examine the current value of some variable. You input "$LineCount". How would you display the current value without using Eval?

If you wanted to avoid having a script failing because a Const declaration had already been included in some #include file which you don't control, how else can you reliably do it other than

If not IsDeclared("var1") then Assign("var1",0x4,2) ?

Assign and Eval, not a sign of evil!

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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...