Pls comment my VBS

T

Tony WONG

i run this script daily to generate html file for records from today to end
of the month but find this script use a lot of resources to loop through all
the items in "" For each Item in KKK ..... Next" loop.

it seems logical to do it but it needs a few minutes to complete.

if i do it by outlook (save as web page), it just a few seconds. the
performance is much better by my script.

Could you kindly comment my script whether it is somehow excessive?

the folder has 2xxx record items. any ways to do it better and faster.

Thanks a lot.

tony


******************** VB script ****************************
Set fso = CreateObject("Scripting.FileSystemObject")
Set webfile = fso.CreateTextFile("c:\temp\uploadevent.htm", True)
Set myOlApp = CreateObject("Outlook.Application")
Set myNamespace = myOLApp.GetNamespace("MAPI")
Set ABC = myNamespace.GetDefaultFolder(18)

For Each objfolder In ABC.Folders
If objfolder = "Event" Then

Set KKK = objfolder.Items
KKK.Sort "Start", False

date1 = DateAdd("m", 1, Date)
date2 = Year(date1) & "/" & Month(date1) & "/" & "1"
date3 = FormatDateTime(date2)
date4 = DateAdd("d", -1, date3) + 0.99999
b = 0

webfile.Write "<html><head><META HTTP-EQUIV='Content-Type'
content='text/html; charset=big5'><link rel=stylesheet href=schedule.css
type=text/css></head><body bgcolor ='#CCFFFF'>"

For Each Item In KKK
If Item.Class = 26 Then
If Item.Start >= date + 0.00001 And Item.Start <= date4 Or
Item.Start < date4 And Item.end > date4 Or Item.End >= date + 0.00001 And
Item.End <= date4 + 0.00001 Then
With webfile
If DateValue(Item.Start) <> a Then
If b <> 0 Then
.writeline "<br>"
End If
b = b + 1

if DateValue(Item.Start) < DateValue(date) then
mark = DatePart("yyyy", Item.Start) & DatePart("m", Item.Start) &
DatePart("d", Item.Start)
else
mark = "mark"
end if

.writeline "<a name=" & mark & " id=" &
mark & " href='#" & mark & "'>" & day(item.start) & "&nbsp" &
MonthName(month(item.start), true) & " - " &
weekdayname(weekday(item.start)) & "</a><br>"
End If

.write "<strong>" & Item.Subject &
"</strong>"

If Item.Location <> "" Then
itemLocat = " (" & Item.Location & ")"
End If

If Item.End - Item.Start < 1 Then
.Write "&nbsp&nbsp&nbsp&nbsp" &
Left(TimeValue(Item.Start), 5) & " - " & Left(TimeValue(Item.End), 5)
ElseIf Item.End - Item.Start = 1 Then
.Write "&nbsp&nbsp&nbsp&nbsp" & "Full day"
ElseIf Item.End - Item.Start > 1 Then
if MonthName(Month(Item.Start), True) = MonthName(Month(Item.End -
0.00001), True) then
.Write "&nbsp&nbsp&nbsp&nbsp" &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & "&nbsp" &
MonthName(Month(Item.Start), True)
else
.Write "&nbsp&nbsp&nbsp&nbsp" &
Right(FormatDateTime(DateValue(Item.Start), 2), 2) &
MonthName(Month(Item.Start), True) & " - " &
Right(FormatDateTime(DateValue(Item.End) - 1, 2), 2) & "&nbsp" &
MonthName(Month(Item.End), True)
end if
End If

.writeline itemLocat & "<br>"
itemLocat = ""
End With
a = DateValue(Item.Start)

End If
End If
Next

webfile.Write "</body></html>"
webfile.Close

End If
Next
 
K

Ken Slovak - [MVP - Outlook]

Iterating that many items in that many folders using the Outlook object
model in an interpreted language (VBScript) is always going to be slow. It
would be faster using a different API such as CDO 1.21 or Redemption
(www.dimastr.com/redemption). From CDO or Redemption's RDO objects you
probably would expect an order of magnitude speed increase.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top