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
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
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
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
"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
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
OK! Before I get into this, I need to know how much you know about classes if at all
Dabas
ASKER
My knowledge of classes is very limited. I am a beginner. I know how to create a new class.
Thanks
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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