Link to home
Start Free TrialLog in
Avatar of thimss2
thimss2

asked on

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
Avatar of Dabas
Dabas
Flag of Australia image

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
Avatar of thimss2
thimss2

ASKER

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
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
Avatar of thimss2

ASKER

Yes that is what I am trying to do.

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

Dabas
Avatar of thimss2

ASKER

My knowledge of classes is very limited. I am a beginner. I know how to create a new class.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Dabas
Dabas
Flag of Australia 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