Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with this code

Status
Not open for further replies.

forostec

Programmer
Oct 5, 2004
13
0
0
CO
with this code i'm trying to do the next thing:
I need to determinate the work day(monday, tuestay, wednesday, thursday and wednesday) and the labour time from 8 am to 5 pm, if so, place in excel "5x8" but if not i have to place "7x24".
i have to determinate the weekend (Sunday and Saturdays) and place the "7x24" in excel.

But it doesn't work at all, can you help me to check it out?
Thanks


if upper(tablest.dia)="MONDAY" OR upper(tablest.dia)="TUESDAY" OR upper(tablest.dia)="WEDNESDA" OR upper(tablest.dia)="THURSDAY" OR UPPER(tablest.dia)="FRIDAY" then
if hour(tablest.finicio)>=8 and hour(tablest.finicio)<17 then
XLSheet.Cells(i+1,21).value = "5x8" &&tablest.jornada
endif
ELSE
*if UPPER(tablest.dia)="SATURDAY" or UPPER(tablest.dia)="SUNDAY" then
if hour(tablest.finicio)>=8 and hour(tablest.finicio)<17 then
XLSheet.Cells(i+1,21).value = "7x24"
endif
* else
if (hour(tablest.finicio)>=17 and hour(tablest.finicio)<0) or (hour(tablest.finicio)>=0 and hour(tablest.finicio)<8) then
XLSheet.Cells(i+1,21).value = "7x24"
endif
endif
 

What exactly doesn't work?
The logic or Excel Automation?
Does it do it the wrong way or you get an error message?

 
OK, I see incorrect logic already.
In your last IF you are checking for hour(tablest.finicio)>=17 and hour(tablest.finicio)<0, which is never true at the same time. It should be OR. Plus, you can shorten your whole logic to do it more readable.

How about this piece instead of your whole fragment:

Code:
lWrk=IIF(INLIST(UPPER(tablest.dia), ; 
        "MONDAY","TUESDAY","WEDNESDA","THURSDAY","FRIDAY") AND ;
         BETWEEN(HOUR(tablest.finicio),8,17), "5x8", "7x24")

XLSheet.Cells(i+1,21).Value = lWrk

See if it works.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top