Das Notes Forum
Domino 9 und frühere Versionen => Entwicklung => Thema gestartet von: Holger am 03.05.03 - 13:52:55
-
Hallo Script Profis,
ausser meinem Summierungsproblem habe ich noch ein Problem mit meinem Script, dem Provider gefällt in diesem nicht, dass dort getnthdocument steht und er hätte gerne getnextdocument, ich habe mit meinen geringen Script Kenntnissen mal probiert das umzuschreiben aber habe es nicht geschafft, das Script hatte ich auch mal hier aus dem Forum und konnte es zwar bezüglich der Formatierung und der Felder umschreiben aber das mit dem getnextDocument kriege ich nicht hin. Weiß jemand von euch rat?
Sub Initialize
Dim ws As New NotesUIWorkspace
Dim s As New NotesSession
Dim collection As NotesDocumentCollection
Set db = s.CurrentDatabase
Set db = s.CurrentDatabase
' On Error Goto Initialize_Error
Set collection = db.UnprocessedDocuments
' Start link to Excel
Set XLApp = CreateObject("excel.application")
If XLApp Is Nothing Then
Error XLAPP_NOT_STARTED
End If
' Add the worksheet
XLApp.Workbooks.Add
Set XLBook = XLApp.Workbooks(XLApp.ActiveWorkbook.Name)
Set Sheet1 = XLBook.Worksheets(1)
Sheet1.Name = "Test_Financials"
intcurrow = 1
Sheet1.Cells(intCurRow, 1).Value = "Project Name"
Sheet1.Cells(intCurRow, 2).Value = "Revenue Increase 2003"
Sheet1.Cells(intCurRow, 3).Value = "Revenue Increase 2004"
Sheet1.Cells(intCurRow, 4).Value = "Revenue Increase 2005"
Sheet1.Cells(intCurRow, 5).Value = "Revenue Increase FY"
Sheet1.Cells(intCurRow, 6).Value = "Cost Saving 2003"
Sheet1.Cells(intCurRow, 7).Value = "Cost Saving 2004"
Sheet1.Cells(intCurRow, 8).Value = "Cost Saving 2005"
Sheet1.Cells(intCurRow, 9).Value = "Cost Saving FY"
Sheet1.Cells(intCurRow, 10).Value = "Investment 2003 Q1"
Sheet1.Cells(intCurRow, 11).Value = "Investment 2003 Q2"
Sheet1.Cells(intCurRow, 12).Value = "Investment 2003 Q3"
Sheet1.Cells(intCurRow, 13).Value = "Investment 2003 Q4"
Sheet1.Cells(intCurRow, 14).Value = "Investment 2004 Q1"
Sheet1.Cells(intCurRow, 15).Value = "Investment 2004 Q2"
Sheet1.Cells(intCurRow, 16).Value = "Investment 2004 Q3"
Sheet1.Cells(intCurRow, 17).Value = "Investment 2004 Q4"
Sheet1.Cells(intCurRow, 18).Value = "Investment 2005 Q1"
Sheet1.Cells(intCurRow, 19).Value = "Investment 2005 Q2"
Sheet1.Cells(intCurRow, 20).Value = "Investment 2005 Q3"
Sheet1.Cells(intCurRow, 21).Value = "Investment 2005 Q4"
Sheet1.Cells(intCurRow, 22).Value = "Investment FY"
Sheet1.Cells(intCurRow, 23).Value = "Operating Cost 2003 Q1"
Sheet1.Cells(intCurRow, 24).Value = "Operating Cost 2003 Q2"
Sheet1.Cells(intCurRow, 25).Value = "Operating Cost 2003 Q3"
Sheet1.Cells(intCurRow, 26).Value = "Operating Cost 2003 Q4"
Sheet1.Cells(intCurRow, 27).Value = "Operating Cost 2004 Q1"
Sheet1.Cells(intCurRow, 28).Value = "Operating Cost 2004 Q2"
Sheet1.Cells(intCurRow, 29).Value = "Operating Cost 2004 Q3"
Sheet1.Cells(intCurRow, 30).Value = "Operating Cost 2004 Q4"
Sheet1.Cells(intCurRow, 31).Value = "Operating Cost 2005 Q1"
Sheet1.Cells(intCurRow, 32).Value = "Operating Cost 2005 Q2"
Sheet1.Cells(intCurRow, 33).Value = "Operating Cost 2005 Q3"
Sheet1.Cells(intCurRow, 34).Value = "Operating Cost 2005 Q4"
Sheet1.Cells(intCurRow, 35).Value = "Operating Cost FY"
intcurrow = 2
' Create the worksheet
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
CreateSheet
Next
Sheet1.Range("A1", "AJ1").Select
xlapp.Selection.Font.Bold = True
xlapp.Selection.Font.Size = 8
xlApp.Selection.Font.ColorIndex = 5
Sheet1.Range("B1", "AJ1").Select
xlapp.Selection.HorizontalAlignment = 3
XlApp.Range("A1:AJ1").Select
With Xlapp.Selection
.Borders(1).Weight = 2
.Borders(2).Weight = 2
.Borders(3).Weight = 2
.Borders(4).Weight = 2
End With
XlApp.Range("A2:AJ2" & Trim(Str(Cell))).Select
With XlApp.Selection
.Borders(1).Weight = 1
.Borders(2).Weight = 1
.Borders(3).Weight = 1
.Borders(4).Weight = 1
End With
Sheet1.Range("A1", "AJ" + Cstr (intcurrow)).Select
XlApp.Columns(1).Columnwidth = 40
XlApp.Columns(2).Columnwidth = 8
XlApp.Columns(3).Columnwidth = 8
XlApp.Columns(4).Columnwidth = 8
XlApp.Columns(5).Columnwidth = 8
XlApp.Columns(6).Columnwidth = 8
XlApp.Columns(7).Columnwidth = 8
XlApp.Columns(8).Columnwidth = 8
XlApp.Columns(9).Columnwidth = 8
XlApp.Columns(10).Columnwidth = 10
XlApp.Columns(11).Columnwidth = 10
XlApp.Columns(12).Columnwidth = 10
XlApp.Columns(13).Columnwidth = 10
XlApp.Columns(14).Columnwidth = 10
XlApp.Columns(15).Columnwidth = 10
XlApp.Columns(16).Columnwidth = 10
XlApp.Columns(17).Columnwidth = 10
XlApp.Columns(18).Columnwidth = 10
XlApp.Columns(19).Columnwidth = 10
XlApp.Columns(20).Columnwidth = 10
XlApp.Columns(21).Columnwidth = 10
XlApp.Columns(22).Columnwidth = 8
XlApp.Columns(23).Columnwidth = 8
XlApp.Columns(24).Columnwidth = 8
XlApp.Columns(25).Columnwidth = 8
XlApp.Columns(26).Columnwidth = 8
XlApp.Columns(27).Columnwidth = 8
XlApp.Columns(28).Columnwidth = 8
XlApp.Columns(29).Columnwidth = 8
XlApp.Columns(30).Columnwidth = 8
XlApp.Columns(31).Columnwidth = 8
XlApp.Columns(32).Columnwidth = 8
XlApp.Columns(33).Columnwidth = 8
XlApp.Columns(34).Columnwidth = 8
XlApp.Columns(35).Columnwidth = 8
XlApp.Columns(36).Columnwidth = 8
xlApp.Columns(2).Wraptext = True
xlApp.Columns(3).Wraptext = True
xlApp.Columns(4).Wraptext = True
xlApp.Columns(5).Wraptext = True
xlApp.Columns(6).Wraptext = True
xlApp.Columns(7).Wraptext = True
xlApp.Columns(8).Wraptext = True
xlApp.Columns(9).Wraptext = True
xlApp.Columns(10).Wraptext = True
xlApp.Columns(11).Wraptext = True
xlApp.Columns(12).Wraptext = True
xlApp.Columns(13).Wraptext = True
xlApp.Columns(14).Wraptext = True
xlApp.Columns(15).Wraptext = True
xlApp.Columns(16).Wraptext = True
xlApp.Columns(17).Wraptext = True
xlApp.Columns(18).Wraptext = True
xlApp.Columns(19).Wraptext = True
xlApp.Columns(20).Wraptext = True
xlApp.Columns(21).Wraptext = True
xlApp.Columns(22).Wraptext = True
xlApp.Columns(23).Wraptext = True
xlApp.Columns(24).Wraptext = True
xlApp.Columns(25).Wraptext = True
xlApp.Columns(26).Wraptext = True
xlApp.Columns(27).Wraptext = True
xlApp.Columns(28).Wraptext = True
xlApp.Columns(29).Wraptext = True
xlApp.Columns(30).Wraptext = True
xlApp.Columns(31).Wraptext = True
xlApp.Columns(32).Wraptext = True
xlApp.Columns(33).Wraptext = True
xlApp.Columns(34).Wraptext = True
xlApp.Columns(35).Wraptext = True
xlApp.Columns(36).Wraptext = True
xlApp.Columns(1).VerticalAlignment = 1
xlApp.Columns(2).VerticalAlignment = 1
xlApp.Columns(3).VerticalAlignment = 1
xlApp.Columns(4).VerticalAlignment = 1
xlApp.Columns(5).VerticalAlignment = 1
xlApp.Columns(6).VerticalAlignment = 1
xlApp.Columns(7).VerticalAlignment = 1
xlApp.Columns(8).VerticalAlignment = 1
xlApp.Columns(9).VerticalAlignment = 1
xlApp.Columns(10).VerticalAlignment =1
xlApp.Columns(11).VerticalAlignment =1
xlApp.Columns(12).VerticalAlignment =1
xlApp.Columns(13).VerticalAlignment =1
xlApp.Columns(14).VerticalAlignment =1
xlApp.Columns(15).VerticalAlignment =1
xlApp.Columns(16).VerticalAlignment =1
xlApp.Columns(17).VerticalAlignment =1
xlApp.Columns(18).VerticalAlignment =1
xlApp.Columns(19).VerticalAlignment =1
xlApp.Columns(20).VerticalAlignment =1
xlApp.Columns(21).VerticalAlignment =1
xlApp.Columns(22).VerticalAlignment =1
xlApp.Columns(23).VerticalAlignment =1
xlApp.Columns(24).VerticalAlignment =1
xlApp.Columns(25).VerticalAlignment =1
xlApp.Columns(26).VerticalAlignment =1
xlApp.Columns(27).VerticalAlignment =1
xlApp.Columns(28).VerticalAlignment =1
xlApp.Columns(29).VerticalAlignment =1
xlApp.Columns(30).VerticalAlignment =1
xlApp.Columns(31).VerticalAlignment =1
xlApp.Columns(32).VerticalAlignment =1
xlApp.Columns(33).VerticalAlignment =1
xlApp.Columns(34).VerticalAlignment =1
xlApp.Columns(35).VerticalAlignment =1
xlApp.Columns(36).VerticalAlignment =1
With XlApp.Worksheets(1)
.PageSetup.Zoom = 60
.PageSetup.Orientation = 2
.PageSetup.PrintTitleRows = "$1:$1"
.Pagesetup.centerheader="Test Financials- Confidential"
.Pagesetup.RightFooter = "Page &P" & Chr$(13) & "Date: &D"
.Pagesetup.CenterFooter = ""
End With
Print "Saving excel spreadsheet as C:\Test_Financials.xls"
XLBook.SaveAs ("C:\Test_Financials.xls")
Sheet1.Range("A2").Select
xlApp.Visible = True
' XLBook.Close
Initialize_Exit:
' XLApp.Quit
' Set Sheet1 = Nothing
' Set XLBook = Nothing
' Set XLApp = Nothing
' Print "Completed"
Exit Sub
Initialize_Error:
Beep
Select Case Err
Case XLAPP_NOT_STARTED
strErrMsg = "Excel Application could not be started."
Case TEMP_FILE_PATH_NOT_SPECIFIED
strErrMsg = "A 'Temporary File Path' entry was not found in the Keywords view."
Msgbox "The following error occurred in the Worksheet Process." & CRLF & "Error No. " & Cstr(Err) & " - " & strErrMsg,,"An Application Error Has Occurred"
Resume Initialize_Exit
End Sub
-
Dann kannst du :
For i = 1 To collection.Count
Set doc = collection.GetNthDocument( i )
CreateSheet
Next
ersetzen durch:
Set doc = collection.GetFirstDocument
If Not doc Is Nothing Then
CreateSheet
Set doc = collection.GetNextDocument (doc)
End If
eknori
-
Super Eknori, Danke das funktioniert.
Gruß
Holger
-
Hallo
ich bin es nochmal, habe jetzt doch ein Problem, der Agent export mir jetzt nur noch ein Dokument nach Excel obwohl ca. 15 in der Db stehen. Vorher hat er alle exportiert, woran könnte das liegen?
Gruß
-
ich kenne eknori´s IF Schleifenkonstrukt zwar so noch nicht, aber nimm mal zB stattdessen eine WHILE Schleife
While Not (doc Is Nothing)
CreateSheet...
....
Set doc = collection.GetNextDocument (doc)
Wend
dann springt beim "set doc=..." die Vearbeitung wieder ins "While Not..", bis eben kein Doc mehr gefunden wird zum abarbeiten.
-
@Rob: uupps; hatte ich do aus der Designer Hilfe kopiert :-[ :-[
-
... die GetNthDocument-Methode kann besser noch mit For-Next und GetFirstDocument-GetNextDocument() ersetzt werden.
Dim i As long
Set doc = collection.GetFirstDocument
For i = 1 to dc.Count
' # ... dein Code
Set doc = collection.GetNextDocument(doc)
Next
... das ist von der Performance her gesehen der beste Weg, vor allem, wenn in der Collection viele Dokumente sind...
ata
-
... das ist von der Performance her gesehen der beste Weg, vor allem, wenn in der Collection viele Dokumente sind...
@ata
Da muß ich dir aber widersprechen. Ich habe in verschiedenen Artikel zur Performance bei Notes-Datenbanken und -Programmierung gelesen, dass GetFirstDocument/GetNextDocument dem GetNthDocument von der Geschwindigkeit weit überlegen sei, besonder bei Collections mit vielen Dokumenten.
Schau mal hier. Achte besonders mal auf die Zeiten.
http://www.atnotes.de/index.php?board=9;action=display;threadid=3039;start=0 (http://www.atnotes.de/index.php?board=9;action=display;threadid=3039;start=0)
Axel
-
wieso ?
das arbeitet doch mit getFirstDocument, getNextDocument
Das einzige seltsame ist IMHO
For i = 1 to dc.Count
Ich glaube
do while doc is Nothing ' oder so ähnlich
ist gebräuchlicher und vermutlich auch schneller.
-
Hi,
hast recht. Ich hab nur das For i = .... gelesen
Axel
-
@Axel
... genau das habe ich ja geschrieben...
@Axel_Janssen
... For i = 1 to dc.Count ist besser, denn es wird eine klare Anzahl durchlaufen. While ... Wend ist sehr weit verbreitet, aber nicht unbedingt schneller, da eine fortwährende Überprüfung der Bedingung bei jedem Teilschritt innerhalb geführt werden muß. Was das in Sekunden bedeutet kann ich nicht sagen. Der von mir beschriebene Weg ist der effizienteste den ich kenne...
ata
-
@ata, wie schreibt sich eknoris Sig:
Every little programming improvement means nothing, but
the sum of all the little improvements is what makes the difference.
Bingo :)
Ich werde in Zukunft statt dem While die For Schleife verwenden, hast Recht. Wenn denn der Check auf eine While Bedingung mit "doc is nothing" wirklich nicht schneller als der Check auf einen maximalen Count ist. Ich "befürchte" aber fast, daß "Nothing" schneller zu checken ist, als ein Integer, da es weniger Speicher einnimmt (denk ich mal) und die Bedingungsüberprüfung dadurch etwas schneller läuft. Eine Integer Zahl muß ja vom Prozessor zerlegt werden und bit für bit verglichen werden. Ein Nothing...tja, wenn ich das wüßt.
Hier die Definition von Nothing:
the initial value of an object reference variable. As soon as you assign a specific reference to the variable, the variable no longer contains NOTHING. You can explicitly assign the value NOTHING to an object reference variable. To test a variable for the NOTHING value, use the Is operator
Ich denke, daß damit recht klar sein müßte, daß eine For Schleife etwas langsamer als ein While Schleife sein sollte, gerade weil ein Test auf eine nicht referenzierte Objektvariable nur True/False sein kann, was technisch gesprochen weniger CPU Schritte beim Vergleich bedeutet als ein count gegen einen max count (bitweiser Vergleich zweier Integerzahlen).
-
... ich hatte mal testweise verschiedeneKonstrukte mit der Zeit verglichen. Ich benutzte anstelle von Integer einen Long als Zählervariable und war geringfügig schneller mit For... Next
ata
-
Man könnte das ja mal mit der StopWatch-Klasse aus dem View-Artikel zu Performance-Messung (ist etwa 2 Jahre her, denke ich) ja mal explizit nachmessen.
Ich tendiere allerdings wie ata zur For-Schleife. Gecheckt werden muss da ja in jedem Durchgang überhaupt nichts, die Schleife läuft einfach so lange durch, wie man anfangs definiert hat. Und die Berechnung der Count-Eigenschaft dürfte rechenzeitmäßig quasi umsonst sein, da die garantiert (das ist meine persönliche Vermutung) schon bei der Erzeugung des dc-Objekts berechnet wird.
-
hab eine Information bekommen, daß auf der Lotus Devcon (soll angeblich in Vegas 2000 gewesen sein) die Aussage gemacht wurde, daß While Wend schneller sind.
-
laut Redbook => sg245602.pdf
Use For Loops Instead of Do Loops or While Loops
For loops are faster than Do loops and While loops because the condition that bounds the Do or While loop must be evaluated at each iteration of the loop. In the following example, the first fragment runs 60 percent faster than the
second fragment.
Fragment A
For y = 1 to 15000
z = z+1
Next
Fragment B
Do
z = z+1
y = y+1
Loop While y <= 15000
The performance savings occur because the looping overhead is minimized in the For case. If your loop does a lot of work, the actual performance improvement will be less than the 60 percent mentioned since the looping overhead becomes a smaller fraction of the total loop time.
########
Use Forall Instead of For in Referencing Array Elements
Forall loops are faster in handling arrays than For loops.
Forall is 75 percent faster than For when referencing all elements in a 1-dimensional numeric array, and 50 percent faster when referencing elements in a 2-dimensional array. Similar performance improvements occur in arrays with higher numbers of dimensions. String arrays achieve somewhat less performance improvement than numeric arrays, but these are still significant.
cu
-
For i = 1 to dc.Count
würde ich auch immer dann verwenden, wenn ich mit einer col arbeite; denn da wird der Count intern bereits beim Füllen der Col ermittelt
do while doc is Nothing
ist wohl noch ein Relikt aus der Zeit, als es noch Keine ViewEntryCollection gab.
da mußte dann in der Tat die komplette View durchlaufen werden, da man ja nie wissen konnte, wie viele docs in der View sind.
Aber abei der NotesViewEntryClass gibt es ja auch die Property Count. Sollte dann auch performanter sein.
eknori
-
gutes Zitat, Perfomance und sehr hilfreich denke ich.
Nur in dem Falle eines Loops durch Docs zählt das Beispiel oben nicht, weil der While Loop einen zusätzlichen Rechen Step beinhaltet, den das For so nicht hat. Das Ergebnis ist natürlich dann nicht mehr überraschend.
Hab selbst aufgrund des Tips von Flamme und harkpabst aus The View die StopWatch Klasse genommen und folgende Codes über 25000 Docs miteinander verglichen und kam auf folgendes Ergebis vorab, daß die While bei insgesamt á 10 Läufen idR zwischen 1.5 und 2 Sekunden schneller war. Dabei hat die FOR Schleife immer im Bereich GetNextDocument "an Boden verloren". Das spiegelt mE meine Annahme wider, daß ein Check auf True/False (mit "is Doc nothing") schneller als ein Check auf einen Schleifendurchlauf Zähler ist (For i=1 to viewcoll.count). Der Code ist bei beiden total identisch, außer dem Schleifenrumpf. Fairerweise bilde ich bei beiden den ViewCollection.Count, obwohl ich das bei While nicht bräuchte.
For Schleife ("exemplarisch" 1 aus 10)
seconds % calls secs/call event
===========================================================================
00054,691 100,0% 0000001 00054,691 Total run time
00033,586 061,4% 0025318 00000,001 Process Document
00012,577 023,0% 0025318 00000,000 GetNextDocument
00000,000 000,0% 0000001 00000,000 GetFirstDocument
WHILE Schleife ("exemplarisch" 1 aus 10)
seconds % calls secs/call event
===========================================================================
00052,323 100,0% 0000001 00052,323 Total run time
00032,758 062,6% 0025318 00000,001 Process Document
00011,944 022,8% 0025318 00000,000 GetNextDocument
00000,000 000,0% 0000001 00000,000 GetFirstDocument
Der Code für FOR und WHILE im Kopfbereich 100% identisch:
Dim stopwatch As Stopwatch
Dim session As NotesSession
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim count As Integer
Dim vcentries As Integer
Set stopwatch = New Stopwatch
Set session = New NotesSession
Set db = session.CurrentDatabase
Set view = db.GetView("LoopTest")
count = 0
Dim vc As NotesViewEntryCollection
Set vc = view.AllEntries
vcentries = vc.count
Call stopwatch.Start("GetFirstDocument")
Set doc = view.GetFirstDocument
Call stopwatch.Stop("GetFirstDocument")
UND hier die For Schleife (Code oben und dieser Part im Agent No.1, separat angestoßen)
For i=1 To vcentries
Call stopwatch.Start("Process Document")
count = count + 1
Print Cstr(count)
Call stopwatch.Stop("Process Document")
Call stopwatch.Start("GetNextDocument")
Set doc = view.GetNextDocument(doc)
Call stopwatch.Stop("GetNextDocument")
Next
UND hier die WHILE Schleife (Code oben und dieser Part im Agent No.2, separat angestoßen)
While (Not doc Is Nothing)
Call stopwatch.Start("Process Document")
count = count + 1
Print Cstr(count)
Call stopwatch.Stop("Process Document")
Call stopwatch.Start("GetNextDocument")
Set doc = view.GetNextDocument(doc)
Call stopwatch.Stop("GetNextDocument")
Wend
Womit bewiesen wäre, daß Notes nicht immer Notes ist, eine For Schleife nicht immer schneller als eine While und eine While nicht immer schneller als eine For und Statistiken eben Statistiken sind.
Unterzeichnet "Gruppe der hebräischen While Volksfront"
-
Otternasen, köstliche Otternasen !!
-
;D ;D 8) 8)
sollten wir nicht mal ein Treffen machen mit VideoBeilagen á la Monty?
-
@Rob
traue nie einer Statistik, ausser sie ist von dir selbst erstellt worden.
;-)
cu
-
;D 8) ;D
-
@Rob
traue nie einer Statistik, ausser sie ist von dir selbst erstellt worden.
;-)
cu
...oder anders herum:
Traue nie einer Statistik, di du nicht selbst gefälscht hast. ;D ;)
Axel