 # Type mismatch: text argument used when a number was expected

Seriously confused I can run a very short procedure just fine when starting with 1 record yet it fails when starting on a different record. Obviously the Type of the fields and variables do not change regardless of the starting record. Thus every field and variable has the same ‘Type’ during each running of the procedure.

What could then be causing this error?

(I’ve exported the data, and reimported it replacing all existing data in an attempt to rule out corruption.)

Just guessing. Maybe you have a ?( function that is returning one datatype when the condition is true, and another when it is false.

Nope. In the below code, Lat & Lng are Floats. (I’m sure you will recognize the formula, Thank you for that.) It fails on the Select sometimes depending on the starting record.

``````Local LLat, LLng, LDistance

GetText "Find other addresses within how many miles?",LDistance

LDistance = Val(LDistance)
LLat = Lat ; Original address Lat
LLng = Lng ; Original address Lng

Select ARCCOS(SIN(LLat*π/180)*SIN(Lat*π/180)+COS(LLat*π/180)*COS(Lat*π/180)*COS(Lng*π/180-LLng*π/180))*3959 ≤ LDistance``````

The problem also looks familiar. We had a similar problem with Jim Cook’s database. The problem occurs when it tries to calculate the distance to its own position. In a perfect world

``````SIN(LLat*π/180)*SIN(Lat*π/180)+COS(LLat*π/180)*COS(Lat*π/180)*COS(Lng*π/180-LLng*π/180)
``````

would equal 1 when LLat=Lat and LLng=Lng and arccos(1) is 0, but this is floating point arithmetic and you can expect a tiny amount of roundoff error. If the number is slightly smaller than 1, it calculates the distance as a few nanometers, instead of 0, and there is no problem, but if the number is slightly larger than 1, there is an error, because the arccosine function is only defined for numbers between -1 and 1.

We dealt with that by displacing the latitude of the reference point by a few feet, so that it’s never trying to find the distance from a point to itself. Try changing

``````LLat = Lat
``````

to

``````LLat = Lat + 0.000001
``````

or something similar.

OMG. David, you are amazing. How you got from ‘Type mismatch’ to an illegal equation, I don’t know. I do know that I want to thank you for your time.

When I saw it the first time, it was in a Panorama X database, and that wasn’t the error message. If I were looking at it for the first time, with that error message, I might still be trying to figure it out.

1 Like