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?
Printable View
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?
Welcome to Forums, Franklin! :wave:
Where are "pieces completed" comming from ? What is it - some values in the database, some values in some textboxes on the form ? :confused: :confused: :confused:
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
:confused: :confused:
Sorry, I'm still not following...
Do you have any clue Franklin as to where to start or this is just a homework assignment?
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
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
I don't know what to do next?
any ideas?
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
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:
'to calculate totals use this: Private Sub cmdCalc_Click() 'validate first textbox With Text1 If Not IsNumeric(Trim(.Text)) Then MsgBox "Invalid entry" .SelStart = 0 .SelLength = Len(.Text) .SetFocus Exit Sub End If End With 'validate second textbox With Text2 If Not IsNumeric(Trim(.Text)) Then MsgBox "Invalid entry" .SelStart = 0 .SelLength = Len(.Text) .SetFocus Exit Sub End If End With 'calculate total amount txtTotal.Text = Format(CCur(Text1.Text) + CCur(Text1.Text), "$0.00") End Sub 'to clear all of your texboxes use this: Private Sub cmdClear_Click() Dim txt As Control For Each txt In Me.Controls If TypeOf txt Is TextBox Then txt.Text = "" End If Next txt End Sub
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 ?
Just multiply values from two textboxes - isn't that a simple math? :confused:Quote:
Originally Posted by Franklin67
In the sample above Text1 textbox represents "Pieces Completed" and Text2 - "Price Paid per Piece"VB Code:
txtTotal.Text = Format(CLng(Text1.Text) * CCur(Text1.Text), "$0.00")
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
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.
can you show me how to do that?
and my maths is weak
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.
well just read the attachment file and help me out
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:
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 etc etc End Select End Function
Your not gonna learn if your too lazy to do read just 2 pages about select case
Somewhat off topic: A humble attidude will get you further in lifeQuote:
Originally Posted by Franklin67
on topic: I'll try to code something later tonight, I just need to get in vb-mood :p
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.Quote:
Originally Posted by JensPeder
no what i ment was only the coding not the whole thing
I can't believe how many people use these forums to do their homework for them...
Okay Check whether i got this correctVB Code:
Private Sub CmdSummary_Click() 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 [COLOR=DarkGreen]'Display a summary message box[/COLOR] intQuantity = Val(txtPieces.Text) curAmount = intQuantity * curPrice [COLOR=Red] lblAmount.Caption = FormatCurrency(curAmount, 2) cmdCalculate. Enabled = False[/COLOR] mintTotalNumber = mintTotalNumber + intQuantity mcurTotalPay = mcurTotalPay + curAmount mintCustomerCount = mintCustomerCount + 1 curAverage = mcurTotalPay / mintCustomerCount [COLOR=DarkGreen]'Format the numbers[/COLOR] strFormattedAvg = FormatCurrency(curAverage, 2) strFormattedPay = FormatCurrency(mcurTotalPay, 2) [COLOR=Red]strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _ "Total Pay: " & strFormattedPay & vbCrLf & _[/COLOR] "Average Pay: " & strFormattedPay MsgBox strMessageString, vbInformation, "Piecework summary" [COLOR=Red]public Function GetPayPerEmp ingTotalPcs As Long)As Currency Select Case lngTotalPcs.[/COLOR] {How com i got this in red ? Case 1 To 199 GetPayPerEmp = lngTotalPcs * 0.5 Case 200 To 299 GetPayPerEmp = lngTotalPcs * 0.55 Case 400 To 599 GetPayPerEmp = ingtotalPcs * 0.60 Case 600 Or more GetPayPerEmp = ingtotal * 0.65 End Select End Function End Sub
Edit: Added [vbcode][/vbcode] tags for clarity. - Hack
Run it, and tell us if it comes back with the right answer.Quote:
Originally Posted by Franklin67
Only those in the red are giving problem
VB Code:
'missing parenthese here public Function GetPayPerEmp ingTotalPcs As Long)As Currency 'should be public Function GetPayPerEmp [color=blue][b]([/b][/color][b][/b]ingTotalPcs As Long)As CurrencyVB Code:
'these need to be on different lines 'not lblAmount.Caption = FormatCurrency(curAmount, 2) cmdCalculate. Enabled = False 'but lblAmount.Caption = FormatCurrency(curAmount, 2) cmdCalculate. Enabled = FalseVB Code:
'got one too many lines here 'not strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _ "Total Pay: " & strFormattedPay & vbCrLf & _ "Average Pay: " & strFormattedPay MsgBox strMessageString, vbInformation, "Piecework summary" 'but strMessageString = "Total number of pieces: " & mintTotalNumber & vbCrLf & _ "Total Pay: " & strFormattedPay & vbCrLf & _ "Average Pay: " & strFormattedPay MsgBox strMessageString, vbInformation, "Piecework summary"
You don't declare a procedure (the function) within another procedure (the sub)
VB Code:
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.60 Case Is > 599 GetPayPerEmp = ingtotal * 0.65 End Select 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
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 assignementQuote:
Originally Posted by RhinoBull
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 ?
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
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.
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
& :confused:
End Function ?
did i miss anything else ?
Quote:
Originally Posted by Franklin67
VB Code:
'again, you have a run on line 'not Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs 'but Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs 'then all your Case statements follow this
Read up regarding procedures pls. definition, types, samples etc
so you mean i must put this on every line ?
Public Function GetPayPerEmp (lngTotalPcs As Long) As Currency Select Case lngTotalPcs
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.
I don't understand Could you show me an example?
:confused: :ehh:Quote:
Originally Posted by Franklin67
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.
A sample won't suffice, you have to read up on it otherwise all were trying to say would sound greek to you.
you mean Erase The Select Case statement off the line
Compile Error
Expected End of the Line .
you mean Erase The Select Case statement off the line ?
Compile Error
Expected End of the Line :confused:
There's a world of difference between erase and move
How Do I Move The select case stement off the line
Compile Error
Expected End of the line :Confused:
Put your curosr under the S of Select and hit the Enter key.Quote:
Originally Posted by Franklin67
and move It where Hmmmm?
Move it nowhere.Quote:
Originally Posted by Franklin67
Just get it off the same line as your Function declaration. If put your cursor under the S in Select and hit enter, you should be just fine.
Are you familiar with the structure of Functions or the structure of Select Case statements?
We're already being patient and trying to explain as best as we could given the fact that your slow on the pickup. But it's not entirely dependent on us.Quote:
Originally Posted by Franklin67
"Help us help you" so to speak.
Like This ?
Public Function GetPayPerEmp(lngTotalPcs As Long) As Currency
Select Case lngTotalPcs
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
End Function
what should i do next ?
You got it (except for an extra End Function. You only need one of those. :) )Quote:
Originally Posted by Franklin67
I have no idea what this means, but as far as building your function goes, you don't have to do anything next.Quote:
Originally Posted by Franklin67
I've made a few changes. See the comments
VB Code:
Public Function GetPayPerEmp(lngTotalPcs As Long) As Currency Select Case lngTotalPcs case 0 to 200 ' or whatever it should be for the next line GetPayPerEmp = lngTotalPcs * 0.5 Case 200 To 299 ' this should be 399, or you won't get 300-399 GetPayPerEmp = lngTotalPcs * 0.55 Case 400 To 599 GetPayPerEmp = ingtotalpcs * 0.6 Case Is > 599 GetPayPerEmp = ingtotalpcs * 0.65 End select End Function
and thats all what's next
Case 200 To 299 ' this should be 399, or you won't get 300-399
Change the 299 to 399 ?
You don't have to change it. Just add another Case statement to cover for it.
so just add another select case to the next line & The next line .......
Quote:
Originally Posted by Franklin67
VB Code:
Public Function GetPayPerEmp(lngTotalPcs As Long) As Currency Select Case lngTotalPcs case 0 to 200 ' or whatever it should be for the next line GetPayPerEmp = lngTotalPcs * 0.5 Case 200 To 299 ' this should be 399, or you won't get 300-399 GetPayPerEmp = lngTotalPcs * 0.55 Case 300 To 399 'just a new case statement. that is all GetPayPerEmp = lngTotalPcs * whatever Case 400 To 599 GetPayPerEmp = ingtotalpcs * 0.6 Case Is > 599 GetPayPerEmp = ingtotalpcs * 0.65 End Select End Function
how do i do that ?
Add this between 200 and 400, and supply the coreect whatever value.
Unless 300-399 uses the same price as 200-299, in which case you can just change the other statement like I said earlier. If you leave it out, then nothing will be multiplied as a case wouldn't be found
VB Code:
Case 300 To 399 'just a new case statement. that is all GetPayPerEmp = lngTotalPcs * whatever
so what should i add for the new case statement?
Look at post #54
Case 200 To 299 ' this should be 399, or you won't get 300-399
(So this is what i have to type in)
VB Code:
Case 300 To 399 'just a new case statement. GetPayPerEmp = lngTotalPcs 0.55
Yes. Or, you can just copy what I posted and overlay what you have now.Quote:
Originally Posted by Franklin67