Jump to content

Short IF sentence in autoit?


Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

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