Das Notes Forum

Domino 9 und frühere Versionen => ND8: Entwicklung => Thema gestartet von: lucy123 am 06.03.15 - 08:57:04

Titel: Fehler bei Berechnung
Beitrag von: lucy123 am 06.03.15 - 08:57:04
Hallo zusammen,

ich möchte eine Feldberechnung durchführen, die mir sagt, wieviel Tage zwischen der Erstellung (DOM1a) und des aktuellen Datum (dtnow) liegen.
Leider klappt das  nur, wenn DOM1a befüllt ist. Sobald ein Eintrag fehlt, steigt das Script aus.
Wo liegt mein Fehler?

Gruß Willi

On Error GoTo errHandler
   Dim strTitle As String
   Dim strError As String
   Dim strServer As String
   Dim strDatabase As String
   Dim session As New NotesSession
   Dim db As NotesDatabase
   Dim collection As NotesDocumentCollection
   Dim doc As NotesDocument
   Dim doc2 As NotesDateTime
   Set db = session.CurrentDatabase
   strTitle=db.Title   
   Dim intCount1 As Integer
   Dim intCount2 As Integer
   Dim searchFormula As String   
   searchFormula$ = {Form = "MGrund" & Ebene1 = "Lotus Notes" & !( }
   searchFormula$ = searchFormula & {(Status2 = "EIN") |(Status2 = "CALL") | (fertig_B1="LÖSCH") }
   searchFormula$ = searchFormula & { |(Ges_N2=1 & Ges_N3=1) |(Ges_N2=2 & Ges_N3=2) | (Ges_N2=3 & Ges_N3=3)  }
   searchFormula$ = searchFormula & { |(Ges_N2=4 & Ges_N3=4) |(Ges_N2=5 & Ges_N3=5) }
     searchFormula$ = searchFormula & { )}      
   Set collection = db.Search(searchFormula$, Nothing,0)

   'Hier meldet der Agent 4288 - Property must be of type Date

       Set doc = collection.GetFirstDocument()
   Do While Not(doc Is Nothing)
      Dim dtDOM1a As NotesDateTime
      Dim dtNow As NotesDateTime
      Dim intDifference As Double         
         Set dtNow = New NotesDateTime( Now() )
         Set dtDOM1a = New NotesDateTime( "" )
         dtDOM1a.LSLocalTime = doc.DOM1a(0)
         intDifference = dtNow.TimeDifference(dtDOM1a )       
      intDifference = intDifference /(86400)
      doc.FIELDVIEW49 = intDifference                     
         If intDifference > 30 Then
            doc.FIELDVIEW50 = 92
         Else
            doc.FIELDVIEW50 = 83
         End If      
      Call doc.Save( False, True )
         intCount1=intCount1+1      
         Set doc = collection.GetNextDocument(doc)
   Loop         
         strError = "Aktualisierung ausgewählte Datensätze" +Chr(13)+Chr(10)
         strError = strError + "=========================================="+Chr(13)+Chr(10)
         strError = strError + "Datensätze Teil 1 aktualisiert: "+Trim(Str(intCount1)) + Chr(13)+Chr(10)
         strError = strError + "Datensätze Teil 2 aktualisiert: "+Trim(Str(intCount2)) + Chr(13)+Chr(10)   
         WriteAgentLog (strError)
OutOfHere:   
   Exit Sub   
errHandler:   
   strError = strError + "Fehler [Zeile " + Trim$ (Str$ (Erl())) + "] " +  Trim$ (Str$ (Err)) + " - " + Error$
   WriteAgentLog (strError)   
   Resume OutOfHere      
End Sub
Titel: Re: Fehler bei Berechnung
Beitrag von: Andrew Harder am 06.03.15 - 09:33:32
Code
dtDOM1a.LSLocalTime = doc.DOM1a(0)
Wenn das Feld nicht gesetzt ist, dann kommt da ein Leerstring zurück und der ist nun mal definitiv kein Datum.

Noch eine Anmerkung ist nicht bös gemeint...
Code
Dim intDifference As Double         
...
intDifference = dtNow.TimeDifference(dtDOM1a )
Du nennst eine Variable intDifference, deklarierst Sie als Double und rufst dann eine Funktion auf, welche dort einen Long zurück gibt.
Etwas viel an Datentypen ;)