|
-
Feb 19th, 2000, 07:20 AM
#1
Thread Starter
Junior Member
My payroll calculator gives the wrong answer and i am pretty sure my code is right. It is supposed to give time and a half for hours worked over 40 but gives the wrong answer, it does give the right answer for hours under 40 though, here is the code: What's wrong? 
Dim inthours As Integer
Dim intrate As Integer
Dim intgross As Integer
inthours = txthours.Text
intrate = txtrate.Text
If inthours > 40 Then
intrate = intrate * 1.5
lblgross.Caption = inthours * intrate
ElseIf inthours <= 40 Then
intrate = intrate
lblgross.Caption = inthours * intrate
End If
End Sub
-
Feb 19th, 2000, 08:59 AM
#2
Fanatic Member
This seems to work for me:
Code:
Private Sub Command1_Click()
Dim intHours As Integer
Dim intRate As Integer
Dim intGross As Integer
intHours = txthours.Text
intRate = txtrate.Text
If intHours > 40 Then
lblgross.Caption = 40 * intRate 'I added this line...
intRate = intRate * 1.5
lblgross.Caption = lblgross.Caption + (intHours - 40) * intRate '...and modified this one
ElseIf intHours <= 40 Then
intRate = intRate
lblgross.Caption = intHours * intRate
End If
End Sub
Also when you defined IntRate as Integer: it only works for even numbers, if your rate is odd, then 1.5 of it will always be .5 too much (hope you know what I mean - it simply rounds it)
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
[This message has been edited by QWERTY (edited 02-19-2000).]
-
Feb 19th, 2000, 11:36 AM
#3
Addicted Member
Hi.
Worked hours = 60
Rate = 6
Hint, The way to do it:
(40 * 6) + (20 + 9) 
QWERTY, Int gives the Integer part only. 1.5 => 1
Good Luck.
-
Feb 19th, 2000, 12:06 PM
#4
Thread Starter
Junior Member
Thanks, I understand it now. And changed the rate one's to currency and did the other stuff. Thanks.
-
Feb 19th, 2000, 12:12 PM
#5
Fanatic Member
Actually Lyla 1.5 = 2 if you have variable defined as integer. Checked it, I can't be wrong. 
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
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
|