Jump to content

Possible If statement


jercfd
 Share

Recommended Posts

How come the if statement can't do two commands on one line?

Example: If $i = 1 Then $ElementLeft = 599 And $ElementTop = 30

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("Form1", 633, 447, 275, 231)
Global $ElementLeft, $ElementTop
For $i = 0 To 1
    If $i = 0 Then $ElementLeft = 55 And $ElementTop = 30
    If $i = 1 Then $ElementLeft = 599 And $ElementTop = 30
    GUICtrlCreateLabel("", $ElementLeft, $ElementTop, 30, 30, $SS_BLACKFRAME)
    GUICtrlCreateLabel($i + 1, $ElementLeft + 2, $ElementTop + 1, 20, 10)
    GUICtrlSetFont(-1, 7.5, 400, 0, "Arial")
    GUICtrlCreateLabel("Text", $ElementLeft + 1, $ElementTop + 14, 28, 15, $SS_CENTER)
    GUICtrlSetFont(-1, 8, 800, 0, "MS Sans Serif")
Next
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd
Link to comment
Share on other sites

If $i = 0 Then 
           $ElementLeft = 55 
           $ElementTop = 30
        EndIf

Just an example of an if statement doing 2 things.

/:

or this since $ElementTop = 30 is the same
For $i = 0 To 1
    $ElementTop = 30
    If $i = 0 Then $ElementLeft = 55
    If $i = 1 Then $ElementLeft = 599
    ;;;;
    ;;;;
    ;;;;
Next

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

Link to comment
Share on other sites

I was just asking why. I'm just trying to optimize my code to have as little lines as possible.

Yep - I understand that :-)

I don't know the technical reason.

Having fewer characters is a goal too:

$ElementTop = 30

If $i = 0 Then $ElementLeft = 55

If $i = 1 Then $ElementLeft = 599

or

If $i = 0 Then $ElementLeft = 55 And $ElementTop = 30

If $i = 1 Then $ElementLeft = 599 And $ElementTop = 30

Maybe a dev will drop by and enlighten us - in the meantime, enjoy AutoIt :-)

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

Link to comment
Share on other sites

probably for the same reason that You cannot do this :-)
MsgBox(0, "", "") And MsgBox(0, "", "")oÝ÷ ØIÝ!ø(v¤YrhêÝ£*.ë-)¶°k+ayÊzZ(Ì"¶.¶+ªê-x­Êjwh¶¬jëh×6$e = MsgBox(0, "", "") And MsgBox(0, "", "")

edit:

I recon you owe me a drink for that.

Edited by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

Since AutoIt uses Lazy Evaluation you can actually do custom ifs inside the regular if.

So:

If $i = 0 Then
      $ElementLeft = 55
       $ElementTop = 30
EndIf

Can be expressed as:

If $i=0 And (Assign("ElementLeft",55) And Assign("ElementTop",30)) And 0 Then Exit

I once did a whole GUI with this method, it's in my sig.

:mellow:

Edited by monoceres

Broken link? PM me and I'll send you the file!

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