Link to home
Start Free TrialLog in
Avatar of cmdolcet
cmdolcetFlag for United States of America

asked on

Issues with determining Array Length

How to determine a variable length of an array where I am looking for the last two value in the array. Those last two values are always start with "vad" or  "rate" but the array length size can be variable.
SOLUTION
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of cmdolcet

ASKER

Given your last statement is true which it is how could I pull out the value in the array.length-1 and array.length?

I need the actual value in the slot and not the index.
Can you show how you're creating the array?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
So I am looking at how to discover the values ( DistanceVar,RateVar)
The TempArray is array I am working with but how do I assign the DistanceVar and the RateVar which is always the last two slots in the array.

  If tempArray.Length > 0 Then
                    Me.ChartVel.ChartAreas(0).AxisX.Minimum = 0
                    Me.ChartVel.ChartAreas(0).AxisX.Title = "Time"
                    Me.ChartVel.ChartAreas(0).AxisY.Title = "m/s"
                   For intloopVel = 0 To tempArray.Length - 2
                        If intloopVel < 255 Then
                            Veldata.Add(tempArray(intloopVel))
                            Veltime.Add(tempArray(intlooptime))
                            x = Veltime(intloopVel)
                            x = 0.000001 * x
                            y = Veldata(intloopVel)
                            lstVelocityChartReadings.Items.Add(tempArray(intloopVel))
                            Me.ChartVel.Series(0).Points.AddXY(x, y)
                            If Veldata(intloopVel) >= PeakPoint Then
                                PeakPoint = Veldata(intloopVel)
                            End If
                            If value = 100 Then
                            Else
                                Application.DoEvents()
                                value = value + 0.5
                                PrgGraphBar.Value = value
                            End If
                            intlooptime = intlooptime + 1
                        End If
                    Next
                    VelErrorChartCounter = 0
                    PrgGraphBar.Value = 0
                    DistanceVar = tempArray(?)
                    RateVar = tempArray(?)
                    DistanceVar = DistanceVar.Remove(0, 6)
                    RateVar = RateVar.Remove(0, 7)
                    lblPeakValue.Text = PeakPoint
                    lblVelDistance.Text = DistanceVar
                    lblVelocityRateData.Text = RateVar
EndIf

Open in new window

Quite simply:
DistanceVar = tempArray(tempArray.Length - 2)
RateVar = tempArray(tempArray.Length - 1)

Open in new window

This of course assumes that tempArray.Length - 2 and tempArray.Length - 1 are both valid indices.

-saige-
It_Sage,

What do you mean?
Say tempArray has a length of 1, tempArray.Length - 1 = 0, where as tempArray.Length - 2 = -1.  -1 is an invalid index.

-saige-