Function GetRadius()
iRadius = CInt(txtMiles.Text)
Dim strZip As String = CStr(txtZip.Text)
Dim conn As OleDbConnection = New OleDbConnection(strCon)
Dim strSelect1 As String = ( _
"SELECT top 1 latitude, longitude, zip FROM tblZipCode " & _
"WHERE zip = @Zip")
Dim cmd1 As OleDbCommand = New OleDbCommand(strSelect1, conn)
Dim dtrZip As OleDbDataReader
cmd1.Parameters.AddWithValue("@Zip", strZip)
Try
conn.Open()
dtrZip = cmd1.ExecuteReader(CommandBehavior.SingleRow)
If dtrZip.Read Then
strLat1 = CStr(dtrZip("Latitude"))
strLon1 = CStr(dtrZip("Longitude"))
strZip = CStr(dtrZip("Zip"))
End If
dtrZip.Close()
Catch ex As Exception
MessageBox.Show(ex.StackTrace)
Finally
conn.Close()
End Try
Dim iStartLat As Double = CSng(strLat1)
Dim iStartLon As Double = CSng(strLon1)
Dim ZipId As String = CStr(strZip)
Dim LatRange As Double = iRadius / ((6076 / 5280) * 60)
Dim LonRange As Double = iRadius / (((System.Math.Cos(CDbl _
(iStartLat * 3.141592653589 / 180)) * 6076) / 5280) * 60)
Dim LowLatitude As Double = iStartLat - LatRange
Dim HighLatitude As Double = iStartLat + LatRange
Dim LowLongitude As Double = iStartLon - LonRange
Dim HighLongitude As Double = iStartLon + LonRange
Dim strSelect2 As String = _
"Select Zip, City, State, AreaCode, " & _
"Latitude, Longitude From tblZipCode " & _
"Where Latitude <=" & HighLatitude & _
"And Latitude >=" & LowLatitude & _
"And Longitude <=" & HighLongitude & _
"And Longitude >=" & LowLongitude
Dim Cmd2 As New OleDbDataAdapter(strSelect2, conn)
Dim ds As New DataSet
Cmd2.Fill(ds, "ZipCodes")
dgZipCodes.DataSource = ds.Tables("ZipCodes")
End Function