Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21843

Runtime Error 340 - Control Array Element "0" does not exist

$
0
0
I am getting Runtime Error 340- Control Array Element "0) does not exist, while executing the VB6 code for Sample Statistics.

Attachment 93487

I have created 5 labels "Random Data Sample", "Average", "Standard Deviation", "DataMin" and "DataMax" with Index property as 1, 0, 1,2, 3 respectively and also created 5 list boxes i.e. List1, List2, List3, List4 and List5 respectively for the above labels with the code as under :
Function ArrayStats(DataArray() As Double) As Double()[/COLOR]
Dim Res(4) As Double
Sum = 0
SumSquares = 0
DCount = 0
DataMin = 999999
DataMax = 999999
For i = LBound(DataArray) To UBound(DataArray)
Sum = Sum + DataArray(i)
SumSquares = SumSquares + DataArray(i) ^ 2
If DataArray(i) > DataMax Then DataMax = DataArray(i)
If DataArray(i) < DataMin Then DataMin = DataArray(i)
DCount = DCount + 1
Next
Avg = Sum / DCount
StdDev = Sqr(SumSquares / DCount - Avg ^ 2)
Res(1) = Avg
Res(2) = StdDev
Res(3) = DataMin
Res(4) = DataMax
ArrayStats = Res()
End Function

Private Sub Command1_Click()
Dim SData(100) As Double
Dim Stats() As Double

List1.Clear
For i = 1 To 100
SData(i) = Rnd() * 10000
List1.AddItem SData(i)
Next
Stats() = ArrayStats(SData())
For i = 1 To 4
lblSTATS(i - 1).Caption = Stats(i)
Next
End Sub
Pl. help in resolving the problem.
Attached Images
 

Viewing all articles
Browse latest Browse all 21843

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>