vb class second attempt

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • thomasp@msala.net

    #1

    vb class second attempt


    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
  • _AnonCoward

    #2
    Re: vb class second attempt


    <thomasp@msala. net> wrote in message
    news:430cb8f1$0 $6974$b9f67a60@ news.newsdemon. com...
    :
    : 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.



    (Please be aware, I've added the occasional line continuation character
    (" _") in order to reformat your code for the newsgroup. I haven't
    changed any actual logic - I hope!)



    '************** *************** *************** *************** ************
    *************** ********
    :
    '************** *************** *************** *************** ************
    *************** ********
    : '**** 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



    I advocate you use Option Strict as a general practice. You have a
    number of implicit conversions going on in your code you may not know
    about (I'll point these out in a bit). These are possibly harmless here,
    but they can create unexpected errors. Also, I always automatically
    import System and Microsoft.Visua lBasic.


    Option Strict
    Imports Microsoft.Visua lBasic
    Imports System
    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


    Here is one of those implicit conversions I mentioned earlier. Option
    Strict will reject this. Use this instead:


    Private _AveragePOI As String = "0"


    Or declare it as an Integer


    : 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



    Be careful here - sorting strings that represent numbers can produce
    unexpected results. For example, "10" comes before "2" in a string
    comparison.


    : 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


    Try this instead (cleaner code and possibly a triffle faster):


    _TargetsTracked = aryDates.Length


    : 'These two properties give the length of the
    : 'IDF attack and the average time between each
    : 'acquisition
    : _IDFTimeSpan = funIDFTimeSpan( aryDates)
    :
    : _AvgTimeBetween Tracks = _
    : TimeSpan.FromSe conds( _
    : _IDFTimeSpan.To talSeconds / _TargetsTracked )
    :
    : '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)


    As far as I'm aware, "Call" isn't necessary. Doesn't hurt anything
    however.


    : 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


    _TargetsTracked is an Integer but you are returning a String. Are you
    sure about that? Better in my judgement to return this as an Integer
    type and let the consumer convert as needed. Also, since a String is a
    reference type (created on the heap) and Integer is a value type (which
    exists on the stack), converting an Integer to a String involves
    additional overhead. It's a performance hit.


    If you do want to return a string, do so explicitly - this way, there is
    no ambiguity as to what your intentions are here.


    Return CStr(_TargetsTr acked)


    This by the way is an example of where Option Strict is helpful. This
    will compile fine without Option Strict turned on and this conversion
    will be allowed. However, if this isn't what you intended, you wouldn't
    be informed.


    : 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)


    You've already imported the System.Text.Reg ularExpressions namespace, so
    the fully qualified name isn't necessary. Also, since these is strictly
    a test for numbers, I don't see where the IgnoreCase option is necessary
    here.


    Dim rexTarget As New Regex("^([0-9]{10})$")


    : 'check the length
    : If Len(Trim(strGri d)) <> 10 Then
    : Return False
    : End If


    This is redundant. Your reg expression will test this for you. For
    example, the following strings will not produce a match:


    "123456789"
    "123456789 "
    " 123456789"
    "1234567891 23"
    "123"
    "abcdefghij "


    : If rexTarget.IsMat ch(strGrid) Then
    : Return True
    : Else
    : Return False
    : End If
    : End Function


    I personally like compact code. The following works just as well (and,
    again, is perhaps a tiny bit faster):


    Return rexTarget.isMat ch(strGrid)


    If fact, if you want to get fancy, you can make this entire test a
    single line of code:


    Private Function funValidGrid(By Val strGrid As String) As Boolean
    Return New Regex("^([0-9]{10})$").isMatc h(strGrid)
    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


    Ok, I think you've got a genuine bug going on here as well as another
    implicit conversion. I don't think this expression is doing what you
    want:


    Return intTotal / x + 1


    You are first dividing intTotal by x then adding 1 to the result. I
    gather your intention is to first add 1 to x then divide that into
    intTotal. If so, this is what you want:


    intTotal / (x + 1)


    And, you have another implicit conversion going on here. intTotal / (x +
    1) generates a Double. Your function returns an Integer however. Since
    you don't have Option Strict turned on, the compiler is making the
    conversion for you. However, such conversions will not necessarily
    generate the results you want. Consider a hypothetical:


    intTotal = 20
    x = 10


    This becomes: 20 / (10 + 1) and will render a result of
    1.8181818181818 2. If you allow this to be implicity converted, your
    result would be 2 (such conversions round to the nearest value). If you
    wanted 1 in this case (that is, just grab the portion before the decimal
    point), you'll need a different approach. Here are a few options:


    'This produces the same result as the implicit conversion,
    'but it's explicit - this way, it's clear in your code
    'this is what you intended

    CInt(intTotal / (x + 1))


    'This is integer division. It will simply discard unwanted
    'digits and does not need to be converted

    intTotal \ (x + 1)


    : 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


    To be honest, I'm not sure what is happening here. Please forgive me if
    I'm misunderstand your code here. I gather you want to find the highest
    and lowest values then return the difference between them. Yes? If so,
    then I believe you've already sorted these values in your constructor
    before calling this function:


    Array.Sort(aryP OOEasting)
    Array.Sort(aryP OONorthing)

    '...

    _POOEastSpread = funSpread(aryPO OEasting)
    _POONorthSpread = funSpread(aryPO ONorthing)


    If I'm correct in this, why not just grab the first and last elements of
    the sorted array and do the comparison from there?

    Public Shared Function funSpread(ByVal aryGrids() As Integer) _
    As Integer

    Dim intLow As Integer
    Dim intHigh As Integer

    intLow = aryGrids(0)
    intHigh = aryGrids(aryGri ds.GetUpperBoun d(0))
    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


    If you import the Microsoft.Visua lBasic namespace, you can simplify this
    code.


    For x As Integer = 0 To aryFullGrid.Get UpperBound(0)
    If funValidGrid(ar yFullGrid(x)) Then
    aryEastingGird( x) = CInt(Left(aryFu llGrid(x), 5))
    aryNorthingGird (x) = CInt(Right(aryF ullGrid(x), 5))
    End If
    Next


    : #End Region
    :
    : End Class


    Ralf
    --
    ----------------------------------------------------------
    * ^~^ ^~^ *
    * _ {~ ~} {~ ~} _ *
    * /_``>*< >*<''_\ *
    * (\--_)++) (++(_--/) *
    ----------------------------------------------------------
    There are no advanced students in Aikido - there are only
    competent beginners. There are no advanced techniques -
    only the correct application of basic principles.


    Comment

    • thomasp@msala.net

      #3
      Re: vb class second attempt


      Thanks for all the comments. I had given up on someone responding.

      this was a real screw up on my part:[color=blue]
      > CInt(intTotal / (x + 1))[/color]

      I don't see how I did not see that when I view the results of the report

      The[color=blue]
      > Option Strict[/color]

      Helped me see most of the errors in my code, but has left me with one that I
      have not solved yet.
      This line of code does not work with Option Strict on
      _AveragePOO = _AvgPOOEasting. ToString.PadLef t(5, "0") & " " &
      _AvgPOONorthing .ToString.PadLe ft(5, "0")
      it complains about a string to char conversion.

      these ten digit numbers that I deal with in this code has been a real
      problem for day one. The ten digits
      are actually just a big x y cordinate. Five digits represent x and five
      represent y. This would be fine,
      but it is possible to have a cordinate like 3815703123 when when you split
      them up and asign them to an
      integer you loose the 0 in 03123 or a cordinate like 0315703123 and you end
      up with eight digits. That is
      why I have handled them as string right up till I have to do some type of
      math and then get them back to
      string quickly. Programming is very new to me, but it has made my job a
      whole lot easier having this code
      to automate a lengthy task.

      Once again, thanks very much for help and comments. I know this had to have
      taken a little of your time.

      Thomas

      --
      Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
      ------->>>>>>http://www.NewsDemon.c om<<<<<<------
      Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

      Comment

      • _AnonCoward

        #4
        Re: vb class second attempt


        <thomasp@msala. net> wrote in message
        news:430e0e7a$0 $6979$b9f67a60@ news.newsdemon. com...
        :
        : Thanks for all the comments. I had given up on someone responding.
        :
        : this was a real screw up on my part:
        : > CInt(intTotal / (x + 1))
        :
        : I don't see how I did not see that when I view the results of the
        : report
        :
        : The
        : > Option Strict
        :
        : Helped me see most of the errors in my code, but has left me with one
        : that I have not solved yet.
        : This line of code does not work with Option Strict on
        : _AveragePOO = _AvgPOOEasting. ToString.PadLef t(5, "0") & " " &
        : _AvgPOONorthing .ToString.PadLe ft(5, "0")
        : it complains about a string to char conversion.


        Try ...PadLeft(5, "0"c) (untested)


        Ralf



        Comment

        • _AnonCoward

          #5
          Re: vb class second attempt


          <thomasp@msala. net> wrote in message
          news:430e0e7a$0 $6979$b9f67a60@ news.newsdemon. com...
          :
          : Thanks for all the comments. I had given up on someone responding.
          :
          : this was a real screw up on my part:
          : > CInt(intTotal / (x + 1))
          :
          : I don't see how I did not see that when I view the results of the
          : report
          :
          : The
          : > Option Strict
          :
          : Helped me see most of the errors in my code, but has left me with one
          : that I have not solved yet.
          : This line of code does not work with Option Strict on
          : _AveragePOO = _AvgPOOEasting. ToString.PadLef t(5, "0") & " " &
          : _AvgPOONorthing .ToString.PadLe ft(5, "0")
          : it complains about a string to char conversion.


          Try ...PadLeft(5, "0"c) (untested)


          Ralf



          Comment

          • thomasp@msala.net

            #6
            Re: vb class second attempt


            I used PadLeft(5, CChar("0")) which if I had to guess means the same as your
            PadLeft(5, "0"c) answer.


            Thanks,

            Thomas

            --
            Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
            ------->>>>>>http://www.NewsDemon.c om<<<<<<------
            Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

            Comment

            • _AnonCoward

              #7
              Re: vb class second attempt


              <thomasp@msala. net> wrote in message
              news:430ed3df$0 $6920$b9f67a60@ news.newsdemon. com...
              :
              : I used PadLeft(5, CChar("0")) which if I had to guess means the same
              : as your PadLeft(5, "0"c) answer.
              :
              :
              : Thanks,
              :
              : Thomas


              Yes, both approaches will compile identically.


              Ralf


              Comment

              Working...