jhbell Posted July 16, 2004 Share Posted July 16, 2004 Change in IF.. Then Statement Syntax ??I think this is more a develoment issue than a bug:Using released version of V3 the following works fine:If $var1 = value then if $var2 = value then $var3 = valueIt is also valid Syntax per : If <expression> Then statementIn beta version installed today I get:----------------------------------------------------------------If $var1 = value then if $var2 = value then $var3 = valueIf $var1 = value then ^ ERRORError: This keyword cannot be used after a "Then" keyword.----------------------------------------------------------------I appreciate that better code would have used "and" but that isnot the point... I think exceptions like this make a language hard to learn/remember/use and document. eg:If <expression> Then statement EXCEPT that statement cannot be ..... Kinda like "i after e except when followed by or preceeded by..." I will now go and correct my poor V3 code but beware the wrathof dumb and dirty coders when you release the beta! PS: To verify this I switched back and forth between old and new versions by renaming the new and old versions of autoitV3.exe in Program files. Surely thereis a better way af compatibility testing... can SciTe be set up with one button fornew and one for old? Appreciate any input you guys have on a better way. Link to comment Share on other sites More sharing options...
pekster Posted July 16, 2004 Share Posted July 16, 2004 Just use this instead: If $var = 1 Then If $other_var = 1 Then Do_My_Func() EndIf [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
jhbell Posted July 16, 2004 Author Share Posted July 16, 2004 Ah yes! So the documentation should read: #csIf statement syntax can be confusing:Remember that in the form: If <expression> Then statementthat the statement may not be another if statement.however in the form:If <expression> ThenstatementsEndIfthat the statements may be other if statementsunless of course they are of the form If <expression> Then statementin which case statement may not be another if statement!#ce Its all clear to me now. Time for bed! Link to comment Share on other sites More sharing options...
pekster Posted July 16, 2004 Share Posted July 16, 2004 It is slightly ackward, but you should never need to do this, because if you have two If statements that would be executed right after one another, you can combine them with AND or OR. This is true because the compiler is smart enough to stop testing the conditional statement if it knows it's false from the part it's already calculated. For example, let $a = 0 and consider the following line of code: If $a AND MsgBox(4, "PICK", "Pick an option please") = 7 Then Exit In that line of code, you will never see the Message Box, even though it is part of the conditional statement. That is because $a was 0, and the program exited before it displayed the message box since there was no need to get that result. However, if $a was 1 in the above example, then you would see the message box. My whole point is that there should never be a need to use that syntax you posted above that gave you an error. If you want to use it anyway, you'll have to use the form I posted in my first reply. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
Administrators Jon Posted July 16, 2004 Administrators Share Posted July 16, 2004 The "If ... Then ... If" thing should never have been allowed and has been removed as a bug fix in the beta. Allowing it makes checking for block structures in the code much more messy (i.e. the internal code that checks for missing EndIfs and determining whether an If statement is a single line type or a block type) Deployment Blog: https://www.autoitconsulting.com/site/blog/ SCCM SDK Programming: https://www.autoitconsulting.com/site/sccm-sdk/ Link to comment Share on other sites More sharing options...
jhbell Posted July 18, 2004 Author Share Posted July 18, 2004 May I suggest then that you change the help file to the following:----CHANGES IN CAPS----If...Then --------------------------------------------------------------------------------Conditionally run a single statement.If <expression> Then NON-CONDITIONAL-STATEMENT Parametersexpression If the expression is true, the statement is executed. RemarksThis version of the If statement is used to execute a single statement without the overhead of an EndIf.THE STATEMENT HOWEVER MUST BE NON-CONDITIONAL. IE:- IT MAY NOT BE AN IF OR WHILE STATEMENT.The expression can contain the boolean operators of AND, OR, and NOT as well as the logical operators <, <=, >, >=, =, ==, and <> grouped with parentheses as needed. Link to comment Share on other sites More sharing options...
CyberSlug Posted July 18, 2004 Share Posted July 18, 2004 The "If ... Then ... If" thing should never have been allowed and has been removed as a bug fix in the beta. Allowing it makes checking for block structures in the code much more messy (i.e. the internal code that checks for missing EndIfs and determining whether an If statement is a single line type or a block type)I agree with Jon. It's bad/messy syntax, but I discovered Visual Basic does allow statements like If 1=1 Then If 2=2 Then MsgBox(0,"","foo") Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig! Link to comment Share on other sites More sharing options...
pekster Posted July 18, 2004 Share Posted July 18, 2004 I agree with Jon. It's bad/messy syntax, but I discovered Visual Basic does allow statements like If 1=1 Then If 2=2 Then MsgBox(0,"","foo")Most languages do, but Jon did say it's a lot harder to code in terms of the C++ sources. I also don't see why this is even an issue. There should never be a need to chain If statements together like that. If you have some code that uses that method, you can split it up with proper use of AND or OR blocks (and parentheeses as required.)It might be nice to be able to chain them together, but it's really not that hard to use one of the 2 avaiable alternatives. [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes. Link to comment Share on other sites More sharing options...
jhbell Posted July 19, 2004 Author Share Posted July 19, 2004 My original issue was not so much wanting to do it this way, but rather messing up the language definition with these exception rules. If we accept that this one line IF is an exception to avoid Endif for convenience, then I'd go along with the non-conditional statement change above. I had thought that the interpreter could handle the second IF by simply treating it as an 'AND' but I couldn't figure out what it should do on If a=1 Then While B<5 Will someone update the Help File? 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