Results 1 to 8 of 8

Thread: Help with code, please?! :)

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    New York
    Posts
    4

    Help with code, please?! :)

    Hi everyone! I'm new to this forum and to Visual Basic. I don't know much about the language let alone any other language for that matter, but I'm learning. I'm taking this class and we have our 4th and final assignment due on Tuesday and I'm looking to see if anyone can give any insight to see what I'm doing wrong. I'm not asking anyone to do my homework for me, I have my code written out and my programs seem to run fine, but in the end i'm not getting the numbers I should... this is what I mean.

    We have to calculate the Net Pay of an employee of a company (Jackson's Jelly Beans, don't ask, it's what the professor used) LOL
    And anyway, the way she has us do this is by having 2 input boxes: 1 for number of hours worked, and 2 for hourly rate
    Gross Pay is calculated as Number of Hours Worked multiplied by Hourly Rate
    and
    Payroll Tax is calculated as follows: (and we have a chart)

    Gross Pay Payroll Tax
    Less than 100 0
    $100 - $400.99 4% of Gross Pay greater than $100
    $401 - $700.99 $10 plus 6% of Gross Pay greater than $400
    More than $701 $28 plus 8% of Gross Pay greater than $700

    and then she tells us that Net pay is calculated as Gross Pay minus Payroll Tax (I think this is where I go wrong)

    My code so far is:

    Option Explicit
    Public Const ApplicationTitle = "Jackson's Jelly Beans"
    Public Sub Assignment4()

    Dim intHours As Integer
    Dim intRate As Integer
    Dim curGross As Currency
    Dim intTax As Integer

    intHours = InputBox("Enter Number of Hours Worked", ApplicationTitle, Default:=0)

    intRate = InputBox("Enter Hourly Rate", ApplicationTitle, Default:=0)

    CurGross = intHours * intRate

    Select Case curGross

    Case Is <= 100
    intTax = 0
    Case Is <= 400.99
    intTax = 0.04 * curGross
    Case Is <= 700.99
    intTax = 10 + 0.06 * curGross
    Case Else
    intTax = 28 + 0.08 * curGross
    End Select

    MsgBox "Net Pay =" & FormatCurrency(curGross)

    End Sub

    ...so again if anyone can maybe just guide me or point out to me what you think I did wrong. We get some values to try to input into our program to see if we did it right, and although my numbers come up close they don't match, so I know I'm right on the edge of this somewhere. I would love any help I can get. Thank you so much!!!!
    ~Jill

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Help with code, please?! :)

    Welcome to the forums!
    It's usually a little bit busier around here. When things are slow, you may want to post in the Classic Forum. Back to your program:

    You need to subtract the tax!

    VB Code:
    1. MsgBox "Net Pay =" & FormatCurrency(curGross - intTax )

    and use Code Tags in the future, so it's easy to read:
    VB Code:
    1. Option Explicit
    2. Public Sub form_load() ' Assignment4()
    3. Const ApplicationTitle = "Jackson's Jelly Beans"
    4.  
    5. Dim intHours As Integer
    6. Dim intRate As Integer
    7. Dim curGross As Currency
    8. Dim intTax As Currency
    9.  
    10. intHours = InputBox("Enter Number of Hours Worked", ApplicationTitle, Default:=0)
    11.  
    12. intRate = InputBox("Enter Hourly Rate", ApplicationTitle, Default:=0)
    13.  
    14. curGross = intHours * intRate
    15.  
    16. Select Case curGross
    17. Case Is < 100
    18.   intTax = 0
    19. Case 100 To 400.99
    20.   intTax = 0.04 * (curGross - 100)
    21. Case 401 To 700.99
    22.   intTax = 10 + (0.06 * (curGross - 400))
    23. Case Else
    24.   intTax = 28 + (0.08 * (curGross - 700))
    25. End Select
    26.  
    27. MsgBox "Net Pay =" & FormatCurrency(curGross - intTax)
    28.  
    29. End Sub
    Last edited by dglienna; May 1st, 2005 at 11:19 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2005
    Location
    New York
    Posts
    4

    Re: Help with code, please?! :)

    Thanks for the tip! I'll remember to post Classic Forum that's probably where most of the users here are anyway, I should've figured. But Thank you so much for helping me out!! You're the best!

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Help with code, please?! :)

    I've made a few changes to correct the numbers. Enjoy!

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help with code, please?! :)

    Beaner, the VBA Forum is for questions concerning code dealing with MS Office suite programs and other programs
    that also support VBA. VBA is similar to VB but its dependant on Office, usually.

    If you are using VB5 or VB6 then the Classic VB Forum is the correct place to post this type of question.

    Just a little help on determining where to post future questions. Dont wory if your still unsure, post it and it will get moved
    to its appropriate forum.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: Help with code, please?! :)

    Did the reply from dglienna help?
    I suppose the numbers are still not correct.
    I was said that:
    Gross Pay Payroll Tax
    Less than 100 0
    $100 - $400.99 4% of Gross Pay greater than $100
    $401 - $700.99 $10 plus 6% of Gross Pay greater than $400
    More than $701 $28 plus 8% of Gross Pay greater than $700
    I understand it that way:

    Gross Pay 0 to 99,99 0 Tax
    Gross Pay 100 to 400,99 Tax 0,04*(GrossPay-100)
    Gross Pay 401 to 700,99 Tax 10+0,06*(GrossPay-400)
    Gross Pay more than 701 Tax 28+0,08*(GrossPay-700)
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Help with code, please?! :)

    fixed that, too.

    I was looking at the numbers first, and fixed the range. Assumed that the calcs were right, until I heard otherwise. Also, the web page should have been given, which would have given me correct numbers to test it, which I would have done.
    No problem, though. It's done now, in VBF.

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Help with code, please?! :)

    Did you notice it was a school assignment?
    So I suppose you get an 'A', dgleinna.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

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