[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 325
  • Last Modified:

error in function procedures, calculating average, handicap, and series total, and finding high game

In this VS Code I am having a problem seperating the function procedures, calculating the average, handicap, and series total, and finding the high game.

Public Class bowlingForm

    Private Function FindAverage(ByVal score1Integer As Integer, ByVal score2Integer As Integer, ByVal score3Integer As Integer) As Decimal
        'Return the average of three games.

        Return (score1Integer + score2Integer + score3Integer) / 3D
    End Function

    Private Function FindHandicap(ByVal averageDecimal As Decimal) As Decimal
        'Calculate the handicap.

        Return (200D - averageDecimal) * 0.8D
    End Function
    Private Function FindSeries(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As Integer
        'Calculate the series total.

        Return game1Integer + game2Integer + game3Integer
    End Function
    Private Function FindHighGame(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As String
        'Find the highest gane in the series.

        If game1Integer > game2Integer And game1Integer > game3Integer Then
            Return "1"
        ElseIf game2Integer > game1Integer And game2Integer > game3Integer Then
            Return "2"
        ElseIf game3Integer > game1Integer And game3Integer > game2Integer Then
            Return "3"
        Else
            Return "Tie"
        End If
    End Function

    Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
        'Calculate individual and summary info.

        Dim averageDecimal, handicapDecimal As Decimal
        Dim seriesInteger, game1Integer, game2Integer, game3Integer As Integer
        Dim highGameString As String
        Try
            With Me
                game1Integer = Integer.Parse(.score1TextBox.Text)
                game2Integer = Integer.Parse(.score2TextBox.Text)
                game3Integer = Integer.Parse(.score3TextBox.Text)

                'Perform all calculations.
                averageDecimal = FindAverage(game1Integer, game2Integer, game3Integer)
                seriesInteger = FindSeries(game1Integer, game2Integer, game3Integer)
                highGameString = FindHighGame(game1Integer, game2Integer, game3Integer)
                handicapDecimal = FindHandicap(averageDecimal)

                'Format the output.
                .averageTextBox.Text = averageDecimal.ToString("N1")
                .highGameTextBox.Text = highGameString
                .seriesTextBox.Text = seriesInteger.ToString()
                .handicapTextBox.Text = handicapDecimal.ToString("N1")
            End With
        Catch
            MessageBox.Show("Please Enter three numeric scores", "Missing Data", MessageBoxButtons.OK)
        End Try
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'Terminate the project.

        Me.Close()
    End Sub
    Private Sub ClearToolStripMenuitem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        With Me
            With .nameTextBox
                .Clear()
                .Focus()
            End With
            .maleRadioButton.Checked = False
            .femaleRadioButton.Checked = False
            .scoreaverageTextBox.Clear()
            .scorehandicapTextBox.Clear()
            .scorehighGameTextBox.Clear()
            .seriesTextBox.Clear()
            .averageTextBox.Clear()
            .highGameTextBox.Clear()
            .handicapTextBox.Clear()
        End With
    End Sub
End Class


Here is a list of my errors:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
'score1TextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'score2TextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'score3TextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'averageTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'highGameTextBox' is not a member of 'WindowsApplication1.bowlingForm'
'seriesTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'handicapTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
'Close' is not a member of 'WindowsApplication1.bowlingForm'.
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
'nameTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'maleRadioButton' is not a member of 'WindowsApplication1.bowlingForm'.
'femaleRadioButton' is not a member of 'WindowsApplication1.bowlingForm'.
'scoreaverageTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'scorehandicapTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'scorehighGameTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'seriesTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'averageTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'highGameTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
'handicapTextBox' is not a member of 'WindowsApplication1.bowlingForm'.
0
qsykes
Asked:
qsykes
  • 6
  • 4
3 Solutions
 
SanclerCommented:
This looks like VB.NET 2005.  In that, each form has two files.  They are to be found in the project directory.  If everything is OK, you should also be able to see both of them in the Solution Explorer window (on the right of the screen in the VB IDE default layout) if you click the button (at the top of that window) for "Show all files".

The one you show is the code file: its name should be something like bowlingform.vb.  There should be another one - with a name something like bowlingform.designer.vb - which contains designer-generated code for the display content of the form: all the textboxes, etc.  VB generates that as you drag controls onto the form, position them, change their sizes, shapes, colors, etc.  Internally (if it exists, you can have a look inside it by opening it with Notepad) that second file should start

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class bowlingform
    Inherits System.Windows.Forms.Form

The error messages you are reporting suggest that that second file is missing, or corrupted, or that its link with the code file had been broken because its name internally - that is, bowlingform - is different from that in the code file.

So, does it exist?  If so, how does it start?

Roger
0
 
qsykesAuthor Commented:
In my book it was told to type in the code as stated above, It does not have a designer vb. Al l I was told to do was seperate the function procedures, calculating the average, handicap, and series total, and finding the high game.
0
 
Jai STech ArchCommented:
Normally there are two parts for a form - one is user CODE and another is your designer code...whenever you place a control on your form a designer code is generated and it is stored in a file <yourformanme>.designer.cs...
this is not ideal though...you can have your designer in one form as like in vs2003....which will be in the INITIALIZE component event...and is called in the constructor...
try placeing a CONTROL in your form in the design view...

check you book it would probably say "place these controls " - if it doesnt...then the book knows that its OBVIOUS...
0
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.

 
SanclerCommented:
Open VB.  Click on File on the menu bar at the top.  Click on New Project on the dropdown that appears.  Select (or accept) Windows Application on the dialog window that then appears.  A blank form (called Form1) should then appear.  

There should be a toolbox (probably down the left hand side of the screen): if it's not there click View on the menu at the top, then Toolbox in the dropdown that appears.  In the Toolbox click on TextBox.  Move your mouse over the blank form.  Click where you want the top left of the textbox to appear then, keeping the button down, move the mouse to where you want the bottom right of the textbox to be.  A textbox should now be shown on the form.  Its properties should be shown in the properties pane (probably bottom right of the screen).  Go to the properteis pane, find the property Name, and alter it from TextBox1 to score1TextBox.

Repeat that step for every one of the textboxes that appear in the error list from your first post.  And do similar, with radiobuttons, for the two radiobuttons that are mentioned.  You can reposition and resize the various controls (and the form itself) by dragging and dropping with the mouse.  You might also want to drag and drop and set the text properties of labels, so that the user will know which textbox is which.

When you've done all that, click in the Solution Explorer window near the top on the button for View Code.  The screen will then show a the code file which, at the moment, will just contain

Public Class Form1

End Class

Copy all the code from your first post - except the lines at the beginning and end, saying "Public Class bowlingForm" and "End Class" - and paste them into that file between the existing lines.

Now try to run the project.  If it doesn't work, post the error message/s back here.

Roger
0
 
qsykesAuthor Commented:
Ok I have completed the form and I have 3 errors left and they say:
Handles clause requires a WithEvents variable defined in the containing type or one of its base types.
This comes up 3 times.

This error is in reference to CalcualteToolStripMenuItem.Click
ExitToolStripMenuItem.Click
ClearToolStripMenuItem.Click


Here is how the code looks.

'Project:           Chapter 5 Bowling Example
'Programmer:        Qiana S. Sykes
'Date:              September 16, 2007
'Folder:            Ch05Bowling
'Description:       This project calculates bowling statistics using multiple function procedures.

Public Class bowlingForm

    Private Function FindAverage(ByVal score1Integer As Integer, ByVal score2Integer As Integer, ByVal score3Integer As Integer) As Decimal
        'Return the average of three games.

        Return (score1Integer + score2Integer + score3Integer) / 3D
    End Function

    Private Function FindHandicap(ByVal averageDecimal As Decimal) As Decimal
        'Calculate the handicap.

        Return (200D - averageDecimal) * 0.8D
    End Function
    Private Function FindSeries(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As Integer
        'Calculate the series total.

        Return game1Integer + game2Integer + game3Integer
    End Function
    Private Function FindHighGame(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As String
        'Find the highest gane in the series.

        If game1Integer > game2Integer And game1Integer > game3Integer Then
            Return "1"
        ElseIf game2Integer > game1Integer And game2Integer > game3Integer Then
            Return "2"
        ElseIf game3Integer > game1Integer And game3Integer > game2Integer Then
            Return "3"
        Else
            Return "Tie"
        End If
    End Function

    Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
        'Calculate individual and summary info.

        Dim averageDecimal, handicapDecimal As Decimal
        Dim seriesInteger, game1Integer, game2Integer, game3Integer As Integer
        Dim highGameString As String
        Try
            With Me
                game1Integer = Integer.Parse(.score1TextBox.Text)
                game2Integer = Integer.Parse(.score2TextBox.Text)
                game3Integer = Integer.Parse(.score3TextBox.Text)

                'Perform all calculations.
                averageDecimal = FindAverage(game1Integer, game2Integer, game3Integer)
                seriesInteger = FindSeries(game1Integer, game2Integer, game3Integer)
                highGameString = FindHighGame(game1Integer, game2Integer, game3Integer)
                handicapDecimal = FindHandicap(averageDecimal)

                'Format the output.
                .averageTextBox.Text = averageDecimal.ToString("N1")
                .highGameTextBox.Text = highGameString
                .seriesTextBox.Text = seriesInteger.ToString()
                .handicapTextBox.Text = handicapDecimal.ToString("N1")
            End With
        Catch
            MessageBox.Show("Please Enter three numeric scores", "Missing Data", MessageBoxButtons.OK)
        End Try
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'Terminate the project.

        Me.Close()
    End Sub
    Private Sub ClearToolStripMenuitem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        With Me
            With .nameTextBox
                .Clear()
                .Focus()
            End With
            .maleRadioButton.Checked = False
            .femaleRadioButton.Checked = False
            .scoreaverageTextBox.Clear()
            .scorehandicapTextBox.Clear()
            .scorehighGameTextBox.Clear()
            .seriesTextBox.Clear()
            .averageTextBox.Clear()
            .highGameTextBox.Clear()
            .handicapTextBox.Clear()
        End With
    End Sub
End Class




0
 
SanclerCommented:
Sorry, I missed those refrences in the original code you posted.  You need to add a menu strip.  You can drag it from the toolbox onto the form.  It will sit at the top.  There will be a box at its top left saying "Type Here".  Click on it.  It will become editable, and two more similar boxes will appear: one under it and one to its right.  Type Exit in the first box.  Then click in the one on the right and type Calculate in that.  Then click in the new box that has appeared on the right of that and type Clear in that.

It may work OK just doing that.

If it doesn't, re-paste the code from your original post (excluding the first and last lines) to replace all the code (except the first and last lines) now in the code file.  And try again.

If it still doesn't, come back with the error messages that are now showing.

Roger
0
 
qsykesAuthor Commented:
I have all the errors completed but I am still having a problem calcualting the average, handicap, and series total, and finding the high game. And none of my controls on my run screen do not work.

'Project:           Chapter 5 Bowling Example
'Programmer:        Qiana S. Sykes
'Date:              September 16, 2007
'Folder:            Ch05Bowling
'Description:       This project calculates bowling statistics using multiple function procedures.

Public Class bowlingForm

    Private Function FindAverage(ByVal score1Integer As Integer, ByVal score2Integer As Integer, ByVal score3Integer As Integer) As Decimal
        'Return the average of three games.

        Return (score1Integer + score2Integer + score3Integer) / 3D
    End Function

    Private Function FindHandicap(ByVal averageDecimal As Decimal) As Decimal
        'Calculate the handicap.

        Return (200D - averageDecimal) * 0.8D
    End Function
    Private Function FindSeries(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As Integer
        'Calculate the series total.

        Return game1Integer + game2Integer + game3Integer
    End Function
    Private Function FindHighGame(ByVal game1Integer As Integer, ByVal game2Integer As Integer, ByVal game3Integer As Integer) As String
        'Find the highest gane in the series.

        If game1Integer > game2Integer And game1Integer > game3Integer Then
            Return "1"
        ElseIf game2Integer > game1Integer And game2Integer > game3Integer Then
            Return "2"
        ElseIf game3Integer > game1Integer And game3Integer > game2Integer Then
            Return "3"
        Else
            Return "Tie"
        End If
    End Function

    Private Sub CalculateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CalculateToolStripMenuItem.Click
        'Calculate individual and summary info.

        Dim averageDecimal, handicapDecimal As Decimal
        Dim seriesInteger, game1Integer, game2Integer, game3Integer As Integer
        Dim highGameString As String
        Try
            With Me
                game1Integer = Integer.Parse(.score1TextBox.Text)
                game2Integer = Integer.Parse(.score2TextBox.Text)
                game3Integer = Integer.Parse(.score3TextBox.Text)

                'Perform all calculations.
                averageDecimal = FindAverage(game1Integer, game2Integer, game3Integer)
                seriesInteger = FindSeries(game1Integer, game2Integer, game3Integer)
                highGameString = FindHighGame(game1Integer, game2Integer, game3Integer)
                handicapDecimal = FindHandicap(averageDecimal)

                'Format the output.
                .averageTextBox.Text = averageDecimal.ToString("N1")
                .highGameTextBox.Text = highGameString
                .seriesTextBox.Text = seriesInteger.ToString()
                .handicapTextBox.Text = handicapDecimal.ToString("N1")
            End With
        Catch
            MessageBox.Show("Please Enter three numeric scores", "Missing Data", MessageBoxButtons.OK)
        End Try
    End Sub

    Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
        'Terminate the project.

        Me.Close()
    End Sub
    Private Sub ClearToolStripMenuitem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        With Me
            With .nameTextBox
                .Clear()
                .Focus()
            End With
            .maleRadioButton.Checked = False
            .femaleRadioButton.Checked = False
            .scoreaverageTextBox.Clear()
            .scorehandicapTextBox.Clear()
            .scorehighGameTextBox.Clear()
            .seriesTextBox.Clear()
            .averageTextBox.Clear()
            .highGameTextBox.Clear()
            .handicapTextBox.Clear()
        End With
    End Sub
End Class


0
 
qsykesAuthor Commented:
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
This is the error showing now.

I have worked with the code and three of my calcualtions are posting. The only ones that are not posting are ScoreAverage, scoreHighGame, and scorehandicap.
0
 
SanclerCommented:
There is no code anywhere in what you show to put anything in the ScoreAverage, scoreHighGame, and scorehandicap textboxes.  The last sub shows them as being cleared, but there is no code that fills them.

On what line is that error occurring?

Roger
0
 
qsykesAuthor Commented:
Thank you very much Roger for taking the time to help me. I have the code running properly.
0
 
qsykesAuthor Commented:
Thank you very much!!!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now