|
-
Oct 19th, 2005, 10:12 AM
#1
Thread Starter
Lively Member
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.
-
Oct 19th, 2005, 10:18 AM
#2
PowerPoster
Re: Calculation Help
So... what's the question, exactly?
-
Oct 19th, 2005, 10:20 AM
#3
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?
-
Oct 19th, 2005, 11:21 AM
#4
Thread Starter
Lively Member
Re: Calculation Help
I have done the first part which is the amount earned But the rest it does
nothing
-
Oct 19th, 2005, 11:22 AM
#5
Re: Calculation Help
 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.
-
Oct 19th, 2005, 11:29 AM
#6
Thread Starter
Lively Member
Re: Calculation Help
VB Code:
]Private Sub cmdcalculate_Click()
'Determined The Amount Due
Dim intpieces As Integer
Dim Curprice As Currency
Dim Curamountearned As Currency
intpieces = Val(txtpieces)
'Validate for missing data and enable summary button after
'the first order has been entered
If txtname.Text = "" Then
MsgBox "Please Enter Name", vbOKOnly, "Data Entry Error"
txtname.SetFocus
ElseIf Not IsNumeric(txtpieces.Text) Then
MsgBox "Please Enter a Positive Number for the Piece Count", _
vbOKOnly, "Data Entry Error"
With txtpieces
.Text = " "
.SetFocus
End With
Else
cmdsummary.Enabled = True
' Find person with greatest number of pieces
If intpieces > MintHighestpieces Then 'compare to current winner
MintHighestpieces = intpieces
Mstrhighname = txtname.Text
End If
'find pay rate
If intpieces < 200 Then
Curprice = 0.5
ElseIf intpieces < 400 Then
Curprice = 0.55
ElseIf intpieces < 600 Then
Curprice = 0.6
Else
Curprice = 0.65
End If
'calculate the pay
Curamountearned = intpieces * Curprice
lblamountearned.Caption = FormatCurrency(Curamountearned)
'add to totals
mintpiecesTotal = mintpiecesTotal + intpieces
Dim mintemployeecount As Integer
Mcurpaytotal = Mcurpaytotal + Curamountearned
End If
End Sub
Private Sub cmdclear_Click()
txtname.Text = ""
txtpieces.Text = ""
lblaverage.Caption = ""
lblmoney.Caption = ""
lblpieces = ""
lbltotalmoney = ""
lblamountearned = ""
End Sub
Private Sub cmdexit_Click()
End
End Sub
Private Sub cmdsummary_Click()
'Calculate the average and dispaly the totals
Dim curaveragepay As Currency
Dim strmessage As String
curaveragepay = Mcurpaytotal / mintemployeecount
strmessage = "Total number of pieces " + mintpiecesTotal + vbCrLf + _
"Average Pay: " + FormatCurrency(curaveragepay) + cbCrLf + _
"Person producing most: " + Mstrhighname & vbCrLf + _
" (produced " + MintHighestpieces + " pieces)"
MsgBox strmessage, vbOKOnly, "Piecework Summary"
End Sub
Private Sub Form_Load()
'Initialise the variables
MintHighestpieces = -1
End Sub
Private Sub Label1_Click()
'calculate the pay
Curamountearned = intpieces * Curprice
lblamountearned.Caption = FormatCurrency(Curamountearned)
End Sub
Private Sub Lblearned_Click()
End Sub
Last edited by Hack; Oct 19th, 2005 at 11:39 AM.
-
Oct 19th, 2005, 11:36 AM
#7
Thread Starter
Lively Member
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)
-
Oct 19th, 2005, 11:43 AM
#8
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:
Private Curamountearned As Currency
Now, try your code.
-
Oct 19th, 2005, 11:58 AM
#9
Thread Starter
Lively Member
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
-
Oct 19th, 2005, 12:01 PM
#10
Re: Calculation Help
 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.
-
Oct 19th, 2005, 12:10 PM
#11
Thread Starter
Lively Member
Re: Calculation Help
Then Where Do I transfer it to ?
Private Curamountearned As Currency
-
Oct 19th, 2005, 12:21 PM
#12
Re: Calculation Help
 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.
-
Oct 19th, 2005, 06:35 PM
#13
Thread Starter
Lively Member
Re: Calculation Help
Okay i've already done that
-
Oct 19th, 2005, 06:40 PM
#14
Thread Starter
Lively Member
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 ?
-
Oct 20th, 2005, 05:51 AM
#15
Thread Starter
Lively Member
-
Oct 20th, 2005, 11:32 PM
#16
Thread Starter
Lively Member
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)
-
Oct 21st, 2005, 07:15 AM
#17
Re: Calculation Help
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|