Click here to Skip to main content
15,888,802 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen16-Oct-12 4:21
professionalEddy Vluggen16-Oct-12 4:21 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 4:13
zaimah17-Oct-12 4:13 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen17-Oct-12 4:51
professionalEddy Vluggen17-Oct-12 4:51 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 5:25
zaimah17-Oct-12 5:25 
GeneralRe: How to update Gridview with value textbox = Null Pin
zaimah17-Oct-12 6:04
zaimah17-Oct-12 6:04 
GeneralRe: How to update Gridview with value textbox = Null Pin
Eddy Vluggen17-Oct-12 9:20
professionalEddy Vluggen17-Oct-12 9:20 
AnswerRe: [SOLVED] How to update Gridview with value textbox = Null Pin
josephSurgeon31-Oct-12 4:27
josephSurgeon31-Oct-12 4:27 
QuestionIndex was outside the bounds of the array Pin
etteychan12-Oct-12 19:03
etteychan12-Oct-12 19:03 
hi, i have a problem of Index was outside the bounds of the array. i don't understand how to amend the existing solution in my case. anyone could help me? the message error is System.IndexOutOfRangeException {"Index was outside the bounds of the array. Below is the code & the error is at sixth last line(strTextOut = arrMicrosensor(intNum).strCode)

Public Function sensorWithinRange() As MicrosensorStruct()

        Dim arrMicrosensor() As MicrosensorStruct                               '
        Dim dblNearestStation As MicrosensorStruct                              '
        Dim intStationCounter As Integer                                        'Counter for stations
        Dim dblStationE As Double                                               'Easting coords of one station
        Dim dblStationN As Double                                               'Northing coords of one station
        Dim intNearestSensor As Integer                                         '
        Dim strNearestSensor() As String                                        '
        Dim intA, intB, IntMaxIndex As Integer                                  '
        Dim dblMaxValue As Double                                               '
        Dim sMax, sTemp As MicrosensorStruct                                    '
        Dim strTextOut As String                                                '

        Dim strArrColumns() As String                                           'Columns within 1 station record
        Dim chrArrDelim() As Char = " ,".ToCharArray()                          'File delimiter

        Dim sReader As IO.StreamReader
        Dim strRecord As String

        intStationCounter = -1
        intNearestSensor = 0
        dblStationE = CDbl(txtEasting.Text)
        dblStationN = CDbl(txtNorthing.Text)

        sReader = IO.File.OpenText(txtFilename.Text)
        strRecord = sReader.ReadLine()

        strRecord = sReader.ReadLine()

        Do While (Not sReader.EndOfStream)

            strRecord = sReader.ReadLine()
            intStationCounter = (intStationCounter + 1)

        Loop

        sReader.Close()

        Dim intNrStations As Integer                                            'Total number of station
        ReDim arrMicrosensor(intNrStations)

        sReader = IO.File.OpenText(txtFilename.Text)
        strRecord = sReader.ReadLine()
        dblNearestStation.dblRngeDist = Double.PositiveInfinity

        For intStationCounter = 0 To intNrStations - 1
            strRecord = sReader.ReadLine()
            strArrColumns = strRecord.Split(chrArrDelim)

            arrMicrosensor(intStationCounter).lngID = CLng(strArrColumns(0))
            arrMicrosensor(intStationCounter).strOUTCORP = strArrColumns(1)
            arrMicrosensor(intStationCounter).strCode = strArrColumns(2)
            arrMicrosensor(intStationCounter).dblNorthing = CDbl(strArrColumns(3))
            arrMicrosensor(intStationCounter).dblEasting = CDbl(strArrColumns(4))
            arrMicrosensor(intStationCounter).dblRngeDist = CalculateDistance(dblStationN, dblStationE, arrMicrosensor(intStationCounter).dblNorthing, arrMicrosensor(intStationCounter).dblEasting)

            If arrMicrosensor(intStationCounter).dblRngeDist < CDbl(txtRangeDist.Text) Then
                intNearestSensor = intNearestSensor + 1

                'string for text in listbox
                lboNearestStation.Items.Add("STATION ID:" & arrMicrosensor(intStationCounter).lngID.ToString & " , " _
                                    & "REFERENCE CODE:" & arrMicrosensor(intStationCounter).strCode & " , NORTHING:" _
                                    & arrMicrosensor(intStationCounter).dblNorthing.ToString("F") & ", EASTING:" _
                                    & arrMicrosensor(intStationCounter).dblEasting.ToString("F") & ", at:" _
                                    & arrMicrosensor(intStationCounter).dblRngeDist.ToString("F") & "m")

            End If

        Next intStationCounter
        sReader.Close()

        ReDim strNearestSensor(intNearestSensor - 1)

        For intStationCounter = 0 To intNrStations - 1
            If arrMicrosensor(intStationCounter).dblRngeDist < CDbl(txtRangeDist.Text) Then
                intNearestSensor = 0
                strNearestSensor(intNearestSensor) = arrMicrosensor(intStationCounter).strCode
            End If

        Next

        Dim intNum As Integer

        intNum = CInt(txtNrSensor.Text)

        'For intNum = 0 To intNum - 1
        For intNum = 0 To intNum - 1
            For intA = arrMicrosensor.GetUpperBound(0) To 1 Step -1

                sMax = arrMicrosensor(0)
                dblMaxValue = sMax.dblRngeDist
                IntMaxIndex = 0

                For intB = 0 To intA
                    If arrMicrosensor(intB).dblRngeDist > dblMaxValue Then
                        dblMaxValue = arrMicrosensor(intB).dblRngeDist
                        IntMaxIndex = intB

                    End If
                Next intB

                sTemp = arrMicrosensor(intA)
                arrMicrosensor(intA) = arrMicrosensor(IntMaxIndex)
                arrMicrosensor(IntMaxIndex) = sTemp

            Next intA

            strTextOut = arrMicrosensor(intNum).strCode

        Next intNum

        Return arrMicrosensor
    End Function


modified 13-Oct-12 1:40am.

AnswerRe: Index was outside the bounds of the array Pin
Richard MacCutchan12-Oct-12 21:07
mveRichard MacCutchan12-Oct-12 21:07 
QuestionConfused by my own code: LINQ FirstOrDefault Pin
Steven St. John11-Oct-12 13:18
Steven St. John11-Oct-12 13:18 
AnswerRe: Confused by my own code: LINQ FirstOrDefault Pin
Steven St. John16-Oct-12 6:58
Steven St. John16-Oct-12 6:58 
QuestionVB.NET Parameters error Pin
Diego Carrion11-Oct-12 4:12
Diego Carrion11-Oct-12 4:12 
AnswerRe: VB.NET Parameters error Pin
Simon_Whale11-Oct-12 4:45
Simon_Whale11-Oct-12 4:45 
GeneralRe: VB.NET Parameters error Pin
Diego Carrion11-Oct-12 4:47
Diego Carrion11-Oct-12 4:47 
GeneralRe: VB.NET Parameters error Pin
ChandraRam11-Oct-12 11:06
ChandraRam11-Oct-12 11:06 
QuestionSlow Ping and not guaranteed success Pin
Herboren10-Oct-12 5:44
Herboren10-Oct-12 5:44 
AnswerRe: Slow Ping and not guaranteed success Pin
Dave Kreskowiak10-Oct-12 8:13
mveDave Kreskowiak10-Oct-12 8:13 
GeneralRe: Slow Ping and not guaranteed success Pin
Herboren10-Oct-12 11:33
Herboren10-Oct-12 11:33 
GeneralRe: Slow Ping and not guaranteed success Pin
Dave Kreskowiak10-Oct-12 13:01
mveDave Kreskowiak10-Oct-12 13:01 
GeneralRe: Slow Ping and not guaranteed success Pin
Herboren10-Oct-12 16:20
Herboren10-Oct-12 16:20 
GeneralRe: Slow Ping and not guaranteed success Pin
Dave Kreskowiak10-Oct-12 23:50
mveDave Kreskowiak10-Oct-12 23:50 
GeneralRe: Slow Ping and not guaranteed success Pin
Eddy Vluggen15-Oct-12 1:19
professionalEddy Vluggen15-Oct-12 1:19 
QuestionFunction Not Found From Dll Component Pin
AmbiguousName10-Oct-12 1:57
AmbiguousName10-Oct-12 1:57 
AnswerRe: Function Not Found From Dll Component Pin
Eddy Vluggen11-Oct-12 0:08
professionalEddy Vluggen11-Oct-12 0:08 
GeneralRe: Function Not Found From Dll Component Pin
AmbiguousName12-Oct-12 1:07
AmbiguousName12-Oct-12 1:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.