Jump to content

VBscript Help


Recommended Posts

I need this script to output, after entering XXXXXX , without asking for hours worked, i am unsure where i went wrong!

Option Explicit

Const strTitle = "Employee Pay Calculator"
Const sngPAY_RATE = 25
Const sngTAX_RATE = 0.3

Dim strEmployeeID
Dim sngHours
Dim sngGrossPay
Dim intTotalEmps
Dim sngTotalGross
Dim intTotalHours
Dim sngPayrollTax

intTotalEmps = 0
sngTotalGross = 0
intTotalHours = 0

strEmployeeID = (InputBox("Enter Employee ID", strTitle, ""))
WHILE (strEmployeeID <> "XXXXXX")
sngHours = (InputBox("Enter Hours worked", strTitle, ""))
sngGrossPay = sngHours * sngPAY_RATE
intTotalEmps = intTotalEmps + 1
intTotalHours = intTotalHours + sngHours
sngTotalGross = sngTotalGross + sngGrosspay
WEND
sngPayrollTax = sngTotalGross * sngTAX_RATE
MsgBox "Total Employees: " & intTotalEmps & vbCrlf &_
"Total Hours: " & sngTotalHours & vbCrlf & _
"Total Gross: " & FormatCurrency(sngTotalGross, 2) & vbCrlf & _
"Payroll Tax: " & FormatCurrency(sngPayrollTax, 2), vbInformation, strTitle

Edited by erw34r3
Link to comment
Share on other sites


I am not quite sure what you wanted with your script, your explanation is lost to me.

Try this and add to it.

Const sngPAY_RATE = 25
Const sngTAX_RATE = 0.3

Dim strEmployeeID, sngHours, sngGrossPay, intTotalEmps, sngTotalGross, intTotalHours, sngPayrollTax

Do
strEmployeeID = (InputBox("Enter Employee ID" & vbCrLf & "Type Exit To Quit", strTitle, ""))
If Not strEmployeeID = "quit" Then
WScript.Echo strEmployeeID
Else
WScript.Quit(0)
End If
Loop While strEmployeeID = ""

Link to comment
Share on other sites

Ok, here i go.

My script asks for a employee id then asks for hours worked.

While employee id does not equal XXXXXX , the script tallies employees and other calculation are performed.

After entering XXXXXX, the script should not ask for hours worked :(.

It should now display totals, it does, but only after entering hours for XXXXXX, which it should not.

My guess is i have not put the INPUTS in the correct place.

Any ideas anyone?

PS I would like to use WHILE/WEND, I do not wish to learn DO/WHILE just yet.

Edited by erw34r3
Link to comment
Share on other sites

Try this code and add what ever scripting needed in the second loop.

Const sngPAY_RATE = 25
Const sngTAX_RATE = 0.3

Dim strEmployeeID, sngHours, sngGrossPay, intTotalEmps, sngTotalGross, intTotalHours, sngPayrollTax

Do '-> Loop To Get UserID Input Or Quit Script Loop 01 Start
strEmployeeID = (InputBox("Enter Employee ID" & vbCrLf & "Type Exit To Quit", strTitle, ""))
If Not strEmployeeID = "quit" Then
WScript.Echo strEmployeeID
sngHours = (InputBox("Enter The Amount Of Hours You Have Booked " & vbCrLf & "Type Exit To Quit", strTitle, ""))
Do '-> Loop To Get Total Hours Input Or Quit Script Loop 02 Start
If Not sngHours = "quit" Then
'-> Place What Ever Code You Need In Here

Else '-> User Cancel Hours
WScript.Quit(1)
End If
Loop While strEmployeeID = "" '-> Loop 02 End
Else '-> User Cancel ID
WScript.Quit(0)
End If
Loop While strEmployeeID = "" '-> Loop 01 End

Link to comment
Share on other sites

I am not ungrateful, but..... I did insist on using WHILE/WEND, i do appreciate your work! I am not seeking an answer that requires DO/LOOP WHILE. Is it possible, to display results, without entering HOURSWORKED for employee XXXXXX ?

Link to comment
Share on other sites

As the script is it ment to get user input threw ID and hours worked.

The only way to stop the loop is either type in quit and it will exit the script

with no iformation being process. The advantage of using loops is to force

a responce from the user, either fill in the ID or quit, fill Hours or quit.

There is no point in processing information if the user skips adding it.

Link to comment
Share on other sites

The way your loop was written (while, with inputbox in it), it will always try to do the math using "XXXXXX" as a number, so it will always error out. I don't really see what the problem is WRT using do/loop vs a while loop really.

Either ways, a simple spreadsheet is far better for things like this... You could enter all your employees (and their IDs), along with their specific hourly rates, etc and have all the math done there. It could also easily calculate your other stuff (like how much you take off their pay for various things, etc). I don't see why you'd even want to use a vbscript for this in the first place.

Link to comment
Share on other sites

...

PS I would like to use WHILE/WEND, I do not wish to learn DO/WHILE just yet.

The reason that WHILE/WEND was outed in "VBScript" as it is tested once at the start. DO/WHILE also gives the option at the start or end of the loop. When tested "Do While" or "Loop While" gives more options for you as a programmer.

Edit: Keyword change

Edited by MHz
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...