I need to create a program which calculates the bonus points for the books read.
This program need to obtain reader name and bonus point earned.

Number of books read Points is as bellow;
First three books 10 points each
Next three books 15 points each
All books over six 20 points each

I have created an interface like attached in doc file "Reading Program.doc".

I have created the code to calculate the bonus point, refer interface "Form2", when the calculate button is clicked, below is the source code creted:

Public Function calcPoints(Booksread As Integer) As Integer
Dim Points As Integer
Dim Booksremaining As Integer

Points = 0
Booksremaining = Booksread
If Booksremaining > 0 Then
    Points = Min(Booksremaining, 3) * 10
    Booksremaining = Booksremaining - 3
End If
If Booksremaining > 0 Then
    Points = Points + Min(Booksremaining, 3) * 15
    Booksremaining = Booksremaining - 3
End If
If Booksremaining > 0 Then
    Points = Points + Booksremaining * 20
    Booksremaining = 0
End If
calcPoints = Points
End Function

Private Sub calculate_Click()
Dim Points As Integer
Text2.Text = Points
End Sub

This source code does not seems to be working as it returning zero bonus points when i click the calculate button.

Can anyone help me on this as soon!
Thank you.

/Vishal

Recommended Answers

All 2 Replies

I really do not understand your code.

Why are you using 3 different logic for the same condition
If Booksremaining > 0 Then and that to in independent IF blocks ???

This was my code from a previous post. It uses three if blocks with the same condition because each if block will alter the value of books remaining.

The problem is in the Click event, you do not call the function the line

Text2.Text = Points

should read

Text2.text = CalcPoints(val(text1.text))

You should also use the
Option Explicit

compiler directive, which requires all variables to be declared. It can be painful at compile time but it is worth it at run time.

You can have it included automatically by checking "Require Variable Declaration" in the options.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.