[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

display the average number of books read for all readers in a session

Posted on 2007-09-30
2
Medium Priority
?
310 Views
Last Modified: 2008-03-06
I am trying to display the average number of books read for all readers in a session
*The average should be displayed in the summary*

This is how my code reads:

rivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub PointsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PointsToolStripMenuItem.TextChanged

        BonusPointsTextBox.Text = calcPoints(PointsToolStripMenuItem.Text)
    End Sub

    Private Function calcPoints(ByVal input As String) As Integer
        Dim points As Integer

        Try
            Dim numBooks As Integer = Integer.Parse(input)

            If numBooks <= 3 Then
                points = numBooks * 10
            Else
                points = 3 * 10
                If numBooks <= 6 Then
                    points = points + (numBooks - 3) * 15
                Else
                    points = points + (3 * 15)
                    points = points + (numBooks - 6) * 20
                End If
            End If
        Catch ex As Exception
        End Try

        Return points
    End Function
    Friend WithEvents AverageLabel As System.Windows.Forms.Label
    Friend WithEvents AverageTextBox As System.Windows.Forms.TextBox

    Private Sub SummaryToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SummaryToolStripMenuItem.Click

    End Sub
End Class
0
Comment
Question by:qsykes
2 Comments
 
LVL 22

Accepted Solution

by:
JimBrandley earned 1500 total points
ID: 19988475
I'm not a VB programmer, but this algorithm will do what you want.
1. Add two new member variable to the form, or the class that contains your event handlers. Call them mReaders and mTotalBooks, and initialize both to zero.

2. Inside calcPoints, add this just before you return points:
  mReaders = mReaders + 1
  mTotalBooks = mTotalBooks + numBooks

3. In PointsToolStripMenuItem_Click, after
BonusPointsTextBox.Text = calcPoints(PointsToolStripMenuItem.Text)

add the VB version of this:
 AverageTextBox.Text = ((double)mTotalBooks / (double)mReaders).ToString();

where (double) is the C# cast operator that converts a numeric value to a double precision floating point operator. You may need to use a format string to limit the precision of the result string.

Jim
0
 

Author Comment

by:qsykes
ID: 19990980
Please close this wuestion. This is not the right solution.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

873 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