mismatch / convert to decimal

# Thread: mismatch / convert to decimal

1. Senior Member
Join Date
Dec 1969
Posts
305

## mismatch / convert to decimal

So I&#039;m working on a zip code radius calculation - datatypes for latitude and longitude in the database are decimal, with precision 18 and scale 15. When I run this function:<BR><BR>function GetDistance(Lat1, Long1, Lat2, Long2, Unit)<BR><BR> dim x<BR><BR> x = (sin(DegToRads(Lat1)) * sin(DegToRads(Lat2)) + cos(DegToRads(Lat1)) * cos(DegToRads(Lat2)) * cos(abs((DegToRads(Long2))-(DegToRads(Long1)))))<BR> &#039; Get Acos(x)<BR> x = atn((sqr(1-x^2))/x)<BR><BR> GetDistance = 1.852 * 60.0 * ((x/pi)*180)<BR><BR> select case ucase(Unit)<BR> case "M" <BR> GetDistance = GetDistance / 1.609344<BR> case "N"<BR> GetDistance = GetDistance / 1.852<BR> end select<BR><BR> end function<BR>...<BR><BR>I get a type mismatch on DegToRads in the big calculation line. Can anyone spot a problem or help me convert / make sure the types in the function are decimal.<BR><BR>Thanks

2. Senior Member
Join Date
Dec 1969
Posts
11,334

## RE: mismatch / convert to decimal

So what does the DegToRads function look like? What are you returning?

3. Senior Member
Join Date
Dec 1969
Posts
305

## RE: mismatch / convert to decimal

it should return the distance in miles "M" or the distance in kilometers "N" given the latitude and longitude of an inputted us zip code vs our companies static latitude and longitude.

4. Senior Member
Join Date
Dec 1969
Posts
11,334

## So show the code

to see what it&#039;s returning.<BR><BR>Also, did you try a response.write on that function output to see what it really is returning?

5. Senior Member
Join Date
Dec 1969
Posts
305

## RE: So show the code

I did this: <BR><BR>response.write (GetDistance(41.238352,-080.300747,40.922326,-72.637078,M))<BR><BR>but got nothing:<BR><BR>Microsoft VBScript runtime error &#039;800a000d&#039; <BR><BR>Type mismatch: &#039;DegToRads&#039; <BR><BR>/zip.asp, line 20 <BR>

6. Senior Member
Join Date
Dec 1969
Posts
11,334

## No

Show the DegToRads function. There must be something in that amuck. That&#039;s not a built in VBS function, is it?

7. Senior Member
Join Date
Dec 1969
Posts
305

## RE: No

oh sorry :<BR><BR>function DegToRads(Deg)<BR><BR> DegToRads = cdbl(Deg * pi / 180)<BR><BR> end function<BR><BR>by the way this is 4guys script:

8. Senior Member
Join Date
Dec 1969
Posts
305

## RE: No

http://www.4guysfromrolla.com/webtech/010500-1.shtml

9. Senior Member
Join Date
Dec 1969
Posts
11,334

## Did you define pi?

Pi isn&#039;t a built in constant in VBS like most other languages... is that defined?<BR><BR>Also do a Response.Write on THAT function, to make sure the value is what you want.

10. Senior Member
Join Date
Dec 1969
Posts
305

## RE: Did you define pi?

it was pi! - thank you!

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•