Jump to content
Sign in to follow this  
Newb

Short IF sentence in autoit?

Recommended Posts

Newb

Which is the shorthand for an If expression in autoit?

On a help file i found this

If true = 1 then MsgBox(1,"Is it true?","Yarp!")

but I would like to see something for an expression like

If 5+5=10 Then
ConsoleWrite("Jjj")
Else
ConsoleWrite("nnn")
EndIf

What about it?

If 5+5=10 Then ConsoleWrite("Jjj")

But what about else?

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites
BrewManNH

Not sure what your question is. The second If statement should work, but will always show the Jjj in the console because 5 + 5 will always equal 10, change the 10 to 11 to see the else condition.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Newb

The question is, how do i set the else condition in that shortand if statement?

In some languages there is a one line if statement like this

BooleanVariable=(condition=true)?"ok":"not true"

or something like that. How do I replicate it in autoit?

Edited by Newb

I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites
MvGulik

Answer: You can't, as there is no Else in the short version.

http://www.autoitscript.com/autoit3/docs/keywords/If.htm

"Conditionally run a single statement."


"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Share this post


Link to post
Share on other sites
Newb

Good to know. A pity, as most languages implement such thing, but whatever. Thanks to all.


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites
kaotkbliss

you could do

If 5+5=10 Then ConsoleWrite("Jjj")

If 5+5<>10 Then ConsoleWrite("nnn")

I think that's about as close as you will get

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites
Newb

At that point an else would be a better solution. Thanks anyway.


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

Share this post


Link to post
Share on other sites
lowray1975

The question is, how do i set the else condition in that shortand if statement?

In some languages there is a one line if statement like this

BooleanVariable=(condition=true)?"ok":"not true"

or something like that. How do I replicate it in autoit?

I believe this will be supported in the next release (it's in beta now).

Share this post


Link to post
Share on other sites
Malkey

The question is, how do i set the else condition in that shortand if statement?

In some languages there is a one line if statement like this

BooleanVariable=(condition=true)?"ok":"not true"

or something like that. How do I replicate it in autoit?

Look up the _Iif() function in AutoIt help file.

Share this post


Link to post
Share on other sites
Newb

Look up the _Iif() function in AutoIt help file.

That's exactly what I meant! Nice to know, thanks Malkley.

By the way I think I will stay on If... Then.... Else since my aim was to make the shortest code possible without implementing external libraries/UDF files.

I was doing a decimal to binary converting function (I don't know if there is one in Autoit, couldn't find anything but Binary into Help file, and by the way I wanted to write one on my own) and I was trying to do it as short as possible with basic instructions.

This is the shortest I achieved so far

Func DecToBin($decim)
 Local $temp
 While $decim>=1
  If Floor(Mod($decim,2))>0 Then
   $temp="1"&$temp
  Else
   $temp="0"&$temp
  EndIf
  $decim/=2
 WEnd
Return $temp
EndFunc

And I asked about the shorter If to cut that if in the while loop (I don't want to use _Iif, or external functions, but thanks for letting me know about it Malkey!)

Any way to do my function shorter which is not a predefined autoit converting function? (Like Int, String etc etc)


I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it.

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  

×