erw34r3 Posted March 26, 2009 Share Posted March 26, 2009 (edited) I need this script to output, after entering XXXXXX , without asking for hours worked, i am unsure where i went wrong!Option ExplicitConst strTitle = "Employee Pay Calculator"Const sngPAY_RATE = 25Const sngTAX_RATE = 0.3Dim strEmployeeIDDim sngHoursDim sngGrossPayDim intTotalEmpsDim sngTotalGrossDim intTotalHoursDim sngPayrollTaxintTotalEmps = 0sngTotalGross = 0intTotalHours = 0strEmployeeID = (InputBox("Enter Employee ID", strTitle, ""))WHILE (strEmployeeID <> "XXXXXX")sngHours = (InputBox("Enter Hours worked", strTitle, ""))sngGrossPay = sngHours * sngPAY_RATEintTotalEmps = intTotalEmps + 1intTotalHours = intTotalHours + sngHourssngTotalGross = sngTotalGross + sngGrosspayWENDsngPayrollTax = sngTotalGross * sngTAX_RATEMsgBox "Total Employees: " & intTotalEmps & vbCrlf &_"Total Hours: " & sngTotalHours & vbCrlf & _"Total Gross: " & FormatCurrency(sngTotalGross, 2) & vbCrlf & _"Payroll Tax: " & FormatCurrency(sngPayrollTax, 2), vbInformation, strTitle Edited March 26, 2009 by erw34r3 Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 26, 2009 Share Posted March 26, 2009 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 = 25Const sngTAX_RATE = 0.3Dim strEmployeeID, sngHours, sngGrossPay, intTotalEmps, sngTotalGross, intTotalHours, sngPayrollTaxDo 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 More sharing options...
erw34r3 Posted March 26, 2009 Author Share Posted March 26, 2009 (edited) 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 March 26, 2009 by erw34r3 Link to comment Share on other sites More sharing options...
gunsmokingman Posted March 26, 2009 Share Posted March 26, 2009 Try this code and add what ever scripting needed in the second loop.Const sngPAY_RATE = 25Const sngTAX_RATE = 0.3Dim 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 More sharing options...
erw34r3 Posted March 27, 2009 Author Share Posted March 27, 2009 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 More sharing options...
gunsmokingman Posted March 27, 2009 Share Posted March 27, 2009 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 scriptwith no iformation being process. The advantage of using loops is to forcea 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 More sharing options...
CoffeeFiend Posted March 27, 2009 Share Posted March 27, 2009 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 More sharing options...
erw34r3 Posted March 27, 2009 Author Share Posted March 27, 2009 (edited) Thankyou All, I worked it out today Cheers AnywayWhy? Cos im learning is why! Edited March 27, 2009 by erw34r3 Link to comment Share on other sites More sharing options...
Yzöwl Posted March 27, 2009 Share Posted March 27, 2009 Without wishing to sound ungrateful, it would help the topic and any potential readers of it if you were to provide the solution you worked out! Link to comment Share on other sites More sharing options...
MHz Posted March 29, 2009 Share Posted March 29, 2009 (edited) ...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 March 29, 2009 by MHz Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now