Q:

Finding the mean using a function. vb.net

I'd firstly like to say I'm a beginner in vb.net and coding in general.
I'm trying to find the mean of the numbers in an array.
So far, my code is this.
 Function getMean() As Double
        Dim DblArray(lstbxInput.Items.Count - 1) As Double
        Dim totalsum As Double
        Dim i As Integer
        For i = 0 To dblArray.Length - 1
            totalsum += DblArray(i)
        Next i
        dblmean = totalsum / DblArray.Length
        Return dblmean

    End Function

In the end, I need for dblmean to return the mean value of the dblarray numbers. 
Would this be correct?
Well obviously it's wrong because I tried to print the value on a label and it always comes out as zero. Why?
Is there something wrong with the code? or was there something wrong in printing out the value?
Also, this is the code used to print out dblmean
lblLrgAns.Text = dblmean.ToString
it happens when i click a button. 

A:

When you do this
Dim DblArray(lstbxInput.Items.Count - 1) As Double

All of DblArray items are 0, but you never change any of the DblArray items in your code, so dblmean would also be 0. You need to assign each item of DblArray before calculating the mean.
I would guess this is related to your previous question: putting a list into an array?, so here's how your code should look like
Function getMean() As Double
    Dim DblArray(lstbxInput.Items.Count - 1) As Double

    'get the items from lstbxInput
    getNumbers(DblArray)

    Dim totalsum As Double
    Dim i As Integer
    For i = 0 To dblArray.Length - 1
        totalsum += DblArray(i)
    Next i
    dblmean = totalsum / DblArray.Length
    Return dblmean

End Function

