For those who gave advice on the shortfalls of my first attempt at writing a
vb.net class, Thank You.
I hope that I was able to apply some of your advice to this larger atempt.
At first I didn' t really see an
advantage of a Class over a module containing the same functions, but now
that this Class is working
for me, I have found a possible use. Since this class will hold all the
values used in a report I am
building, I think I will now be able to compare the data in two or more
reports easier than I may
have been able to before the class was written.
Anyway, thanks for the comments on the first one and feel free to comment on
this one. I will try
to correct my mistakes as you point them out.
'************** *************** *************** *************** *************** *************** *****
'************** *************** *************** *************** *************** *************** *****
'**** This class accepts five parameters. These parameters are passed as a
Date/Time ****
'**** array, a string array containing Point of Origin grids, a string
array containing ****
'**** Point of Impact grids, an integer array containing distances, and an
integer array ****
'**** containing directions. From these variables the Class calculates and
exposes 17 ****
'**** ReadOnly properties to be used in an Indirect Fire Report.
****
'**** Acquisitions - which is a count of the targets being reported.
****
'**** IDFTimeSpan - length in minutes and seconds of the IDF attack
****
'**** AvgPOOEasting - the average Easting grid of the POO
****
'**** AvgPOONorthing - the average Northing grid of the POO
****
'**** AveragePOO - string representation of the full POO grid Easting and
Northing ****
'**** POOEastSpread - largest spread in POO easting grids
****
'**** POONorthSpread - largest spread in POO northing grids
****
'**** POOSpread - string representation of the POO Easting and Northing
spread ****
'**** AvgPOIEasting - the average Easting grid of the POI
****
'**** AvgPOINorthing - the average Northing grid of the POI
****
'**** AveragePOI - string representation of the full POI grid Easting and
Northing ****
'**** POIEastSpread - largest spread in POI easting grids
****
'**** POINorthSpread - largest spread in POI northing grids
****
'**** POISpread - string representation of the POI Easting and Northing
spread ****
'**** AverageDistance - average Distance from POI to POO
****
'**** AverageDirectio n - average Direction from POI to POO
****
'************** *************** *************** *************** *************** *************** *****
'************** *************** *************** *************** *************** *************** *****
Imports System.Text.Reg ularExpressions
Public Class classIDFReport
Private _TargetsTracked As Integer = 0
Private _IDFTimeSpan As TimeSpan
Private _AvgTimeBetween Tracks As TimeSpan
Private _AvgPOOEasting As Integer = 0
Private _AvgPOONorthing As Integer = 0
Private _AveragePOO As String = String.Empty
Private _POOEastSpread As Integer = 0
Private _POONorthSpread As Integer = 0
Private _POOSpread As String = String.Empty
Private _AvgPOIEasting As Integer = 0
Private _AvgPOINorthing As Integer = 0
Private _AveragePOI As String = 0
Private _POIEastSpread As Integer = 0
Private _POINorthSpread As Integer = 0
Private _POISpread As String = String.Empty
Private _AverageDistanc e As Integer = 0
Private _AverageDirecti on As Integer = 0
#Region "Constructo rs"
Public Sub New(ByVal aryDates() As Date, ByVal aryPOO() As String, ByVal
aryPOI() As String, _
ByVal aryDistance() As Integer, ByVal aryDirection() As Integer)
'Sort the received arrays
Array.Sort(aryP OO)
Array.Sort(aryP OI)
Array.Sort(aryD istance)
Array.Sort(aryD irection)
'Report is based on number of records
'With valid dates
_TargetsTracked = aryDates.GetUpp erBound(0) + 1
'These two properties give the length of the
'IDF attack and the average time between each
'acquisition
_IDFTimeSpan = funIDFTimeSpan( aryDates)
'_IDFTimeSpan = TimeSpan.FromSe conds(_IDFTimeS pan.TotalSecond s)
_AvgTimeBetween Tracks =
TimeSpan.FromSe conds(_IDFTimeS pan.TotalSecond s / _TargetsTracked )
'_AvgTimeBetwee nTracks =
TimeSpan.FromSe conds(_AvgTimeB etweenTracks.To talSeconds)
'The Point of Origin (POO) array is passed to the sub
'that divides it into the Easting and Northing
'arrays. These two arrays are then sorted and
'various functions are called to assign each of
'the POO properties their values
Dim aryPOOEasting(_ TargetsTracked - 1) As Integer
Dim aryPOONorthing( _TargetsTracked - 1) As Integer
Call subFillGridArra y(aryPOO, aryPOOEasting, aryPOONorthing)
Array.Sort(aryP OOEasting)
Array.Sort(aryP OONorthing)
_AvgPOOEasting = funAverage(aryP OOEasting)
_AvgPOONorthing = funAverage(aryP OONorthing)
_AveragePOO = _AvgPOOEasting. ToString.PadLef t(5) & " " &
_AvgPOONorthing .ToString.PadLe ft(5)
_POOEastSpread = funSpread(aryPO OEasting)
_POONorthSpread = funSpread(aryPO ONorthing)
_POOSpread = _POOEastSpread. ToString & " / " &
_POONorthSpread .ToString
'The Point of Impact (POI) array is passed to the sub
'that divides it into the Easting and Northing
'arrays. These two arrays are then sorted and
'various functions are called to assign each of
'the POI properties their values
Dim aryPOIEasting(_ TargetsTracked - 1) As Integer
Dim aryPOINorthing( _TargetsTracked - 1) As Integer
Call subFillGridArra y(aryPOI, aryPOIEasting, aryPOINorthing)
Array.Sort(aryP OIEasting)
Array.Sort(aryP OINorthing)
_AvgPOIEasting = funAverage(aryP OIEasting)
_AvgPOINorthing = funAverage(aryP OINorthing)
_AveragePOI = _AvgPOIEasting. ToString.PadLef t(5) & " " &
_AvgPOINorthing .ToString.PadLe ft(5)
_POIEastSpread = funSpread(aryPO IEasting)
_POINorthSpread = funSpread(aryPO INorthing)
_POISpread = _POIEastSpread. ToString & " / " &
_POINorthSpread .ToString
_AverageDistanc e = funAverage(aryD istance)
_AverageDirecti on = funAverage(aryD irection)
End Sub
#End Region
#Region "Properties "
Public ReadOnly Property Acquisitions() As String
Get
Return _TargetsTracked
End Get
End Property
Public ReadOnly Property IDFTimeSpan() As TimeSpan
Get
Return _IDFTimeSpan
End Get
End Property
Public ReadOnly Property AvgTimeBetweenT rack() As TimeSpan
Get
Return _AvgTimeBetween Tracks
End Get
End Property
Public ReadOnly Property AvgPOOEasting() As Integer
Get
Return _AvgPOOEasting
End Get
End Property
Public ReadOnly Property AvgPOONorthing( ) As Integer
Get
Return _AvgPOONorthing
End Get
End Property
Public ReadOnly Property AveragePOO() As String
Get
Return _AveragePOO
End Get
End Property
Public ReadOnly Property POOEastSpread() As Integer
Get
Return _POOEastSpread
End Get
End Property
Public ReadOnly Property POONorthSpread( ) As Integer
Get
Return _POONorthSpread
End Get
End Property
Public ReadOnly Property POOSpread() As String
Get
Return _POOSpread
End Get
End Property
Public ReadOnly Property AvgPOIEasting() As Integer
Get
Return _AvgPOIEasting
End Get
End Property
Public ReadOnly Property AvgPOINorthing( ) As Integer
Get
Return _AvgPOINorthing
End Get
End Property
Public ReadOnly Property AveragePOI() As String
Get
Return _AveragePOI
End Get
End Property
Public ReadOnly Property POIEastSpread() As Integer
Get
Return _POIEastSpread
End Get
End Property
Public ReadOnly Property POINorthSpread( ) As Integer
Get
Return _POINorthSpread
End Get
End Property
Public ReadOnly Property POISpread() As String
Get
Return _POISpread
End Get
End Property
Public ReadOnly Property AverageDistance () As Integer
Get
Return _AverageDistanc e
End Get
End Property
Public ReadOnly Property AverageDirectio n() As Integer
Get
Return _AverageDirecti on
End Get
End Property
#End Region
#Region "Functions"
Private Function funValidGrid(By Val strGrid As String) As Boolean
'Setup a regular expression
Dim rexTarget As New
System.Text.Reg ularExpressions .Regex("^([0-9]{10})$",
RegexOptions.Ig noreCase)
'check the length
If Len(Trim(strGri d)) <> 10 Then
Return False
End If
If rexTarget.IsMat ch(strGrid) Then
Return True
Else
Return False
End If
End Function
Public Shared Function funIDFTimeSpan( ByVal aryDates() As Date) As
TimeSpan
Dim StartTime As Date
Dim EndTime As Date
Array.Sort(aryD ates)
For x As Integer = 0 To aryDates.GetUpp erBound(0)
If IsDate(aryDates (x)) Then
If x = 0 Then
StartTime = aryDates(x)
End If
EndTime = aryDates(x)
End If
Next
Return EndTime.Subtrac t(StartTime)
End Function
Public Shared Function funAverage(ByVa l aryGrid() As Integer) As Integer
Dim x As Integer = 0
Dim intTotal As Integer = 0
For x = 0 To aryGrid.GetUppe rBound(0)
If aryGrid(x) > 0 Then
intTotal += aryGrid(x)
End If
Next
If x > 0 Then
Return intTotal / x + 1
Else
Return 0
End If
End Function
Public Shared Function funSpread(ByVal aryGrids() As Integer) As Integer
Dim intLow As Integer = 0
Dim intHigh As Integer = 0
For x As Integer = 0 To aryGrids.GetUpp erBound(0)
If aryGrids(x) > 999 Then
If x = 0 Then
intLow = aryGrids(x)
End If
intHigh = aryGrids(x)
End If
Next
Return intHigh - intLow
End Function
#End Region
#Region "Subs"
Private Sub subFillGridArra y(ByVal aryFullGrid() As String, ByRef
aryEastingGird( ) As Integer, _
ByRef aryNorthingGird () As Integer)
For x As Integer = 0 To aryFullGrid.Get UpperBound(0)
If funValidGrid(ar yFullGrid(x)) Then
aryEastingGird( x) =
CInt(Microsoft. VisualBasic.Lef t(aryFullGrid(x ), 5))
aryNorthingGird (x) =
CInt(Microsoft. VisualBasic.Rig ht(aryFullGrid( x), 5))
End If
Next
End Sub
#End Region
End Class
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.c om<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Comment