It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

Can't figure out what's wrong? Please Help?

Moderator: dafunkymunky

Can't figure out what's wrong? Please Help?

Postby katielynnsdad on Sun Feb 03, 2008 7:39 pm

I have been trying for 3 days now to figure out what is wrong with this code, Can anyone clue me in please?

Public Function CalcAverage(ByVal average As Decimal, ByVal total As Decimal) As Decimal


count = count + 1

'calculate average if count is greater than zero
If count > 0 Then

average = total / count

End If

Return average

End Function

Thank you very much for any help!
Last edited by katielynnsdad on Tue Feb 05, 2008 12:34 am, edited 1 time in total.
katielynnsdad
 
Posts: 4
Joined: Sun Feb 03, 2008 7:35 pm

Postby katielynnsdad on Tue Feb 05, 2008 12:31 am

Sorry! :oops:
katielynnsdad
 
Posts: 4
Joined: Sun Feb 03, 2008 7:35 pm

Postby dragul on Wed Feb 06, 2008 1:53 pm

I think the "Return average" line should be inside the if other wise its trying to do it if the calculation is being done which may be causing the fault:

'///////////////////////////////////////////////
Public Function CalcAverage(ByVal average As Decimal, ByVal total As Decimal) As Decimal

count = count + 1

'calculate average if count is greater than zero
If count > 0 Then

average = total / count

Return average

End If

End Function
'/////////////////////////////

try that
dragul
 
Posts: 16
Joined: Wed Apr 20, 2005 7:54 pm
Location: Abergavenny, Wales, UK

Postby aklwer3456 on Sat Feb 09, 2008 4:04 pm

Decimal is not VB data type. Try DOUBLE instead (if you mean floating point).

or INTEGER, if you mean whole integer,
or LONG--> same but range is bigger

And the logic of your function is not clear. What do you want to accomplish?

Public Function CalcAverage(ByVal average As Double, _
ByVal total As Double) As Double

count = count + 1
'calculate average if count is greater than zero
If count > 0 Then
average = total / count

'instead of Return average
CalcAverage= average
End If
End Function
aklwer3456
 
Posts: 6
Joined: Sat Feb 09, 2008 3:35 pm

Postby katielynnsdad on Sun Feb 10, 2008 10:12 pm

The CalcAvg() is a function returning the average rain fall to the calc button code. In the program you enter the amount of rainfall and it calculates the total rain and the average rain, every time you enter an amount.
Also, the function is supposed to be Private instead of public.
It uses 2 functions to calculate the total and the average.
Thank you all for your help!
katielynnsdad
 
Posts: 4
Joined: Sun Feb 03, 2008 7:35 pm


Who is online

Users browsing this forum: No registered users and 3 guests