Jump to content
Sign in to follow this  
jercfd

Possible If statement

Recommended Posts

jercfd

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

Share this post


Link to post
Share on other sites
Dinosaurr

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

Just an example of an if statement doing 2 things.

/:

Share this post


Link to post
Share on other sites
herewasplato

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

probably for the same reason that You cannot do this :-)
MsgBox(0, "", "") And MsgBox(0, "", "")
Is an EndIf gonna kill ya? Or do you just like the way the code looks without it? :-)

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

Share this post


Link to post
Share on other sites
herewasplato

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]

Share this post


Link to post
Share on other sites
jercfd

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

Share this post


Link to post
Share on other sites
herewasplato

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]

Share this post


Link to post
Share on other sites
trancexx

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

Share this post


Link to post
Share on other sites
monoceres

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!

Share this post


Link to post
Share on other sites
jercfd

Thanks for all the replies. I kind of prefer monoceres way of assigning variable values

Share this post


Link to post
Share on other sites
monoceres

Thanks for all the replies. I kind of prefer monoceres way of assigning variable values

Seriously? My way is clearly dumbest and is really only for showing off.


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

Share this post


Link to post
Share on other sites
trancexx

It's for mowing chicks.

Like... Hi baby! Take look at this. Ha? What do you think? ... you like it? Damn, you look good. What's your name?

anyways... sorry :mellow:


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
monoceres

It's for mowing chicks.

Like... Hi baby! Take look at this. Ha? What do you think? ... you like it? Damn, you look good. What's your name?

anyways... sorry :mellow:

Who doesn't use their AutoIt skillz when hunting :(


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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.