Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

populating new array from an old one

snooglets7snooglets7 Member Posts: 5
Aloha,

I am trying to do what was suggested to me and use a new array: beargArr(), and populate with values from another array arrSurvey(i,0) that conform to a value of arrSurvey(i,1)...I can't get it to work! Also...does anyone know how to reuse a button that calls a procedure. Everytime I clear all the fields etc then enter required input and press teh button...the output values are NaN!..

[color=Red]'Find the number of elements needed in the new array[/color]
j = 0
Call sortArrBearg()
For i = arrSurvey.GetUpperBound(0) - 1 To 0
If arrSurvey(i, 1) <= limDist Then
j = j + 1
ElseIf arrSurvey(i, 1) > limDist Then
j = j
End If
Next i

[color=Red]'set the array size[/color]
intCount = j - 1
ReDim beargArr(intCount)

[color=Red]'populate the new array[/color]

For i = arrSurvey.GetLength(1) - 1 To 0
If arrSurvey(i, 1) < limDist Then
For j = 0 To intCount
beargArr(j) = arrSurvey(i, 1)
Next j
End If
Next i
[color=Red]
'sort the new array[/color]
Dim maxIndex As Integer 'j, i = counter , maxIndex = element where maximum value is held, max = maximum element value, intTemp = temporary integer
Dim max, dblTemp As Double

Try

For i = (beargArr.Length - 1) To 1 Step -1 ' reverse loop cycle
max = beargArr(0)
maxIndex = 0
For j = 1 To i
If (beargArr(j) > max) Then
max = beargArr(j) 'find biggest value
maxIndex = j
End If
Next j

dblTemp = beargArr(i) 'swap values
beargArr(i) = beargArr(maxIndex)
beargArr(maxIndex) = dblTemp
Next i

Catch ex As Exception
End Try

[color=Red]'get the min and max values of the new array[/color]

For i = (arrSurvey.GetUpperBound(0) - 1) To 0
If arrSurvey(i, 1) <= limDist Then
For j = 0 To (beargArr.Length - 1)
beargArr(j) = arrSurvey(i, 0)
Next j
End If
Next i

i = beargArr.Length - 1
minBearg = beargArr(0)
maxBearg = beargArr(i)

Thanks in advance!

K

Comments

  • BitByBit_ThorBitByBit_Thor Member Posts: 2,444
    I think I see the problem:

    [code]
    [color=Green]'populate the new array[/color]
    For i = arrSurvey.GetLength(1) - 1 To 0 [color=Blue]Step -1[/color]
    [/code]

    Just a small thing you missed here (I saw that you did use it later on).

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.