Else Without IF error

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
doco
Posts: 28
Joined: 05 Sep 2021, 13:36
Location: CN94vx
Contact:

Else Without IF error

Post by doco » 15 Sep 2021, 22:49

Code: Select all

Calculate:
;	set variables
	distance := 0
;	calculate distance between locations first
	Gui, Submit, NoHide
	if(Blong = 0 and Blat = 0 and Elong = 0 and Elat = 0)
		
		MsgBox 49,  Missing Data Points, There is insufficient Data to Continue
		
	else if(Button1 = 1)
		
		distance := % GetDistanceTwoPoints(Blong, Elong)
		ControlSetText, Edit5, % distance
		
	else if(Button2 = 1)
		
		MsgBox, 1, Message, GRID
	
	return

The last Else If throws an error "Else with no matching IF" which is obviously not true.

Suggestions?

TIA
doco


User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Else Without IF error

Post by flyingDman » 16 Sep 2021, 10:38

From the docs:
If an If owns more than one line, those lines must be enclosed in braces (to create a block). However, if only one line belongs to an If, the braces are optional.
In other words, you don't have to go to a 12 year old post to find the answer. It's in the docs...
14.3 & 1.3.7

Post Reply

Return to “Ask for Help (v1)”