Hi All,
I am looking at some of my coding (which i must admit of very much cobbled together) and trying to work out if there is a better way to sanitize it all. Basically I have a large number of scripts that get triggered from one action (e.g. Pager Message Received). Some of these scripts are independent of others (e.g. Recording the message to a database) whilst others a linked, I will give you an example
Pager Message Recieved.
then triggers
RecordtoDB.vb ---> Records Message to Database
LocalAlerts.vb ---> Checks another database to see if the user should be emailed based on the call and their options (e.g. email on call type x in location Y)
Then it triggers another script, which determines if the call is of interest to me, if so it then triggers:
ParseMelways.vb --> Extracts the URL for a melways reference and saves an image to a device using Jon00's Image Capture Tool
ExtractMap.vb--> Takes the above URL, parses through the source and extracts a latitude and longitude, creates google map images, emails them to me and saves them as devices.
This is very messy, but it does function, what I am interested though is how to make it a bit easier for me. The latest thing I have going (thanks to those who helped) is another script which takes in an input (being latitude and longitude) and then compares this against an RSS feed to find the exact coordinates (i can get close, but not exact).
This last script is perfect for what i need to do, but is there any way I can incorporate this into one of my scripts as a function without actually having to put the function in the script (if that makes sense). My concern is that I have 100's of scripts and I would much rather not cross link them all or make them any 'fatter' than they need to be, where they are independent it is fine but in the last example where it takes an input, compares to an RSS feed then gives an output, i would love to have it as a function that I can make available to lots of my scripts, feed it in the input (being Lat Long, or whatever) and have it spit back out the result
e.g. in my script i might do:
hs.writelog("Address", GetClosestLatLng(Latitude,Longitude)) which then accesses another script somewhere else, and the function below to return the string Latitude,Longitude
Thanks!
I am looking at some of my coding (which i must admit of very much cobbled together) and trying to work out if there is a better way to sanitize it all. Basically I have a large number of scripts that get triggered from one action (e.g. Pager Message Received). Some of these scripts are independent of others (e.g. Recording the message to a database) whilst others a linked, I will give you an example
Pager Message Recieved.
then triggers
RecordtoDB.vb ---> Records Message to Database
LocalAlerts.vb ---> Checks another database to see if the user should be emailed based on the call and their options (e.g. email on call type x in location Y)
Then it triggers another script, which determines if the call is of interest to me, if so it then triggers:
ParseMelways.vb --> Extracts the URL for a melways reference and saves an image to a device using Jon00's Image Capture Tool
ExtractMap.vb--> Takes the above URL, parses through the source and extracts a latitude and longitude, creates google map images, emails them to me and saves them as devices.
This is very messy, but it does function, what I am interested though is how to make it a bit easier for me. The latest thing I have going (thanks to those who helped) is another script which takes in an input (being latitude and longitude) and then compares this against an RSS feed to find the exact coordinates (i can get close, but not exact).
This last script is perfect for what i need to do, but is there any way I can incorporate this into one of my scripts as a function without actually having to put the function in the script (if that makes sense). My concern is that I have 100's of scripts and I would much rather not cross link them all or make them any 'fatter' than they need to be, where they are independent it is fine but in the last example where it takes an input, compares to an RSS feed then gives an output, i would love to have it as a function that I can make available to lots of my scripts, feed it in the input (being Lat Long, or whatever) and have it spit back out the result
e.g. in my script i might do:
hs.writelog("Address", GetClosestLatLng(Latitude,Longitude)) which then accesses another script somewhere else, and the function below to return the string Latitude,Longitude
Thanks!
PHP Code:
Imports System.Xml
Imports System.Math
Public Function GetClosestLatLng(ByVal Parms As Object)
Dim Parm() as String
Parm = Parms.Split(",")
Dim Latitude As String = Parm(0)
Dim Longitude As String = Parm(1)
Dim Distance2Address As Integer
Dim LatLongString As String = ""
Dim XMLNews As New XmlDocument
Dim ns As XmlNameSpaceManager = New XmlNameSpaceManager(XMLNews.NameTable)
ns.AddNameSpace("georss", "http://www.georss.org/georss")
Dim XMLNewsNodeList As XmlNodeList
Dim XMLNewsNode As XmlNode
Dim DevStr As String = ""
Dim DescStr As String = ""
Dim DescStr1 As String
Dim SplitStr() As String
Dim URLString As String = "http://osom.cfa.vic.gov.au/public/osom/IN_COMING.rss"
XMLNews.Load(URLString)
XMLNewsNodeList = XMLNews.SelectNodes("/rss/channel/item", ns)
For Each XMLNewsNode In XMLNewsNodeList
Dim GeoRssColl As XmlNodeList = XMLNewsNode.SelectNodes("georss:collection", ns)
For Each XmlPoint As XmlNode In GeoRssColl
If XmlPoint.InnerText <> "" Then
DescStr = " - " & XmlPoint.InnerText
'hs.WriteLog("RSS", DescStr.Remove(0, 3))
DescStr1 = DescStr.Remove(0, 3)
SplitStr = DescStr1.Split(" ")
'hs.WriteLog("RSS - Latitude", SplitStr(0))
'hs.WriteLog("RSS - Longitude", SplitStr(1))
'hs.WriteLog("RSS - Distance", distance(Latitude, Longitude, SplitStr(0), SplitStr(1), "K"))
If Distance2Address = vbEmpty Then
Distance2Address = distance(Latitude, Longitude, SplitStr(0), SplitStr(1), "K")
LatLongString = DescStr1
Else
If distance(Latitude, Longitude, SplitStr(0), SplitStr(1), "K") < Distance2Address Then
Distance2Address = distance(Latitude, Longitude, SplitStr(0), SplitStr(1), "K")
LatLongString = DescStr1
End If
End If
Else
DescStr = ""
End If
Next
Next
If Distance2Address <> vbEmpty Then
hs.WriteLog("FIRECALL DISTANCE", "Closest call to this address is: " & LatLongString & " At a distance of: " & Distance2Address.ToString)
End If
End Function
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: :::
'::: This routine calculates the distance between two points (given the :::
'::: latitude/longitude of those points). It is being used to calculate :::
'::: the distance between two locations using GeoDataSource(TM) products :::
'::: :::
'::: Definitions: :::
'::: South latitudes are negative, east longitudes are positive :::
'::: :::
'::: Passed to function: :::
'::: lat1, lon1 = Latitude and Longitude of point 1 (in decimal degrees) :::
'::: lat2, lon2 = Latitude and Longitude of point 2 (in decimal degrees) :::
'::: unit = the unit you desire for results :::
'::: where: 'M' is statute miles :::
'::: 'K' is kilometers (default) :::
'::: 'N' is nautical miles :::
'::: :::
'::: Worldwide cities and other features databases with latitude longitude :::
'::: are available at http://www.geodatasource.com :::
'::: :::
'::: For enquiries, please contact sales@geodatasource.com :::
'::: :::
'::: Official Web site: http://www.geodatasource.com :::
'::: :::
'::: GeoDataSource.com (C) All Rights Reserved 2013 :::
'::: :::
':::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Const pi = 3.1415926535897931
Function distance(ByVal lat1, ByVal lon1, ByVal lat2, ByVal lon2, ByVal unit)
Dim theta, dist
theta = lon1 - lon2
dist = sin(deg2rad(lat1)) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * cos(deg2rad(theta))
'response.write("dist = " & dist & "<br>")
dist = acos(dist)
dist = rad2deg(dist)
'response.write("dist = " & dist & "<br>")
distance = dist * 60 * 1.1515
Select Case ucase(unit)
Case "K"
distance = distance * 1.609344
Case "N"
distance = distance * 0.8684
End Select
End Function
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This function get the arccos function using arctan function :::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Function acos(ByVal rad)
If Abs(rad) <> 1 Then
acos = pi / 2 - Atan(rad / Sqrt(1 - rad * rad))
ElseIf rad = -1 Then
acos = pi
End If
End Function
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This function converts decimal degrees to radians :::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Function deg2rad(ByVal Deg)
deg2rad = CDbl(Deg * pi / 180)
End Function
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
'::: This function converts radians to decimal degrees :::
'::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Function rad2deg(ByVal Rad)
rad2deg = CDbl(Rad * 180 / pi)
End Function
Comment