Results 1 to 4 of 4

Thread: VB 10 Problem with program

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    2

    VB 10 Problem with program

    Write a complete Visual Basic program to do the following:
    Joe’s Pizza Palace needs an application to calculate the number of slices
    a pizza of any size can be divided into.
    The application should do the following:
     Allow the user to enter the diameter of the pizza, in inches.
     Calculate the number of slices that can be cut from a pizza that size.
     Display a message that indicates the number of slices.
    To calculate the number of slices that can be cut from the pizza, you must know these facts:
     Each slice should have an area of 14.125 inches.
     To calculate the number of slices, divide the area of the pizza by 14.125.
     The area of the pizza is calculated with the formula: Area = π r2
    Note: The π is pi which is equal to 3.14159.The r is the radius of the pizza. Divide the diameter
    by 2 to get the radius.
    Form:
    The application should be done form-based. You may design your own form. It must have the following:
     a label indicating that it is Joe’s Pizza Palace
     a field with label to enter the size (diameter) of the pizza
     a field with label to display the number of slices
     buttons to calculate the number of slices and to exit the application
    Output:
    Use the following test data to determine if the application is calculating properly:
    Diameter of Pizza Number of Slices
    22 inches 27
    15 inches 13
    12 inches 8
    Requirements:
     Name the project Pizza.
     Be sure to include your name included in a comment
     No credit is given for a program that will not execute.
     All rules of academic integrity should be applied as stated in the syllabus.
     Submit the zipped project into Moodle.


    I have errors saying "With Held " events

    WHAT IS WRONG WITH what I HAVE
    Code:
        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles button3.Click
            ' End the application
            End
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            ' Clear the Text Box and lblSlices
            txtDiameter.Clear()
            lblSlices.Text = ""
            ' Return the focus to txtDiameter
            txtDiameter.Focus()
        End Sub
        Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
            Dim Slices As Single
            Dim Diameter As Single
            Dim radius As Single
    
            Diameter = Val(txtDiameter.Text)
            radius = Val(Diameter) \ 2
            Slices = 3.14159 * radius ^ 2 \ 14.125
            lblSlices.Text = FormatNumber(Slices, 0)
        End Sub
    
        Private Sub lblSlices_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblSlices.Click
        End Sub
    
        Private Function lblSlices() As Object
            Throw New NotImplementedException
        End Function
    
        Private Function txtDiameter() As Object
            Throw New NotImplementedException
        End Function
    
    
    End Class
    Last edited by Joacim Andersson; May 23rd, 2012 at 01:55 AM. Reason: Added code tags

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: VB 10 Problem with program

    this works:

    vb Code:
    1. Public Class Form1
    2.  
    3.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    4.         If cboDiameter.SelectedIndex > -1 Then
    5.             Dim radius As Double = CDbl(cboDiameter.Text) / 2
    6.             Dim area As Double = Math.PI * (radius ^ 2)
    7.             Dim slices As Integer = CInt(area / 14.125)
    8.             If slices * 14.125 > area Then slices -= 1
    9.             lblSlices.Text = slices.ToString
    10.         End If
    11.     End Sub
    12.  
    13. End Class

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2012
    Posts
    2

    Re: VB 10 Problem with program

    Ok I have used what you have and it says 1 error,


    Error 1 Handles clause requires a WithEvents variable defined in the containing type or one of its base types.

    What do you do with this?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,416

    Re: VB 10 Problem with program

    eventHandlers (usually) require a handles clause... i.e.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    the highlighted part is the handles clause

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width