Solved

Need help creating a Function

Posted on 2002-03-19
4
143 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:Gmoney
  • 2
4 Comments
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6881730
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
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6881731
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
 
LVL 1

Accepted Solution

by:
samsonite1023 earned 125 total points
ID: 6881788
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
 
LVL 6

Expert Comment

by:sharmon
ID: 6881842
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access Object Property from VBA Module in Excel 2010 2 39
VB6 - Convert HH:MM into Decimal 8 70
Visual Studio 2005 text editor 10 48
Help me. 3 69
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question