J
JP SIngh
Hi All
I am trying to plot the days off employees have taken in the selected month
visually using the following code.
The code below takes a long time to execute typically about 8-15 secs each
time.
Is there a away to optimise the code below
thanks
Set RS = CreateObject("ADODB.Recordset")
dim arrDates(31)
do while not rcado.eof
html = html & "<TR>" & vbcrlf
html = html & "<TD class=off>" & rcADO.Fields("Lastname").Value &
", " & rcADO.Fields ("Firstname").Value & "<TD>" & vbcrlf
sql = "Select * from tempquery "
sql = sql & " WHERE (((sMonStart)=" & selMonth & ") AND ((UserID)="
& rcAdo ("EmployeeNumber") & ") AND ((EnYear)=" & selYear & ")) OR
(((sMonEnd)=" & selMonth & ") AND ((UserID)=" & rcAdo("EmployeeNumber") & ")
AND ((EnYear)=" & selYear & ")) order by Fdate "
RS.Open SQL, conn,adOpenStatic
arrcount = 0
do while not rs.eof
startDate = rs("fdate")
endDate = rs("tdate")
' If both dates exists in current month
if month(startdate) = selmonth and
Month(endDate) = selmonth then
startNum = day(startdate)
endNum = day(enddate)
end if
' If starting date is in previous month
if month(startdate) = selmonth -1 then
startnum = 1
endnum = day(enddate)
end if
' If ending date is in next month
if month(enddate) = selmonth + 1 then
startnum =
day(startdate)
endNum = lastday
end if
do while startnum <=endnum
arrDates(arrcount) =
startnum
startnum = startnum + 1
arrcount = arrcount + 1
loop
startnum = 0
endnum = 0
rs.movenext
loop
RS.Close
for j = 1 to lastday
found = flase
for p = 0 to lastday
if arrDates(p) = j then
found = true
end if
next
if found = true then
html = html & "<TD align = center class=off>"& "X" & "<TD>" & vbcrlf
else
html = html & "<TD align = center class=off>" & "-" & "<TD>" & vbcrlf
end if
next
html = html & "</TR>" & vbcrlf
for p = 0 to lastday
arrDates(p) = ""
next
rcado.movenext
loop
response.write html
I am trying to plot the days off employees have taken in the selected month
visually using the following code.
The code below takes a long time to execute typically about 8-15 secs each
time.
Is there a away to optimise the code below
thanks
Set RS = CreateObject("ADODB.Recordset")
dim arrDates(31)
do while not rcado.eof
html = html & "<TR>" & vbcrlf
html = html & "<TD class=off>" & rcADO.Fields("Lastname").Value &
", " & rcADO.Fields ("Firstname").Value & "<TD>" & vbcrlf
sql = "Select * from tempquery "
sql = sql & " WHERE (((sMonStart)=" & selMonth & ") AND ((UserID)="
& rcAdo ("EmployeeNumber") & ") AND ((EnYear)=" & selYear & ")) OR
(((sMonEnd)=" & selMonth & ") AND ((UserID)=" & rcAdo("EmployeeNumber") & ")
AND ((EnYear)=" & selYear & ")) order by Fdate "
RS.Open SQL, conn,adOpenStatic
arrcount = 0
do while not rs.eof
startDate = rs("fdate")
endDate = rs("tdate")
' If both dates exists in current month
if month(startdate) = selmonth and
Month(endDate) = selmonth then
startNum = day(startdate)
endNum = day(enddate)
end if
' If starting date is in previous month
if month(startdate) = selmonth -1 then
startnum = 1
endnum = day(enddate)
end if
' If ending date is in next month
if month(enddate) = selmonth + 1 then
startnum =
day(startdate)
endNum = lastday
end if
do while startnum <=endnum
arrDates(arrcount) =
startnum
startnum = startnum + 1
arrcount = arrcount + 1
loop
startnum = 0
endnum = 0
rs.movenext
loop
RS.Close
for j = 1 to lastday
found = flase
for p = 0 to lastday
if arrDates(p) = j then
found = true
end if
next
if found = true then
html = html & "<TD align = center class=off>"& "X" & "<TD>" & vbcrlf
else
html = html & "<TD align = center class=off>" & "-" & "<TD>" & vbcrlf
end if
next
html = html & "</TR>" & vbcrlf
for p = 0 to lastday
arrDates(p) = ""
next
rcado.movenext
loop
response.write html