Solved

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

Posted on 2007-09-30
300 Views
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

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
Question by:qsykes

LVL 22

Accepted Solution

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:
mTotalBooks = mTotalBooks + numBooks

add the VB version of this:

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

Please close this wuestion. This is not the right solution.
0

## Featured Post

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …