Page 1 of 4 1234 LastLast
Results 1 to 40 of 159

Thread: [RESOLVED] Piecework Visual Basic 6.0

  1. #1

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

    Resolved [RESOLVED] Piecework Visual Basic 6.0

    Hi I have a project due soon and I am lost. Okay, I need to calculate & summarize the number of pieces completed



    See I am new to visual Basic

    Just a request Does anybody here Has the solution for piecework?

  2. #2

  3. #3

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

    Re: Piecework Visual Basic 6.0

    So Here's the full stats of my project

    I need to Use text Boxes To Obtain The person's name And the number Of pieces Completed



    and i also have to include a calculate button To display the total number of pieces Total Pay and the average pay Per person

    and include Validation To check for missing data


    and Of course The Clear Button

    and i need help with the coding



  4. #4
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    Re: Piecework Visual Basic 6.0

    Sorry, I'm still not following...

  5. #5

  6. #6

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

    Re: Piecework Visual Basic 6.0

    Calc Pay Menu Command

    Calculates and displays the dollar amount earned.



    Also, you need to make sure to not display the Summary form before any data is entered; you cannot calculate a total or an average when no items have been calculated. You can either check the number of employees or disable the Summary menu command until the first order has been calculated. If you choose to disable the Summary menu command, be sure to de-select the Enabled check box when setting it up in the Menu Editor. You will then need to enable it in your code at the right time.

    Summary Menu Command

    Summary Form

    The Summary form should display the summary information. The summary information is as follows:



    1. Total number of pieces

    2. Total number of employees

    3. Total pay for all employees

    4. Average pay for all employees



    The summary information should appear when the form is initially displayed. This form should also include two command buttons, a Back button and a Quit button. The Back button will close the Summary form and go back to the Main form. The Quit button will display a message box to make sure the user would really like to quit the program. If the user selects Yes, terminate the program. If the user selects No, close the Summary form and display the Main form.



    Displays the Summary form and all necessary summary information


    Pieces Completed
    1-199
    200-399
    400-599
    600 Or more




    Price Paid per Piece
    $0.50
    $0.55
    $0.60
    $0.65
    Last edited by Franklin67; Oct 2nd, 2005 at 08:38 AM.

  7. #7

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

    Re: Piecework Visual Basic 6.0

    The first Thing i Have to do

    Is create the text boxes and lables and text boxes

    Which i have already done



    Now only the coding part

  8. #8

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

    Re: Piecework Visual Basic 6.0

    I don't know what to do next?

    any ideas?

  9. #9

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

    Re: Piecework Visual Basic 6.0

    So, i have a calculate button. ,summary button. , clear button.

    and i am
    confused on how to make this work. Completely lost.... any help would be great

  10. #10
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Piecework Visual Basic 6.0

    OK, say you have two textboxes Text1 and Text2 and you want to calculate the toal amount and output it in another textbox say txtTotal:
    VB Code:
    1. 'to calculate totals use this:
    2. Private Sub cmdCalc_Click()
    3.  
    4.     'validate first textbox
    5.     With Text1
    6.         If Not IsNumeric(Trim(.Text)) Then
    7.             MsgBox "Invalid entry"
    8.             .SelStart = 0
    9.             .SelLength = Len(.Text)
    10.             .SetFocus
    11.             Exit Sub
    12.         End If
    13.     End With
    14.    
    15.     'validate second textbox
    16.     With Text2
    17.         If Not IsNumeric(Trim(.Text)) Then
    18.             MsgBox "Invalid entry"
    19.             .SelStart = 0
    20.             .SelLength = Len(.Text)
    21.             .SetFocus
    22.             Exit Sub
    23.         End If
    24.     End With
    25.    
    26.     'calculate total amount
    27.     txtTotal.Text = Format(CCur(Text1.Text) + CCur(Text1.Text), "$0.00")
    28.  
    29. End Sub
    30.  
    31. 'to clear all of your texboxes use this:
    32. Private Sub cmdClear_Click()
    33. Dim txt As Control
    34.  
    35.     For Each txt In Me.Controls
    36.         If TypeOf txt Is TextBox Then
    37.             txt.Text = ""
    38.         End If
    39.     Next txt
    40.  
    41. End Sub

  11. #11

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

    Re: Piecework Visual Basic 6.0

    But how do i calculate The dollar amount earned ?



    Now the summary button to display the total number of pieces the total pay and the average pay per person

    How do i do that ?

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by Franklin67
    But how do i calculate The dollar amount earned ?
    Just multiply values from two textboxes - isn't that a simple math?
    VB Code:
    1. txtTotal.Text = Format(CLng(Text1.Text) * CCur(Text1.Text), "$0.00")
    In the sample above Text1 textbox represents "Pieces Completed" and Text2 - "Price Paid per Piece"

  13. #13

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

    Re: Piecework Visual Basic 6.0

    How about the pieces and the summary button ?

    1-199 Pieces completed the price per piece is $.50
    200-399 Pieces completed the price per piece is $.55
    400-599 Pieces completed the price per piece is $.60
    600+ Pieces completed the price per piece is $.65

  14. #14
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    Then, using the power of common sense, you obviously have to tally first the total quantity completed (and store its value in a variable) before doing additional computations involving rate per piece.

  15. #15

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

    Re: Piecework Visual Basic 6.0

    can you show me how to do that?

    and my maths is weak

  16. #16
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    That's not an excuse unless ..... is VB being taught in elementary nowadays?

    Come on! A little effort on your part pls.

    You get the totalpcs with addition
    You then multiply this with any of the four rates (0.5, 0.55, 0.6, 0.65) with a select case structure or an if...then...elseif structure, I suggest you use the select case.

    All the info is available in MSDN. For now you need to look up the syntax and use of select case

    Also by looking up msdn, you might come across other info you will need for this assignment. Instead of asking about every single detail.
    Last edited by leinad31; Oct 2nd, 2005 at 10:37 AM.

  17. #17

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

    Re: Piecework Visual Basic 6.0

    well just read the attachment file and help me out
    Attached Files Attached Files

  18. #18
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    To perform the pay calculation:
    Use a function procedure to find the pay rate and return a value to the proper event procedure.

    VB Code:
    1. Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency
    2.  
    3.  
    4. Select Case lngTotalPcs
    5. Case 1 To 199
    6.    GetPayPerEmp = lngTotalPcs * 0.5
    7. Case 200 To 299
    8.    GetPayPerEmp = lngTotalPcs * 0.55
    9. etc etc
    10. End Select
    11.  
    12. End Function

    Your not gonna learn if your too lazy to do read just 2 pages about select case
    Last edited by leinad31; Oct 3rd, 2005 at 07:52 AM.

  19. #19
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by Franklin67
    well just read the attachment file and help me out
    Somewhat off topic: A humble attidude will get you further in life

    on topic: I'll try to code something later tonight, I just need to get in vb-mood

  20. #20
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by JensPeder
    Somewhat off topic: A humble attidude will get you further in life

    on topic: I'll try to code something later tonight, I just need to get in vb-mood
    OFF TOPIC: your "on topic" promise shouldn't really be there - we don't do homeworks for anybody - we try to help to solve some particular problem(s) unless it's some "major issue" which is obviously NOT the case here.

  21. #21

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

    Re: Piecework Visual Basic 6.0

    no what i ment was only the coding not the whole thing

  22. #22
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Re: Piecework Visual Basic 6.0

    I can't believe how many people use these forums to do their homework for them...
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

  23. #23

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

    Re: Piecework Visual Basic 6.0

    Okay Check whether i got this correct
    VB Code:
    1. Private Sub CmdSummary_Click()
    2.  
    3.  
    4. Dim curAverage As Currency
    5. Dim intQuantity As Integer
    6. Dim curAmount As Currency
    7. Dim strMessageString As String
    8. Dim strFormattedAvg As String
    9. Dim strFormattedPay As String
    10. Dim curPrice As Currency
    11. [COLOR=DarkGreen]'Display a summary message box[/COLOR]
    12.  
    13. intQuantity = Val(txtPieces.Text)
    14. curAmount = intQuantity * curPrice
    15. [COLOR=Red] lblAmount.Caption =  FormatCurrency(curAmount, 2)  cmdCalculate. Enabled =  False[/COLOR]
    16. mintTotalNumber = mintTotalNumber + intQuantity
    17. mcurTotalPay = mcurTotalPay + curAmount
    18. mintCustomerCount = mintCustomerCount + 1
    19. curAverage = mcurTotalPay / mintCustomerCount
    20.  
    21.  
    22. [COLOR=DarkGreen]'Format the numbers[/COLOR]
    23.  
    24. strFormattedAvg = FormatCurrency(curAverage, 2)
    25. strFormattedPay = FormatCurrency(mcurTotalPay, 2)
    26. [COLOR=Red]strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _
    27. "Total Pay: " & strFormattedPay & vbCrLf & _[/COLOR]
    28.  
    29. "Average Pay: " & strFormattedPay
    30. MsgBox strMessageString, vbInformation, "Piecework summary"
    31.  
    32. [COLOR=Red]public Function GetPayPerEmp ingTotalPcs As Long)As Currency Select Case lngTotalPcs.[/COLOR]  {How com i got this in red ?
    33.  
    34. Case 1 To 199
    35.    GetPayPerEmp = lngTotalPcs * 0.5
    36. Case 200 To 299
    37.    GetPayPerEmp = lngTotalPcs * 0.55
    38.  
    39. Case 400 To 599
    40.  GetPayPerEmp = ingtotalPcs * 0.60
    41.  
    42.    Case 600 Or more
    43.    GetPayPerEmp = ingtotal * 0.65
    44. End Select
    45.  
    46. End Function
    47. End Sub




    Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
    Last edited by Hack; Oct 3rd, 2005 at 06:50 AM.

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

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by Franklin67
    Okay Check whether i got this correct
    Run it, and tell us if it comes back with the right answer.

  25. #25

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

    Re: Piecework Visual Basic 6.0

    Only those in the red are giving problem

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

    Re: Piecework Visual Basic 6.0

    VB Code:
    1. 'missing parenthese here
    2. public Function GetPayPerEmp ingTotalPcs As Long)As Currency
    3. 'should be
    4. public Function GetPayPerEmp [color=blue][b]([/b][/color][b][/b]ingTotalPcs As Long)As Currency
    VB Code:
    1. 'these need to be on different lines
    2. 'not
    3.  lblAmount.Caption =  FormatCurrency(curAmount, 2)  cmdCalculate. Enabled =  False
    4. 'but
    5.  lblAmount.Caption =  FormatCurrency(curAmount, 2)  
    6. cmdCalculate. Enabled =  False
    VB Code:
    1. 'got one too many lines here
    2. 'not
    3. strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _
    4. "Total Pay: " & strFormattedPay & vbCrLf & _
    5.  
    6. "Average Pay: " & strFormattedPay
    7. MsgBox strMessageString, vbInformation, "Piecework summary"
    8. 'but
    9. strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _
    10. "Total Pay: " & strFormattedPay & vbCrLf & _
    11. "Average Pay: " & strFormattedPay
    12. MsgBox strMessageString, vbInformation, "Piecework summary"
    Last edited by Hack; Oct 3rd, 2005 at 07:23 AM.

  27. #27
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    You don't declare a procedure (the function) within another procedure (the sub)

    VB Code:
    1. Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency
    2. '''
    3.  
    4. Select Case lngTotalPcs.  
    5. Case 1 To 199
    6.    GetPayPerEmp = lngTotalPcs * 0.5
    7. Case 200 To 299
    8.    GetPayPerEmp = lngTotalPcs * 0.55
    9.  
    10. Case 400 To 599
    11.  GetPayPerEmp = ingtotalPcs * 0.60
    12.  
    13. Case Is > 599
    14.    GetPayPerEmp = ingtotal * 0.65
    15. End Select
    16.  
    17. End Function

    To call this elsewhere, such in CmdSummary_Click() procedure you do:

    Dim CalculatedPay As Currency
    Dim lngSampleVar As Currency

    'Let's assume 150 pcs to be used as parameter for the function call stored in variable lngSampleVar
    lngSampleVar = 150 'assigned 150 based on previous calculations
    CalculatedPay = GetPayPerEmp(lngSampleVar)
    'CalculatedPay would then become equal to 75 because thats the value returned by the function call
    Last edited by leinad31; Oct 3rd, 2005 at 09:00 AM.

  28. #28
    Addicted Member JensPeder's Avatar
    Join Date
    Sep 2005
    Posts
    249

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by RhinoBull
    OFF TOPIC: your "on topic" promise shouldn't really be there - we don't do homeworks for anybody - we try to help to solve some particular problem(s) unless it's some "major issue" which is obviously NOT the case here.
    Well, I never ment to make a complete program, just read the description and guide the guy a little bit. He should of course try to do most of it himself, but its he's completely lost its nice to get some guidance on how to tackle the assignement

  29. #29

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

    Re: Piecework Visual Basic 6.0

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.
    (ONLY THis one)


    Dim curAverage As Currency
    Dim intQuantity As Integer
    Dim curAmount As Currency
    Dim strMessageString As String
    Dim strFormattedAvg As String
    Dim strFormattedPay As String
    Dim curPrice As Currency
    Dim CalculatedPay As Currency
    Dim lngSampleVar As Currency


    'Display a summary message box

    intQuantity = Val(txtPieces.Text)
    curAmount = intQuantity * curPrice

    mintTotalNumber = mintTotalNumber + intQuantity
    mcurTotalPay = mcurTotalPay + curAmount
    mintCustomerCount = mintCustomerCount + 1
    curAverage = mcurTotalPay / mintCustomerCount


    'Format the numbers

    strFormattedAvg = FormatCurrency(curAverage, 2)
    strFormattedPay = FormatCurrency(mcurTotalPay, 2)
    strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _
    "Total Pay: " & strFormattedPay & vbCrLf & _
    lblAmount.Caption = FormatCurrency(curAmount, 2)
    CmdCalculate.Enabled = False

    strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _
    "Total Pay: " & strFormattedPay & vbCrLf & _
    "Average Pay: " & strFormattedPay
    MsgBox strMessageString, vbInformation, "Piecework summary"


    Private Sub Cmdcalculate_Click()

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.
    Case 1 To 199
    GetPayPerEmp = lngTotalPcs * 0.5
    Case 200 To 299
    GetPayPerEmp = lngTotalPcs * 0.55

    Case 400 To 599
    GetPayPerEmp = ingtotalpcs * 0.6

    Case Is > 599
    GetPayPerEmp = ingtotalpcs * 0.65
    End Function

    and now am i missing anything ?
    Last edited by Franklin67; Oct 3rd, 2005 at 09:10 AM.

  30. #30
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    there's something wrong with the vbcode tags, the function declaration ought to finish with as currency, select case should be on the next line. I had to insert comment characters to get them to go to the next line.

    And the function is declared separately... not nested in the sub procedures declaration

    Private Sub Cmdcalculate_Click()
    ...
    End Sub

    Public Function etc...
    ...
    End Function

  31. #31
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    Oh btw, I believe your gonna use that only for the pay per employee (total pcs sold by employee to get corresponding pay given to him). For the summary form, the computations are different. You get the totals including totals of pay per employee and then divide to get the average.

  32. #32

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

    Re: Piecework Visual Basic 6.0

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.

    This one gives me the error

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.
    Case 1 To 199
    GetPayPerEmp = lngTotalPcs * 0.5
    Case 200 To 299
    GetPayPerEmp = lngTotalPcs * 0.55

    Case 400 To 599
    GetPayPerEmp = ingtotalpcs * 0.6

    Case Is > 599
    GetPayPerEmp = ingtotalpcs * 0.65
    End Sub
    End Function

    where do i put Public Function
    &
    End Function ?

    did i miss anything else ?
    Last edited by Franklin67; Oct 3rd, 2005 at 09:33 AM.

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

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by Franklin67
    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.

    This one gives me the error

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs.
    Case 1 To 199
    GetPayPerEmp = lngTotalPcs * 0.5
    Case 200 To 299
    GetPayPerEmp = lngTotalPcs * 0.55

    Case 400 To 599
    GetPayPerEmp = ingtotalpcs * 0.6

    Case Is > 599
    GetPayPerEmp = ingtotalpcs * 0.65
    End Sub
    End Function

    Public Function
    End Function

    did i miss anything else ?
    VB Code:
    1. 'again, you have a run on line
    2. 'not
    3. Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs
    4. 'but
    5. Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency
    6.  
    7. Select Case lngTotalPcs
    8. 'then all your Case statements follow this

  34. #34
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    Read up regarding procedures pls. definition, types, samples etc

  35. #35

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

    Re: Piecework Visual Basic 6.0

    so you mean i must put this on every line ?

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs

  36. #36
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    No No no That should be two lines.

    THERS SOMETHING WRONG WITH THE PARSING OF THE VBCODE TAGS

    I had to insert the comment char ''' just to keep them from running on the same line.

    "Select Case" should be on a new line.

    But aside from that you have no idea on the poper declaration of procedures... your nesting them in your code. Please read up on procedures, its definition, the types of procedures, etc so you can understand better what I was trying to point out.

  37. #37

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

    Re: Piecework Visual Basic 6.0

    I don't understand Could you show me an example?

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

    Re: Piecework Visual Basic 6.0

    Quote Originally Posted by Franklin67
    so you mean i must put this on every line ?

    Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs


    You don't need to put anything anywhere. Just move the Select Case statement off of the line on which you are declaration your Function.

  39. #39
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Piecework Visual Basic 6.0

    A sample won't suffice, you have to read up on it otherwise all were trying to say would sound greek to you.

  40. #40

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

    Re: Piecework Visual Basic 6.0

    you mean Erase The Select Case statement off the line

    Compile Error
    Expected End of the Line .

Page 1 of 4 1234 LastLast

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