Here is the code for the two functions. Distance is called first with two
grid cordinates.
example: strPOI = 4800030000 ---This is the Point of Impact
strPOO = 4800036000 --- This is the Point of Origin
Function Distance would return 6000 meters. It would also set a value to
diffEast = 0 and diffNorth = 6000
Function Direction is then called with 0 and 6000 and would return a value
of 6400 mils since the direction is due north.
I am working on using regular expression to improve how I trap incorrect
inputs from the user and when number are imported from other files. Since I
was working on improving the code, I just wanted to combine the two and
create a .dll file that I can use with other projects. I am not a
programer, may give it a run when I retire from the miliary. All I am
trying to do now is make all the data my radar sections here in Iraq
manageable.
The link to my website is below. It is full of pictures of some of the
stuff I do over here.
Thanks for all your help,
SFC, MSARNG
Target Acquisition Platoon Seargeant
Visit my webpage:
http://www.msala.net/archives.php
Public Function Distance(ByVal strPOO As String, ByVal strPOI As String,
ByRef diffEast As Double, ByRef diffNorth As Double) As Double
Dim dblEast2 As Double
Dim dblEast1 As Double
Dim dblNorth2 As Double
Dim dblNorth1 As Double
Dim bolValid As Boolean
bolValid = False
If Len(Trim(strPOO)) = 10 Then
If Len(Trim(strPOI)) = 10 Then
bolValid = True
End If
End If
If bolValid = True Then
dblEast1 = Val(Left(strPOO, 5))
dblEast2 = Val(Left(strPOI, 5))
dblNorth1 = Val(Right(strPOO, 5))
dblNorth2 = Val(Right(strPOI, 5))
diffEast = dblEast1 - dblEast2
Select Case diffEast
Case Is > 49000
diffEast = 100000 - diffEast
Case Is < -49000
diffEast = 100000 + diffEast
diffEast = diffEast - (diffEast * 2)
Case Else
diffEast = diffEast
End Select
diffNorth = dblNorth1 - dblNorth2
Select Case diffNorth
Case Is > 49000
diffNorth = 100000 - diffNorth
Case Is < -49000
diffNorth = 100000 + diffNorth
diffNorth = diffNorth - (diffNorth * 2)
Case Else
diffNorth = diffNorth
End Select
Distance = Round(Math.Sqrt((dblEast2 - dblEast1) ^ 2 +
(dblNorth2 - dblNorth1) ^ 2), 0)
Else : Distance = 0
End If
End Function
Public Function Direction(ByVal diffNorth As Double, ByVal diffEast As
Double) _
As Double
'Use IF THEN ELSE to determine which quadrant the target is in
'and call that quadrant funtion to calculate the direction
'Determines quadrant 1
If (diffNorth > 0 Or diffNorth = 0) And _
(diffEast > 0 Or diffEast = 0) Then
Direction = Round(Quadrant1(diffNorth, diffEast), 0)
Else
'Determines quadrant 2
If (diffNorth < 0 Or diffNorth = 0) And _
(diffEast > 0 Or diffEast = 0) Then
Direction = Round(Quadrant2(diffNorth, diffEast), 0)
Else
'Determines quadrant 3
If (diffNorth < 0 Or diffNorth = 0) And _
(diffEast < 0 Or diffNorth = 0) Then
Direction = Round(Quadrant3(diffNorth, diffEast), 0)
Else
'Determines quadrant 4
If (diffNorth > 0 Or diffNorth = 0) And _
(diffEast < 0 Or diffEast = 0) Then
Direction = Round(Quadrant4(diffNorth, diffEast), 0)
End If
End If
End If
End If
End Function
Private Function Quadrant1(ByVal diffNorth As Double, _
ByVal diffEast As Double) As Double
'Assign direction value to due North(6400) and due East(1600)
If diffNorth = 0 Then
Slope = 1600
Else
If diffEast = 0 Then
Slope = 6400
'Caculate direction values between 6400 and 1600 using
'the ArcTan of slope formula
Else
Slope = diffEast / diffNorth
Slope = Math.Atan(Slope) / 0.000981747
End If
End If
'Round slope and pass it back to Direction Function as Quadrant1
Quadrant1 = Round(Slope, 1)
End Function
Private Function Quadrant2(ByVal diffNorth As Double, _
ByVal diffEast As Double) As Double
'Assign direction value to due South(3200) and due East(1600)
If diffNorth = 0 Then
Slope = 1600
Else
If diffEast = 0 Then
Slope = 3200
'Caculate direction values between 1600 and 3200 using
'the ArcTan of slope formula
Else
Slope = diffNorth / diffEast
Slope = Math.Atan(Slope) / 0.000981747
Slope = Abs(Slope) + 1600
End If
End If
'Round slope and pass it back to Direction Function as Quadrant2
Quadrant2 = Round(Slope, 1)
End Function
Private Function Quadrant3(ByVal diffNorth As Double, _
ByVal diffEast As Double) As Double
'Assign direction value to due South(3200) and due West(4800)
If diffNorth = 0 Then
Slope = 4800
Else
If diffEast = 0 Then
Slope = 3200
'Caculate direction values between 3200 and 4800 using
'the ArcTan of slope formula
Else
Slope = diffEast / diffNorth
Slope = Math.Atan(Slope) / 0.000981747
Slope = Abs(Slope) + 3200
End If
End If
'Round slope and pass it back to Direction Function as Quadrant3
Quadrant3 = Round(Slope, 1)
End Function
Private Function Quadrant4(ByVal diffNorth As Double, _
ByVal diffEast As Double) As Double
'Assign direction value to due North(6400) and due West(4800)
If diffNorth = 0 Then
Slope = 4800
Else
If diffEast = 0 Then
Slope = 6400
'Caculate direction values between 4800 and 6400 using
'the ArcTan of slope formula
Else
Slope = diffNorth / diffEast
Slope = Math.Atan(Slope) / 0.000981747
Slope = Abs(Slope) + 4800
End If
End If
'Round slope and pass it back to Direction Function as Quadrant4
Quadrant4 = Round(Slope, 1)
End Function