?
Solved

Calculate distance between one input and one recordset point in Dreamweaver

Posted on 2003-03-25
4
Medium Priority
?
311 Views
Last Modified: 2008-03-17
I am trying to use Dreamweaver to display a simple search result.

I have a recordset that consists of a collection of sites, and each of them contains fields Lat for Latitude, and Long for Longitude.

I allow my user to enter a set of coordinates:  LatInput and LongInput, and a distance.  So they can search for sites that fall within the given distance.

I have added and modified the dreamweaver code, but I am not really sure about if I have the correct syntax, either way, I am getting a HTTP 500 error code.  

Please, any help is greatly appreciated.


  <% dim phi1
  phi1 = Request.Form("LatInput")  
  %>
<% dim lambda1
  lambda1 = Request.Form("LongInput")
  %>
<% dim distSeek
  distSeek = Request.Form("Dist")
  %>
<% dim distance
   distance = 0.0
   %>
<% function findDist (phi2, lambda2)
    phi1 = phi1 * 0.017453292519943
     lambda1 = lambda1 * 0.017453292519943
     phi2 = phi2 * 0.017453292519943
     lambda2 = lambda2 * 0.017453292519943
     distance = (6875.49354156988*Asin(sqrt((sin((phi1-phi2)/2))^2 + cos(phi1)*cos(phi2)*(sin((lambda1-lambda2)/2))^2))) * 1.15077944802354
     End Function
%>
<%     Function Asin(X)
    If (X < -1.0000) Or (X > 1.00000) Then
        Asin = Sgn(X) * 1.5707963267949
    ElseIf X > 0.999999999999999 Or X < -0.999999999999999 Then
        Asin = X * 1.5707963267949
    Else
        Asin = Atn(X / Sqr(-X * X + 1))
    End If
End Function
%>
<%
Dim sites__MMColParam
sites__MMColParam = findDist(sites.Field.Item("Lat"), sites.Field.Item("Long"))
%>
<%
Dim sites
Dim sites_numRows

Set sites = Server.CreateObject("ADODB.Recordset")
sites.ActiveConnection = MM_ROCKSITES_STRING
sites.Source = "SELECT *  FROM dbo.sites  WHERE " + Replace(distSeek, "'", "''") + " >= " + Replace(sites__MMColParam, "'", "''") + ""
sites.CursorType = 0
sites.CursorLocation = 2
sites.LockType = 1
sites.Open()

sites_numRows = 0
%>
0
Comment
Question by:ichavez
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
adathelad earned 500 total points
ID: 8203876
Hi,

> sites__MMColParam = findDist(sites.Field.Item("Lat"), sites.Field.Item("Long"))

This line of your code attempts to retrieve field values from the sites recordset, but this recordset is not defined or opened until further down. This would generate the error.

Cheers
0
 
LVL 13

Expert Comment

by:ispaleny
ID: 8203922
It seams you are trying to create OUTSIDE-INSIDE function.
Decide:
1. SQL function and one query
2. VB function  and a cursor loop

You cannot go by car and stay home :)
0
 

Author Comment

by:ichavez
ID: 8204206
Thanks much, maybe one of you can help me on this:

How do I call a user defined function in the where part of SQL statement?  Because I know the following didn't work:

"SELECT *  FROM dbo.sites  WHERE " + Replace(distSeek, "'", "''") + " >= " + Replace(findDist(Lat, Long), "'", "''") + ""
 
Thanks.
0
 
LVL 23

Expert Comment

by:adathelad
ID: 8204325
Try using "&" to concatenate strings ass opposed to "+":

"SELECT *  FROM dbo.sites  WHERE " + Replace(distSeek, "'", "''") + " >= " + Replace(findDist(Lat, Long), "'", "''") + ""

should be:

"SELECT *  FROM dbo.sites  WHERE " & Replace(distSeek, "'", "''") & " >= " & Replace(findDist(Lat, Long), "'", "''") & ""
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

616 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question