Array - Function with no argument

How do I call a function that takes no argument and returns the average total of the array.

This is what I have come up with:

Public Function Average() as Decimal ={87.5D, 95.25D, 26.50D, 74.45D}
  Dim Average as Decimal
  Dim Number as Integer
  Dim Total as Decimal
If  Number = 0 to 3 then
   Average = Total/Number
Return Convert.ToDecimal (Total/Number)
Else
End If
End Function
thimss2Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
Hi thimss2,
Sorry, does not make sense..
Since you are not passing any arguments, Number will always be zero.
Your function probably will throw a division by zero error.


Dabas
0
thimss2Author Commented:
This the function I created. Nnow want to create an array that calls a function that takes no argument and returns the average total of the array.



Public Function Average(ByVal Total as Decimal, ByVal NumberAs Integer) As String

        If Number AndAlso Total > 0 Then
        Return Convert.ToString(Total / Number)
        Else
       Return "Error"
       End If          

      End Function

 ' procedure which passed the argument
Sub DisplayAvg(ByVal Total as Decimal, ByVal Number as Numberas Integer)
MessageBox.Show("Average  " & Average(Total, Number)
End Sub


Or Should I leave it as:
Public Function Average()
Return Convert.ToDecimal (Total/Number)


Thanks
0
DabasCommented:
I do not understand what you mean by:

"an array that calls a function"

What you MIGHT be talking about is creating a new class, that consists of an array or a collection and returns the average.

Dabas
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

thimss2Author Commented:
Yes that is what I am trying to do.

0
DabasCommented:
thimss2,
OK! Before I get into this, I need to know how much you know about classes if at all

Dabas
0
thimss2Author Commented:
My knowledge of classes is very limited. I am a beginner. I know how to create a new class.

Thanks
0
DabasCommented:
thimss2,
Lets take it one step at a time.

Create a new class as follows:

Public Class cMyArray
    Dim myArray() As Integer
    Private mNumberofItems As Integer = 0
    Public Sub AddToArray(ByVal NewNumber As Integer)
        ReDim Preserve myArray(mNumberofItems)
        myArray(mNumberofItems) = NewNumber
        mNumberofItems += 1
    End Sub
End Class

This is just the first step, but it has to be clear to you before we continue.
See if you can continue by yourself first, before you ask for the next step, and show me what you have tried.

Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.