Results 1 to 15 of 15

Thread: Loops and lists

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Loops and lists

    I have to creat a loop and a list with the following information and can not figure out the codes for the life of me. Can anyone help me out?
    Requirements Document
    Date submitted: August 23,2012
    Application title: The Next Decade Pay Calculator
    Purpose: This Windows application computes the amount of money an employee earns over the
    next decade based on a raise,which is a percentage amount.
    Program In a Windows application,the user enters the present wage per hour and the raise
    Procedures: percentage amount per year to compute the yearly pay over the next 10 years.
    Algorithms, 1. The application opens displaying a title and requesting the amount of present pay per
    Processing,and hour and the expected raise percentage per year.
    Conditions: 2. When the Calculate Pay button is clicked,the program calculates the yearly pay based
    on 40 hours per week and 52 weeks per year.The raise increases each amount after the
    first year.
    3. The yearly amount of pay earned is displayed for the next 10 years.
    4. A File menu contains a Clear and an Exit option.The Clear menu item clears the re-
    sult.The Exit menu item closes the application.
    Notes and 1. Non-numeric values should not be accepted.
    Restrictions: 2. Negative numbers should not be allowed.
    Comments: 1. The application allows decimal entries.

    -I can send what I already have to someone if they think they can easily fix my mistakes. I think my whole problem is coming up with a formula that makes the list calculate the yearly income by adding the pay every year and the raise percentage. Thanks so much.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Loops and lists


    This looks like school work so you should do most of it by yourself but if you let us know what specific problem(s) you are having we'll try to help. You can copy/paste code to show us where the problem is or you can use the Manage Attachments button in the frame below to attach a zip file.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Loops and lists

    It is school work ! I have done the whole outline and everything I just can't seem to figure out where my problem is. When i try and debug the program it freezes and doesn't work. I think I am missing something in my dectotalpay function. Here is the attachment, any hints or advice would help. Thanks for the reply!
    Attached Files Attached Files

  4. #4

  5. #5
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Loops and lists

    Most people aren't going to be too keen to download a ZIP file, extract the project, open it in VS, then trawl through it to work out what's relevant. If you want answers then you should do as much as you can to make it as easy as you can for us to provide them. Post ALL the relevant code and ONLY the relevant code directly in your post, wrapped in [CODE] tags for formatting. Tell us EXACTLY what the problem is, provide any error messages that you receive and point out EXACTLY where they occur. If you make that effort then more people will be likely to make the effort to help you.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  6. #6
    Lively Member
    Join Date
    Oct 2007
    Location
    Upper Midwest
    Posts
    123

    Re: Loops and lists

    To get you started, you have a loop that continues to run unless you click the strCancel button. I commented the loop in your code and it appears to fix the endless running of the application. See the loop I commented below. Once I commented the loop, the program listed the ten years.

    Code:
    Private Sub btnCalculatePay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculatePay.Click
            'The btnCalculatePay click event calculates the yearly pay 
            'based on 40 hours per week and 52 weeks per year. The raise 
            'increases each amount after the first year.
    
            'Declare and initialize the variables.
    
    
            Dim strEnterPay As String = Me.txtEnterPay.Text
            Dim decEnterPay As Decimal
            Dim strEnterRaise As String = Me.txtEnterRaise.Text
            Dim decEnterRaise As Decimal
            Dim strTotalPay As String
            Dim decTotalPay As Decimal = CDec(CStr(decEnterPay * 40 * 52 * decEnterRaise))
            Dim intYears As Integer = 10
            Dim strNormalBoxMessage As String = "Enter the present pay and expected raise"
            Dim strNonNumericErrorMessage As String = "Error - Enter a number for the present pay and expected raise"
            Dim strNegativeNumberErrorMessage As String = "Error - Enter a positive #"
    
            'Declare and initialize loop variables.
    
            Dim strCancelButtonClicked As String = ""
            
    
            For intYears = 1 To 10
    
    
                decTotalPay = (decEnterPay * decEnterRaise)
                Me.lstYearlyPay.Items.Add("year" & intYears & "Total Pay" & _
                decTotalPay)
            Next
    
    
            'The loop allows the user's present pay and expected raise
            'to be calulated to estimate their pay for the next ten years.
            'The loop terminates when it has calculated ten years
            'or the user clicks the Cancel button.
    
    
    
            strTotalPay = CStr(decTotalPay)
    
            'Do Until intYears = 10 _
            '            Or strTotalPay = strCancelButtonClicked
    
            'Loop
    
            If IsNumeric(decEnterPay) Then
                decEnterPay = Convert.ToDecimal(decEnterPay)
    
            End If
            If IsNumeric(decEnterRaise) Then
                decEnterRaise = Convert.ToDecimal(decEnterRaise)
            End If
    
            If decEnterPay > 0 Then
                Me.lstYearlyPay.Items.Add(decTotalPay + intYears)
                decTotalPay += decEnterPay * decEnterRaise
                intYears += 1
                strEnterPay = strNormalBoxMessage
            End If
            If decEnterPay < 0 Then
                strEnterPay = strNegativeNumberErrorMessage
            End If
            If decEnterPay < 0 Then
                strEnterPay = strNonNumericErrorMessage
            End If
    
            If decEnterRaise > 0 Then
                Me.lstYearlyPay.Items.Add(decTotalPay + intYears)
                decTotalPay += decEnterPay * decEnterRaise
                intYears += 1
                strEnterRaise = strNormalBoxMessage
            End If
            If decEnterRaise < 0 Then
                strEnterRaise = strNegativeNumberErrorMessage
    
            End If
            If decEnterRaise < 0 Then
                strEnterRaise = strNonNumericErrorMessage
    
            End If
    
    
    
            'Makes List visible
            Me.lstYearlyPay.Visible = True
    
            'Calculates and displays ten years of pay
            If intYears > 1 Then
                decTotalPay = decEnterPay * 2080 * decEnterRaise
                Me.lstYearlyPay.Text = "Pay for the next ten years is " & _
                    decTotalPay.ToString("C0")
            Else
                Me.lstYearlyPay.Text = "No Pay or Raise entered"
            End If
    
            'Disables the Enter Pay and Enter Raise buttons.
            Me.txtEnterPay.Enabled = False
            Me.txtEnterRaise.Enabled = False
    
    
    
        End Sub

  7. #7
    Lively Member
    Join Date
    Oct 2007
    Location
    Upper Midwest
    Posts
    123

    Re: Loops and lists

    Ashley,

    Here is a new and improved app. I created a function called GetAnnualPayIncrease. The function requires two parameters: AnnualPay and Rate. See code below:

    Code:
    Ashley,
    
    Here is a new and improved app. I created a function called GetAnnualPayIncrease. The function requires two parameters: AnnualPay and Rate. See code below:
    
    Dim HourlyPay As Integer = CInt(txtEnterPay.Text)
    Dim Rate As Decimal = CDec(txtEnterRaise.Text)
    Dim annualSalary As Decimal = ((HourlyPay * 40) * 52)
    
    For yearNumber As Integer = 1 To 10
                If yearNumber = 1 Then
                    Me.lstYearlyPay.Items.Add("Year 1: " & annualSalary.ToString("C"))
                Else
                    annualSalary += GetAnnualPayIncrease(annualSalary, Rate)
                    Me.lstYearlyPay.Items.Add("Year " & yearNumber & ": " & annualSalary.ToString("C"))
                End If
    Next
    
    Private Function GetAnnualPayIncrease(ByVal AnnualPay As Decimal, ByVal Rate As Decimal) As Decimal
            Dim salaryIncrease As Decimal = AnnualPay * (Rate / 100)
            Return salaryIncrease
    End Function
    You will see I made a loop that calls the function 10 times...hence a decade.

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Loops and lists

    Tealmad, maybe you shouldn't do other people's homework for them. Suggestions on how they can write the code for themselves is more appropriate.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  9. #9
    Lively Member
    Join Date
    Oct 2007
    Location
    Upper Midwest
    Posts
    123

    Re: Loops and lists

    New_paycalculator_chap6vb_ashleycarter.zip

    Here is the new app...If you have any questions, let me know.

  10. #10
    Lively Member
    Join Date
    Oct 2007
    Location
    Upper Midwest
    Posts
    123

    Re: Loops and lists

    Quote Originally Posted by jmcilhinney View Post
    Tealmad, maybe you shouldn't do other people's homework for them. Suggestions on how they can write the code for themselves is more appropriate.
    I agree...However, she did have code in her app that worked. She had one too many loops in her code. Not to mention that I remember being new to application development and staying awake for hours on end trying to think.

    One thing that I have learned over the past couple of years is people learn by example.

    On the other hand, I do know people tend to absorb more by doing the work themselves. But, a little shove wouldn't hurt.

    Thanks for your feedback.

  11. #11

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Loops and lists

    Thank you so much, that makes soooo much more sense. The only other problem I still keep having with all my applications is that I get a Z in front a the number. For example, when I run the application it will say Year 1: Z$10,000. I've had this problem on all my other programs and my instructor says he doesn't know what it could be. Any ideas? Thanks again for all your help and expertise, it's sincerely appreciation.

  12. #12
    Lively Member
    Join Date
    Oct 2007
    Location
    Upper Midwest
    Posts
    123

    Re: Loops and lists

    Ashley, this sounds like it may have something to do with your Operating system maybe? What is the currency settings for your PC? From what I can tell, it may be set to Zimbabwe instead of US currency settings? Just a thought....

    Other than that, I would have to research a bit more.

  13. #13
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Loops and lists

    I would look at the regional settings, too. What you are seeing looks like a simple trick that people play on others. If the regional settings are set to the right things, the computer works the way people expect....most of the time, but not always.
    My usual boring signature: Nothing

  14. #14

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    4

    Re: Loops and lists

    Thanks a lot for all the help! You were right, my PC currency settings weren't set to English (United States). I was able to change them and now it all works perfectly! Thank you again.

  15. #15
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Loops and lists

    Now that we've helped you, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that easily by pulling down the Thread Tools menu and selecting the Mark Thread Resolved item. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help.

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