multiple if

Get help with using AutoHotkey and its commands and hotkeys
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

multiple if

03 Dec 2017, 19:26

Hello again,

If A is not number and If A is not = 0

How can i put this together?
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: multiple if

03 Dec 2017, 19:33

If A is not number should be enough. 0 is considered a number in AHK.
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: multiple if

03 Dec 2017, 20:02

Thanks for the reply but it does not work

Code: Select all

A := 0

If A is not number
	MsgBox
User avatar
tidbit
Posts: 1154
Joined: 29 Sep 2013, 17:15
Location: USA

Re: multiple if

03 Dec 2017, 20:12

if blah is/contains/in blah ... are special types of IF, thus they are on their own separate page. they cannot be used on the same line as a normal if (such as with && or ||)

just put another if above/below the one you got.

Code: Select all

A := 0

if (A!=0)
	If A is not number
		MsgBox
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
HIAC
Posts: 111
Joined: 11 Oct 2017, 17:59
Location: Republic of Serbia

Re: multiple if

03 Dec 2017, 20:27

Thanks but then I can't use Else...
User avatar
tidbit
Posts: 1154
Joined: 29 Sep 2013, 17:15
Location: USA

Re: multiple if

03 Dec 2017, 20:31

why not? also, be more upfront with your needs when asking. give as much details as anyone would need, we cannot read minds. how would I know that you needed a way to use 'else'? 20 questions isn't fun.

Code: Select all

A := 0

if (A!=0)
{
	If A is not number
	{ ; infact, {} are not even needed if you're just doing 1 line
		MsgBox
	}
	else
		blah
}
or

Code: Select all

if (A!=0)
{
	If A is not number
		MsgBox
}
else
	blah
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
A_AhkUser
Posts: 1076
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: multiple if

03 Dec 2017, 20:45

Hi HIAC,

Try this, it uses this shorcut for var is/is not a number:

Code: Select all

MsgBox % var+0 != ""

edit: remove trailing zero
Last edited by A_AhkUser on 03 Dec 2017, 21:05, edited 1 time in total.
User avatar
jeeswg
Posts: 6904
Joined: 19 Dec 2016, 01:58
Location: UK

Re: multiple if

03 Dec 2017, 20:56

The special ifs, between/contains/in/is, are lame, because you can't combine them with other conditions on the same line. So, it's best to create custom functions for them.

Code: Select all

q::
if IsNumber("a")
	MsgBox, % "y"
else
	MsgBox, % "n"

if IsNumber(1)
	MsgBox, % "y"
else
	MsgBox, % "n"
return

IsNumber(vText)
{
	if vText is number
		return 1
	else
		return 0
}
[EDIT:] A Between function.
If MousePos X and Y between X and Y, Do A - AutoHotkey Community
https://autohotkey.com/boards/viewtopic ... 11#p163711
Last edited by jeeswg on 03 Dec 2017, 21:05, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Osprey
Posts: 453
Joined: 18 Nov 2017, 05:50

Re: multiple if

03 Dec 2017, 20:57

HIAC wrote:Thanks for the reply but it does not work

Code: Select all

A := 0

If A is not number
	MsgBox
I don't understand. What are you expecting to happen, to see a message box? If "and A != 0" were added to the expression, like you asked for, it still wouldn't resolve to true and show a message box, since A is set to 0.

Return to “Ask For Help”

Who is online

Users browsing this forum: flyingDman, Google [Bot] and 255 guests