Unrecognized command: (.

540 views
Skip to first unread message

Frank Fica

unread,
Apr 18, 2013, 9:44:38 AM4/18/13
to mapi...@googlegroups.com
Does anyone know why am I getting Unrecognized command: (.

It is happening on:

length = Distance(x1,y1,x2,y2,"km")

Thomas Bacon

unread,
Apr 18, 2013, 9:47:26 AM4/18/13
to mapi...@googlegroups.com

Hard to say without knowing what x1, y1, x2, y2 and length are. One thing to check is that you have set MapBasic’s coordinate system prior to using the Distance function (use the ‘Set Coordsys…’ statement).

 

HTH,

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

--
--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
 
---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



Mouchel logo

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

Warren Vick

unread,
Apr 18, 2013, 9:49:43 AM4/18/13
to mapi...@googlegroups.com

Is "length" a reserved word in MB? I can't remember but it would seem to make sense. Try changing the name of that variable.

 

Regards,

Warren Vick

Europa Technologies Ltd.

http://www.europa.uk.com

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 2:45 PM
To: mapi...@googlegroups.com
Subject: [MI-L] Unrecognized command: (.

 

Does anyone know why am I getting Unrecognized command: (.

 

It is happening on:

 

length = Distance(x1,y1,x2,y2,"km")

 

--

Thomas Bacon

unread,
Apr 18, 2013, 9:54:21 AM4/18/13
to mapi...@googlegroups.com

Nope, I think length is ok to use. I just dumped this into the mapbasic window and it was happy with it:

 

Dim length as Integer

length = 20

print length

 

Pretty sure it should compile if it works in the MB window?

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

 

Warren Vick

unread,
Apr 18, 2013, 10:03:46 AM4/18/13
to mapi...@googlegroups.com

Hi Thomas,

 

Yes, it works in a MB program too so that's definitely not it. If there is something wrong with your x1/y1/x2/y2 variables, it's odd that it does generate a type mismatch error. What data type are they?

 

Another thing to check is the line before. Sometime a stray character on the end can generate an error associated with the wrong line.

 

Regards,

Warren

Adrian Gray

unread,
Apr 18, 2013, 10:11:20 AM4/18/13
to mapi...@googlegroups.com

If you are getting this during compilation it’s probably caused by something further up in the code or, one or more of your variables having not been declared. Also, you should avoid using variable names like “length” as this will be a reserved word in many languages (can’t remember if it is in MB) you should use something like fltLength or iLength to indicate the field type.

 

Hope this helps

 

Regards

 

Adrian Gray

www.viewshed.co.uk

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 14:45
To: mapi...@googlegroups.com
Subject: [MI-L] Unrecognized command: (.

 

Does anyone know why am I getting Unrecognized command: (.

 

It is happening on:

 

length = Distance(x1,y1,x2,y2,"km")

 

--

Frank Fica

unread,
Apr 18, 2013, 10:13:46 AM4/18/13
to mapi...@googlegroups.com
Thanks for all the replies, this is code I'm trying out. It is a little bit messy but I'm posting all the code for you to analyze. If I write a new program with:

Dim x1,y1,x2,y2,length As Dim

length = Distance(x1,y1,x2,y2,"km")

It compiles fine, even with the variables not assigned. But in the next code, it gives the error.

Include "MAPBASIC.DEF"


Dim x1, x2, y1, y2, dY As Float

Dim length, bearing, distance As Float

Dim new_pnt As Object

Dim new_pnt_x, new_pnt_y As Float

Dim earthR as Integer ' Radius of Earth


Define PI 3.141593


Declare Function Atn2(ByVal y As Float, ByVal x as Float) As Float

Declare Sub Main



Sub Main

earthR = 6371

distance = 0.001

Fetch Rec 10842 From AllRoads_segments

Dim recID as Integer

recID = AllRoads_segments.ROAD_ID

Select * From AllRoads_segments Where ROAD_ID = recID

Dim nPoly as Integer

nPoly = ObjectInfo(AllRoads_segments.obj, 21)

print "# Segments: " + nPoly


x1 = -89.7654 'ObjectNodeX(AllRoads_segments.obj, 1, 1) ' Longitude of first node on first segment

y1 = 14.3456 'ObjectNodeY(AllRoads_segments.obj, 1, 1) ' Latitude of first node on first segment

x2 = -89.8765 'ObjectNodeX(AllRoads_segments.obj, 1, 2) ' Longitude of second node on first segment

y2 = 14.8765 'ObjectNodeY(AllRoads_segments.obj, 1, 2)


length = ObjectLen(AllRoads_segments.obj,"km")

dY = Distance(x2,y2,x2,y1,"km")


'Calculate angle, with zero degrees being east-west.  Uses if/then for

'horizontal and vertical lines because of an apparent MapInfo bug that

'occasionally causes error when taking Asin(1).

If Dy/f_length = 0 Then 'Horizontal line

bearing = 0

Elseif Dy/f_length = 1 Then 'Vertical line

bearing = 90

Else

bearing = Asin(Dy/f_length)

End If


print "ROAD_ID: " + recID

print "Length in meters: " + length

print "Bearing: " + bearing * RAD_2_DEG + " degrees"


'new_pnt_x = Mod(lon1-Asin(Sin(bearing)*Sin(distance)/Cos(Lat1))+PI,2*PI)-PI

new_pnt_y = Asin(Sin(y1) * Cos(distance/earthR) + Cos(y1) * Sin(distance/earthR) * Cos(bearing))

print "Longitude: " + new_pnt_x

print "Latitude: " + new_pnt_y


Create Point Into Variable new_pnt(new_pnt_x, new_pnt_y)

Insert Into AllRoads_segments_first (obj) Values (new_pnt)


End Sub


Function Atn2(ByVal x As Float, ByVal y As Float) As Float


Dim a As Float

If (abs(x) > abs(y)) Then

a = atn (y/x)

Else 

a = atn (x/y)

If a < 0 Then

a = -PI/2 - a

Else

a = PI/2 -a

End If

End If

If x < 0 Then 

If y < 0 Then

a = a - PI

Else

a = a + PI

End If

Atn2 = a

End If

End Function

Thomas Bacon

unread,
Apr 18, 2013, 10:24:32 AM4/18/13
to mapi...@googlegroups.com

Frank,

 

I managed to get it to compile with SphericalDistance(). Not sure why it’s not working with the Distance function…

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

 

--

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
 
---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Frank Fica

unread,
Apr 18, 2013, 10:29:41 AM4/18/13
to mapi...@googlegroups.com
Thanks Tom, I will give it a try. Weird ah?


On Thursday, April 18, 2013 7:44:38 AM UTC-6, Frank Fica wrote:

Adrian Gray

unread,
Apr 18, 2013, 10:29:51 AM4/18/13
to mapi...@googlegroups.com

Frank,

 

Variables declared outside a sub/function scope should be declare using Global

 

Regards

 

Adrian

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:14
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.

 

Thanks for all the replies, this is code I'm trying out. It is a little bit messy but I'm posting all the code for you to analyze. If I write a new program with:

--

Frank Fica

unread,
Apr 18, 2013, 10:36:11 AM4/18/13
to mapi...@googlegroups.com
Thanks for the tip Adrian.


On Thursday, April 18, 2013 7:44:38 AM UTC-6, Frank Fica wrote:

Thomas Bacon

unread,
Apr 18, 2013, 10:36:49 AM4/18/13
to mapi...@googlegroups.com

Yep. You could also store the command into a string variable and run it with ‘Run Command…’ which would get you around the compile issue.

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:30
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.

 

Thanks Tom, I will give it a try. Weird ah?

--

--
You received this message because you are subscribed to the
Google Groups "MapInfo-L" group.To post a message to this group, send
email to mapi...@googlegroups.com
To unsubscribe from this group, go to:
http://groups.google.com/group/mapinfo-l/subscribe?hl=en
For more options, information and links to MapInfo resources (searching
archives, feature requests, to visit our Wiki, visit the Welcome page at
http://groups.google.com/group/mapinfo-l?hl=en
 
---
You received this message because you are subscribed to the Google Groups "MapInfo-L" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mapinfo-l+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Thomas Bacon

unread,
Apr 18, 2013, 10:38:21 AM4/18/13
to mapi...@googlegroups.com

Is there a specific reason for that Adrian (I’m not questioning it, just curious)? I’ve never declared my module-scope variables as Global, only those which I need across modules.

 

Tom Bacon

GIS Engineer, Mouchel

T 01444 472380 │ E thomas...@mouchel.com W www.mouchel.com

Our values: innovation │ excellence │ integrity │ responsibility

 

Adrian Gray

unread,
Apr 18, 2013, 10:44:14 AM4/18/13
to mapi...@googlegroups.com

What version of MB & MI Pro are you using?

 

Also did you notice you are asking for the distance as X2, Y2, X2, Y1 – did you mean X2, Y2, X1, Y1?

 

As good practice you should also set your MapBasic session Projection and Distance and Area Units.

 

Just a thought ------- I’m not aware of a requirement in MB which require Projection, Distance and Area units to have been set before legacy commands like Distance but perhaps it has become dependent and that’s why SphericalDistance works as it dictates the Projection, distance and area units.

 

From: mapi...@googlegroups.com [mailto:mapi...@googlegroups.com] On Behalf Of Frank Fica
Sent: 18 April 2013 15:30
To: mapi...@googlegroups.com
Subject: [MI-L] Re: Unrecognized command: (.

 

Thanks Tom, I will give it a try. Weird ah?

--

Uffe Kousgaard

unread,
Apr 18, 2013, 10:48:06 AM4/18/13
to mapi...@googlegroups.com
You have a variable and function with the same name, Distance. That's why it fails.

Most frequent mapbasic error, I think.

Would be nice with a better error message from the compiler.

Regards
Uffe


Frank Fica wrote:

Frank Fica

unread,
Apr 18, 2013, 11:05:45 AM4/18/13
to mapi...@googlegroups.com
Adrian,

I'm asking x2,y2,x2,y1 because I'm trying code from Bearing code to calculate line initial bearing.


On Thursday, April 18, 2013 7:44:38 AM UTC-6, Frank Fica wrote:

Frank Fica

unread,
Apr 18, 2013, 11:06:16 AM4/18/13
to mapi...@googlegroups.com
Thanks Uffe, good observation!


On Thursday, April 18, 2013 7:44:38 AM UTC-6, Frank Fica wrote:

Adrian Gray

unread,
Apr 18, 2013, 11:16:18 AM4/18/13
to mapi...@googlegroups.com

Tom,

 

No specific reason, I just feel it helps organise and structure the code. His code looked like it could do with some structuring.

 

Regards

 

Adrian

Image removed by sender. Mouchel logo

Mouchel Limited (Mouchel) is registered in England and Wales with registered number 01686040 at Export House, Cawsey Way, Woking, Surrey, UK, GU21 6QX.  The information in this e-mail is confidential and may be legally privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorised. Any views or opinions expressed in this e-mail may be solely those of the author and are not necessarily those of Mouchel. No contracts may be concluded on behalf of Mouchel by means of email communications. Mouchel reserves the right to monitor and intercept emails sent and received on our network. 

--

~WRD000.jpg

Adrian Gray

unread,
Apr 18, 2013, 11:17:33 AM4/18/13
to mapi...@googlegroups.com

Top spot Uffe!

Adrian Gray

unread,
Apr 18, 2013, 11:18:52 AM4/18/13
to mapi...@googlegroups.com

Ok, it’s just it wasn’t what was in the original email

--

Bill Thoen

unread,
Apr 18, 2013, 11:19:12 AM4/18/13
to mapi...@googlegroups.com
The problem is that it doesn't recognize the Distance() function because you dim'd a variable named 'distance' at the top of that procedure.

Regards,

Bill Thoen
GISnet

Bill Thoen

unread,
Apr 18, 2013, 11:25:36 AM4/18/13
to mapi...@googlegroups.com
They can be declared locally, and that is a VERY useful trick too. What you get when you declare variables outside of functions but inside a module is a private static variable invisible to any code outside the module, but visible to any code inside the module. Very handy for object-like code structures.


Regards,

Bill Thoen
GISnet

Peter Horsbøll Møller

unread,
Apr 21, 2013, 9:33:03 AM4/21/13
to mapi...@googlegroups.com
When I started programming MapBasic some many years ago, I quickly learned to appreciate "Hungarian Notation".

To me it has two purposes:
1. Makes it easy to identify the type of a variable
2. Prevents naming a variable as a function or table

The idea, for those of you that don't know what Hungarian Notation is, is to add a prefix to all your variables

There is a good description of Hungarian Notation on Wikipedia.

I am however not sure that I still use the same prefixes that I used to. I have for instance switched from "sz" to "s" on String variables.

Peter Horsbøll Møller
Pitney Bowes Software



Date: Thu, 18 Apr 2013 16:48:06 +0200
From: uffe.ko...@routeware.dk
To: mapi...@googlegroups.com
Subject: Re: [MI-L] Re: Unrecognized command: (.
Reply all
Reply to author
Forward
0 new messages