Results 1 to 17 of 17

Thread: Calculation Help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Calculation Help

    I Have 7 Labels which i call them


    EnterName
    Enter number of pieces
    Average
    Money per person
    Total Pieces
    Total Amount of money
    Amount Earned



    and the rest are textBoxes all to calculate the above 7 labels to get the answers


    Eg 1. I have to enter name
    2. Number of pieces
    3. Then it will be validate the name and pieces i have give them
    Last edited by Hack; Oct 19th, 2005 at 10:16 AM.

  2. #2
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: Calculation Help

    So... what's the question, exactly?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    This has been split from this thread which was just getting way too long.

    Franklin: Please state your specific question.

    What code for this do you have so far?

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    I have done the first part which is the amount earned But the rest it does

    nothing

  5. #5
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    Quote Originally Posted by Franklin67
    I have done the first part which is the amount earned But the rest it does

    nothing
    Show us what you have done and what isn't working. Please explain what should be done to get it working that you can't figure out.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    VB Code:
    1. ]Private Sub cmdcalculate_Click()
    2. 'Determined The Amount Due
    3.  Dim intpieces         As Integer
    4.  Dim Curprice          As Currency
    5.  Dim Curamountearned   As Currency
    6.  
    7. intpieces = Val(txtpieces)
    8.  
    9. 'Validate for missing data and enable summary button after
    10.     'the first order has been entered
    11.    
    12.    
    13.   If txtname.Text = "" Then
    14.   MsgBox "Please Enter Name", vbOKOnly, "Data Entry Error"
    15.  
    16.  
    17.   txtname.SetFocus
    18.   ElseIf Not IsNumeric(txtpieces.Text) Then
    19.   MsgBox "Please Enter a Positive Number for the Piece Count", _
    20.    vbOKOnly, "Data Entry Error"
    21.    With txtpieces
    22.    .Text = " "
    23.    .SetFocus
    24.    End With
    25.    Else
    26.    
    27.    
    28.    cmdsummary.Enabled = True
    29.    ' Find person with greatest number of pieces
    30.     If intpieces > MintHighestpieces Then   'compare to current winner
    31.     MintHighestpieces = intpieces
    32.     Mstrhighname = txtname.Text
    33.     End If
    34.      
    35.    'find pay rate  
    36.  
    37.    If intpieces < 200 Then
    38.     Curprice = 0.5
    39. ElseIf intpieces < 400 Then
    40.     Curprice = 0.55
    41. ElseIf intpieces < 600 Then
    42.     Curprice = 0.6
    43. Else
    44.     Curprice = 0.65
    45. End If
    46.  
    47.   'calculate the pay
    48.     Curamountearned = intpieces * Curprice
    49.     lblamountearned.Caption = FormatCurrency(Curamountearned)
    50.    
    51.   'add to totals
    52.     mintpiecesTotal = mintpiecesTotal + intpieces
    53.     Dim mintemployeecount  As Integer
    54.     Mcurpaytotal = Mcurpaytotal + Curamountearned
    55. End If
    56. End Sub
    57.  
    58. Private Sub cmdclear_Click()
    59.  
    60.     txtname.Text = ""
    61.     txtpieces.Text = ""
    62.     lblaverage.Caption = ""
    63.     lblmoney.Caption = ""
    64.     lblpieces = ""
    65.     lbltotalmoney = ""
    66.      lblamountearned = ""
    67. End Sub
    68.  
    69. Private Sub cmdexit_Click()
    70. End
    71. End Sub
    72.  
    73. Private Sub cmdsummary_Click()
    74.     'Calculate the average and dispaly the totals
    75. Dim curaveragepay       As Currency
    76. Dim strmessage          As String
    77.  
    78. curaveragepay = Mcurpaytotal / mintemployeecount
    79. strmessage = "Total number of pieces " + mintpiecesTotal + vbCrLf + _
    80.                 "Average Pay:           " + FormatCurrency(curaveragepay) + cbCrLf + _
    81.                 "Person producing most: " + Mstrhighname & vbCrLf + _
    82.                 "   (produced " + MintHighestpieces + " pieces)"
    83. MsgBox strmessage, vbOKOnly, "Piecework Summary"
    84.  
    85. End Sub
    86.  
    87. Private Sub Form_Load()
    88.     'Initialise the variables
    89.    
    90. MintHighestpieces = -1
    91. End Sub
    92.  
    93. Private Sub Label1_Click()
    94. 'calculate the pay
    95.     Curamountearned = intpieces * Curprice
    96.     lblamountearned.Caption = FormatCurrency(Curamountearned)
    97.    
    98. End Sub
    99.  
    100. Private Sub Lblearned_Click()
    101.  
    102. End Sub
    Last edited by Hack; Oct 19th, 2005 at 11:39 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    And now here come the Biggest problem


    The 7 labels & Textboxes NOTHING WORKS
    Except for
    Amount Earned Text Box

    Average Textbox


    Money (Per Person) Textbox


    TotalPieces Textbox


    Total Of Money TextBox


    Now i Can't calculate Or Clear The Box (This Is The part Where It gets)

    (This Is The part Where It gets Messy And Confusion)

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    One problem is with this variable: Curamountearned

    It is created in the click event of your calculate button. Because it is created in that event, that event is the ONLY place you can use it.

    You are also attempting to use it in click event of your label, and that isn't going to work.

    If you need a variable to be used in more than one place on your form, you must declare it in the Form's declaration section. Then, and only then, will it be available form wide.

    Remove Dim Curamountearned As Currency from the calculate click event.

    In your Forms declaration section put:
    VB Code:
    1. Private Curamountearned As Currency
    Now, try your code.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    They are 2 Curamountearned

    It is This one you were Talking About (If This is the One i shall be moving Closer To next step


    Private Sub cmdcalculate_Click()
    'Determined The Amount Due
    Dim intpieces As Integer
    Dim Curprice As Currency
    Private Curamountearned As Currency


    Or



    'calculate the pay
    Curamountearned = intpieces * Curprice

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    Quote Originally Posted by Franklin67
    They are 2 Curamountearned

    It is This one you were Talking About (If This is the One i shall be moving Closer To next step


    Private Sub cmdcalculate_Click()
    'Determined The Amount Due
    Dim intpieces As Integer
    Dim Curprice As Currency
    Private Curamountearned As Currency 'you cant do that here!!!!!!


    Or



    'calculate the pay
    Curamountearned = intpieces * Curprice
    When you use Private, you have to declare the variable in the declarations section of your form, not a control's click event. You need to move that.

    There should only be one variable called Curamountearned. Declare it just once.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    Then Where Do I transfer it to ?

    Private Curamountearned As Currency

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    Quote Originally Posted by Franklin67
    Then Where Do I transfer it to ?

    Private Curamountearned As Currency
    You move it to the Form's declaration section.

    Open up a code window.

    In the upper left hand corner will be a drop down.

    Click on it.

    It will drop down. Scroll up to the top of the drop down and click where it says (General)

    This will take you to the Form's General Declarations section.

    Put it there.

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    Okay i've already done that

  14. #14

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    Now i need to calculate

    The average Lblaverage
    Money per person Lblmoney
    Total pieces LblPieces
    Total amount of money Lbltotalmoney


    What do i have to put in this lines ?

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    Hello anybody there ?

  16. #16

    Thread Starter
    Lively Member
    Join Date
    Oct 2005
    Location
    Singapore
    Posts
    99

    Re: Calculation Help

    Thanks For The Help Guys


    This Project Is over


    But you can still Help me if you want


    Now this project is Clasiified as (Experimental Subject)

  17. #17
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Calculation Help

    Quote Originally Posted by Franklin67
    Now this project is Clasiified as (Experimental Subject)
    If you have questions on it, please start a new thread.

    Thanks.

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