# Need help creating a Function

I'm creating a program for a school that tracks students summer reading and gives them bonus points for each book that they read. I need help in creating the Function to calculate points in the following manner:

The first three books are worth 10 points each. The next three are worth 15 points each. And all books over six are worth 20 points each.
###### Who is Participating?

x

Commented:
Public Function PointsForBooks(numberRead as single) as single
dim tempPoints

If numberRead > 6 Then

PointsForBooks = 75 + (numberRead - 6)*20

Else

For i = 1 to numberRead
Select case i
Case 1 To 3
tempPoints = tempPoints + 10
Case 4 To 6
tempPoints = tempPoints + 15
End Select
Next i

PointsForBooks = tempPoints

EndIf

End Function

This should do it.
-Sam
0

Commented:
Hi Gmoney,

Something like this should works:

Dim points As Long

..

If rs.RecordCount > 6 Then

Points = rs.RecordCount * 20

Else

For i = 1 to rs.RecordCount

Select case i
Case 1 To 3
Points = Points + 10
Case 4 To 6
Points = Points + 20
End Select

Next i

End If
0

Commented:
Public Function myPoints(Byval RCount As Long) As Long
Dim Points As Long
If RCount > 6 Then

Points = RCount * 20

Else

For i = 1 to RCount

Select case i
Case 1 To 3
Points = Points + 10
Case 4 To 6
Points = Points + 20
End Select

Next i
myPoints = Points
End Function
0

Commented:
And yet another way...

Public Function BooksToPoints(ByVal intBooks As Integer) As Integer
If intBooks > 6 Then
BooksToPoints = 75 + ((intBooks - 6) * 20)
ElseIf intBooks > 3 Then
BooksToPoints = 30 + ((intBooks - 3) * 15)
ElseIf intBooks > 0 Then
BooksToPoints = intBooks * 10
End If
End Function
0
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.