It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming Visual Basic Forum

help needed urgently

Moderator: dafunkymunky

help needed urgently

Postby carlozdre on Thu May 10, 2007 9:50 pm

Hello, I am writting a VB program which I am having problems with.
The point of the program is to calculate a workers pay.

However there are 3 tarrifs that apply, a worker cannot work more than 68 hours. The first 33 are paid at RATE1 then from 37 to 44 hours its RATE2 and from 45 to 68 its RATE3.

My problem is that when I type the amount of hours into the textbox defined as txthours the program has to split the number into 3 parts according to the rates mentioned above. I have worked out the first part of my problem, however on the second part is not going well.

For example if I type in 40 hours then the first 36 are stored in the first variable and the next 4 to the second one, however if I put more than 44 the second veriable keeps storing the second part of the number, even tho I have tried to include some kind of validation to stop it.

Please help, I need this program for tomorrow as this is college work and I tried for several hours to get it working and simply cant.

If I don't I am in deep deep sh*t as my attendance is very bad and I need this in order to stay on the course.


Thank you in advance.



------------------------------------
Option Explicit

Dim arr1(1 To 35) As Arraytype
Dim element As Integer

Private Sub cmdexit_Click()

End

End Sub

Private Sub cmdsubmite_Click()

'Dim grostotal As Currency
'Dim ni As Integer
'Dim tax As Integer
Dim rate1 As Currency
Dim rate2 As Currency
Dim rate3 As Currency
Dim pay1 As Currency
Dim pay2 As Currency
Dim pay3 As Currency
Dim row As Single
Dim pay As Integer
Dim original As Integer
Dim cacamaca As Integer

If txtname = "" Then
MsgBox "Please enter a name"
txtname = ""
txtname.SetFocus
ElseIf txtnumber = "" Then
MsgBox " please enter the employees number"
txtnumber = ""
txtnumber.SetFocus
ElseIf txthours = "" Then
MsgBox "Please enter the amount of hours worked"
txthours.SetFocus
ElseIf txthours = 0 Or txthours > 68 Then
MsgBox "Please enter the correct amount of hours"
txthours = ""
txthours.SetFocus
ElseIf txtdate = "" Then
MsgBox "Please enter the date"
txtdate = ""
txtdate.SetFocus
Else

rate1 = 7.45
rate2 = 10.32
rate3 = 15.66

pay = txthours.Text
original = 44



If pay < 37 Then
pay1 = pay
ElseIf pay > 36 Then
pay1 = 36
End If


!!!!!!!!THE PROBLEM!!!!!!!!
If pay > 36 Then
pay2 = pay - 36
ElseIf pay > 44 Then
pay2 = pay - 44
End If

-----------------------------------------
If pay < 37 Then
pay3 = pay
ElseIf pay > 36 Then
pay3 = 36
End If

element = element + 1



End If


row = row + 1
cboname.AddItem (txtname.Text)
lbltest.Caption = "PAY" & pay & " PAY1 " & pay1 & " PAY2 " & pay2 & " PAY3 " & pay3


End Sub
carlozdre
 
Posts: 0
Joined: Thu May 10, 2007 7:56 pm

Postby ashish4172 on Sat May 19, 2007 5:59 am

hi

If pay > 36 Then
pay2 = pay - 36
ElseIf pay > 44 Then
pay2 = pay - 44
End If

u have pb in ur code.For pay=45 both the conditions below happen 2 b true according to ur code.Specify the eaxct rangefor e.g

If pay > 36 and pay < 44 Then
pay2 = pay - 36
ElseIf pay > 44 and pay<68 Then
pay2 = pay - 44
End If

perhaps this could help

cheers
ashish
ashish4172
 
Posts: 4
Joined: Tue Apr 17, 2007 10:44 am


Who is online

Users browsing this forum: No registered users and 3 guests