473,486 Members | 2,353 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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
****
'**** AverageDirection - average Direction from POI to POO
****
'************************************************* *********************************************
'************************************************* *********************************************

Imports System.Text.RegularExpressions
Public Class classIDFReport

Private _TargetsTracked As Integer = 0
Private _IDFTimeSpan As TimeSpan
Private _AvgTimeBetweenTracks 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 _AverageDistance As Integer = 0
Private _AverageDirection As Integer = 0

#Region "Constructors"

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(aryPOO)
Array.Sort(aryPOI)
Array.Sort(aryDistance)
Array.Sort(aryDirection)

'Report is based on number of records
'With valid dates
_TargetsTracked = aryDates.GetUpperBound(0) + 1

'These two properties give the length of the
'IDF attack and the average time between each
'acquisition
_IDFTimeSpan = funIDFTimeSpan(aryDates)
'_IDFTimeSpan = TimeSpan.FromSeconds(_IDFTimeSpan.TotalSeconds)
_AvgTimeBetweenTracks =
TimeSpan.FromSeconds(_IDFTimeSpan.TotalSeconds / _TargetsTracked)
'_AvgTimeBetweenTracks =
TimeSpan.FromSeconds(_AvgTimeBetweenTracks.TotalSe conds)

'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 subFillGridArray(aryPOO, aryPOOEasting, aryPOONorthing)
Array.Sort(aryPOOEasting)
Array.Sort(aryPOONorthing)
_AvgPOOEasting = funAverage(aryPOOEasting)
_AvgPOONorthing = funAverage(aryPOONorthing)
_AveragePOO = _AvgPOOEasting.ToString.PadLeft(5) & " " &
_AvgPOONorthing.ToString.PadLeft(5)
_POOEastSpread = funSpread(aryPOOEasting)
_POONorthSpread = funSpread(aryPOONorthing)
_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 subFillGridArray(aryPOI, aryPOIEasting, aryPOINorthing)
Array.Sort(aryPOIEasting)
Array.Sort(aryPOINorthing)
_AvgPOIEasting = funAverage(aryPOIEasting)
_AvgPOINorthing = funAverage(aryPOINorthing)
_AveragePOI = _AvgPOIEasting.ToString.PadLeft(5) & " " &
_AvgPOINorthing.ToString.PadLeft(5)
_POIEastSpread = funSpread(aryPOIEasting)
_POINorthSpread = funSpread(aryPOINorthing)
_POISpread = _POIEastSpread.ToString & " / " &
_POINorthSpread.ToString

_AverageDistance = funAverage(aryDistance)
_AverageDirection = funAverage(aryDirection)

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 AvgTimeBetweenTrack() As TimeSpan
Get
Return _AvgTimeBetweenTracks
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 _AverageDistance
End Get
End Property

Public ReadOnly Property AverageDirection() As Integer
Get
Return _AverageDirection
End Get
End Property
#End Region
#Region "Functions"

Private Function funValidGrid(ByVal strGrid As String) As Boolean

'Setup a regular expression
Dim rexTarget As New
System.Text.RegularExpressions.Regex("^([0-9]{10})$",
RegexOptions.IgnoreCase)

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

If rexTarget.IsMatch(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(aryDates)

For x As Integer = 0 To aryDates.GetUpperBound(0)
If IsDate(aryDates(x)) Then
If x = 0 Then
StartTime = aryDates(x)
End If
EndTime = aryDates(x)
End If
Next

Return EndTime.Subtract(StartTime)

End Function

Public Shared Function funAverage(ByVal aryGrid() As Integer) As Integer

Dim x As Integer = 0
Dim intTotal As Integer = 0

For x = 0 To aryGrid.GetUpperBound(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.GetUpperBound(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 subFillGridArray(ByVal aryFullGrid() As String, ByRef
aryEastingGird() As Integer, _
ByRef aryNorthingGird() As Integer)

For x As Integer = 0 To aryFullGrid.GetUpperBound(0)
If funValidGrid(aryFullGrid(x)) Then
aryEastingGird(x) =
CInt(Microsoft.VisualBasic.Left(aryFullGrid(x), 5))
aryNorthingGird(x) =
CInt(Microsoft.VisualBasic.Right(aryFullGrid(x), 5))
End If
Next

End Sub

#End Region

End Class

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #1
6 1429

<th*****@msala.net> wrote in message
news:43**********************@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
: ****
: '**** AverageDirection - average Direction from POI to POO
: ****
:
'************************************************* **********************
***********************
:
'************************************************* **********************
***********************
:
: Imports System.Text.RegularExpressions

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.VisualBasic.
Option Strict
Imports Microsoft.VisualBasic
Imports System
Imports System.Text.RegularExpressions
: Public Class classIDFReport
:
: Private _TargetsTracked As Integer = 0
: Private _IDFTimeSpan As TimeSpan
: Private _AvgTimeBetweenTracks 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 _AverageDistance As Integer = 0
: Private _AverageDirection As Integer = 0
:
: #Region "Constructors"
:
: 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(aryPOO)
: Array.Sort(aryPOI)
: Array.Sort(aryDistance)
: Array.Sort(aryDirection)
:
: 'Report is based on number of records
: 'With valid dates
: _TargetsTracked = aryDates.GetUpperBound(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)
:
: _AvgTimeBetweenTracks = _
: TimeSpan.FromSeconds( _
: _IDFTimeSpan.TotalSeconds / _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 subFillGridArray(aryPOO, aryPOOEasting, aryPOONorthing)
As far as I'm aware, "Call" isn't necessary. Doesn't hurt anything
however.
: Array.Sort(aryPOOEasting)
: Array.Sort(aryPOONorthing)
: _AvgPOOEasting = funAverage(aryPOOEasting)
: _AvgPOONorthing = funAverage(aryPOONorthing)
: _AveragePOO = _AvgPOOEasting.ToString.PadLeft(5) & " " & _
: _AvgPOONorthing.ToString.PadLeft(5)
: _POOEastSpread = funSpread(aryPOOEasting)
: _POONorthSpread = funSpread(aryPOONorthing)
: _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 subFillGridArray(aryPOI, aryPOIEasting, aryPOINorthing)
: Array.Sort(aryPOIEasting)
: Array.Sort(aryPOINorthing)
: _AvgPOIEasting = funAverage(aryPOIEasting)
: _AvgPOINorthing = funAverage(aryPOINorthing)
: _AveragePOI = _AvgPOIEasting.ToString.PadLeft(5) & " " & _
: _AvgPOINorthing.ToString.PadLeft(5)
: _POIEastSpread = funSpread(aryPOIEasting)
: _POINorthSpread = funSpread(aryPOINorthing)
: _POISpread = _POIEastSpread.ToString & " / " & _
: _POINorthSpread.ToString
:
: _AverageDistance = funAverage(aryDistance)
: _AverageDirection = funAverage(aryDirection)
:
: 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(_TargetsTracked)
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 AvgTimeBetweenTrack() As TimeSpan
: Get
: Return _AvgTimeBetweenTracks
: 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 _AverageDistance
: End Get
: End Property
:
: Public ReadOnly Property AverageDirection() As Integer
: Get
: Return _AverageDirection
: End Get
: End Property
: #End Region
:
:
: #Region "Functions"
:
: Private Function funValidGrid(ByVal strGrid As String) As Boolean
:
: 'Setup a regular expression
: Dim rexTarget As New _
: System.Text.RegularExpressions.Regex("^([0-9]{10})$", _
: RegexOptions.IgnoreCase)
You've already imported the System.Text.RegularExpressions 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(strGrid)) <> 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"
"123456789123"
"123"
"abcdefghij"
: If rexTarget.IsMatch(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.isMatch(strGrid)
If fact, if you want to get fancy, you can make this entire test a
single line of code:
Private Function funValidGrid(ByVal strGrid As String) As Boolean
Return New Regex("^([0-9]{10})$").isMatch(strGrid)
End Function
: Public Shared Function funIDFTimeSpan(ByVal aryDates() As Date) As
: TimeSpan
:
: Dim StartTime As Date
: Dim EndTime As Date
:
: Array.Sort(aryDates)
:
: For x As Integer = 0 To aryDates.GetUpperBound(0)
: If IsDate(aryDates(x)) Then
: If x = 0 Then
: StartTime = aryDates(x)
: End If
: EndTime = aryDates(x)
: End If
: Next
:
: Return EndTime.Subtract(StartTime)
:
: End Function
:
: Public Shared Function funAverage(ByVal aryGrid() As Integer) _
: As Integer
:
: Dim x As Integer = 0
: Dim intTotal As Integer = 0
:
: For x = 0 To aryGrid.GetUpperBound(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.81818181818182. 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.GetUpperBound(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(aryPOOEasting)
Array.Sort(aryPOONorthing)

'...

_POOEastSpread = funSpread(aryPOOEasting)
_POONorthSpread = funSpread(aryPOONorthing)
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(aryGrids.GetUpperBound(0))
Return intHigh - intLow

End Function
: #End Region
:
: #Region "Subs"
:
: Private Sub subFillGridArray(ByVal aryFullGrid() As String, _
: ByRef aryEastingGird() As Integer, _
: ByRef aryNorthingGird() As Integer)
:
: For x As Integer = 0 To aryFullGrid.GetUpperBound(0)
: If funValidGrid(aryFullGrid(x)) Then
: aryEastingGird(x) = _
: CInt(Microsoft.VisualBasic.Left(aryFullGrid(x), 5))
: aryNorthingGird(x) = _
: CInt(Microsoft.VisualBasic.Right(aryFullGrid(x), 5))
: End If
: Next
:
: End Sub
If you import the Microsoft.VisualBasic namespace, you can simplify this
code.
For x As Integer = 0 To aryFullGrid.GetUpperBound(0)
If funValidGrid(aryFullGrid(x)) Then
aryEastingGird(x) = CInt(Left(aryFullGrid(x), 5))
aryNorthingGird(x) = CInt(Right(aryFullGrid(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.
Nov 21 '05 #2

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.PadLeft(5, "0") & " " &
_AvgPOONorthing.ToString.PadLeft(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.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #3

<th*****@msala.net> wrote in message
news:43**********************@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.PadLeft(5, "0") & " " &
: _AvgPOONorthing.ToString.PadLeft(5, "0")
: it complains about a string to char conversion.
Try ...PadLeft(5, "0"c) (untested)
Ralf

Nov 21 '05 #4

<th*****@msala.net> wrote in message
news:43**********************@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.PadLeft(5, "0") & " " &
: _AvgPOONorthing.ToString.PadLeft(5, "0")
: it complains about a string to char conversion.
Try ...PadLeft(5, "0"c) (untested)
Ralf

Nov 21 '05 #5

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.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
Nov 21 '05 #6

<th*****@msala.net> wrote in message
news:43**********************@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
Nov 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2173
by: Edward Diener | last post by:
This has occurred in MC++, but since there is very little response on that NG, I am also reporting it here in the hope that someone can find me a workaround, and report it to MS. If a __value...
15
9026
by: Steven T. Hatton | last post by:
The following may strike many of you as just plain silly, but it represents the kind of delelima I find myself in when trying to make a design decision. This really is a toy project written for...
5
5901
by: surrealtrauma | last post by:
the requirement is : Create a class called Rational (rational.h) for performing arithmetic with fractions. Write a program to test your class. Use Integer variables to represent the private data...
6
2523
by: gustav04 | last post by:
hi all i have a question: what is the difference between a c-function and an c++ class method (both do exactly the same thing). lets say, i have a function called print2std() and a class...
4
1449
by: Hisham | last post by:
hey all i have problem here suppose i made class base and i derived drv that has function set data in the base class when i want to have array of pointers for both of them base* ba; drv* dr;...
0
1179
by: Edward Diener | last post by:
If a __value class with an event is put into an assembly, and a __gc class in another assembly attempts to attach its own event handler to the __value class's event of an embedded object of the...
9
2481
by: Brian Henry | last post by:
If i inherite a queue class into my class, and do an override of the enqueue member, how would i then go about actually doing an enqueue of an item? I am a little confused on this one... does over...
5
2313
by: Slant | last post by:
Here's a question that most will have different answers to. I'm just dying to find a solution that seems halfway automated!! There really are two seperate issues which might be answered by the...
12
2662
by: Kira Yamato | last post by:
I've posted this in another thread, but I suppose I should've started a new thread for it instead. I cannot get the following short program to compile under g++: #include <iostream> #include...
0
6967
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7132
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7180
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7341
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4870
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4564
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3076
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1381
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
266
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.