Hallo,
ich versuche ein Array mit Datumwerten zu füllen.
Vorgabe ist ein Von- und ein Bis-Datum. In einer Schleife soll dann das Array gefüllt werden:
Dim aDates() As NotesDateTime, vdate As NotesDateTime, bdate As NotesDateTime
Dim i As Integer
Set vdate = New NotesDateTime("15.03.2011")
Set bdate = New NotesDateTime("17.03.2011")
ReDim aDates(0)
Set aDates(0) = vdate
vdate.Adjustday(1)
i = 0
While vdate.Dateonly <= bdate.Dateonly
If (Weekday(vdate.Dateonly) <> 7) And (Weekday(vdate.Dateonly) <> 1) Then
i = i + 1
ReDim Preserve aDates(UBound(aDates) + 1)
Set aDates(UBound(aDates)) = vdate
End If
vdate.Adjustday(1)
Wend
Call doc.ReplaceItemValue( "CalendarDateTime", aDates)
Was aber herauskommt ist dreimal der 18.03.2011.
Als wenn er beim Eintragen in den Array nicht den tatsächlichen Wert, sondern die Referenz auf die Variable einträgt.
Beim Beenden der Schleife entspricht vdate ja dem 18.03.2011.
Muss ich hier mit einer Hilfsvariable arbeiten oder wie?
Oder:
Set aDates(UBound(aDates)) = New NotesDateTime(vdate.DateOnly)
Bei der letzten Zeile
Call doc.ReplaceItemValue( "CalendarDateTime", aDates)
ist mir allerdings neu, dass das funktioniert, da aDates ja NotesDateTime-Objekte enthält und mir war / ist nicht klar, dass diese direkt dem Feld zugeordnet werden können ?!?
Gruß
Marco
Ich habe das Ganze mal auf die Schnelle angepasst und in einen Button innerhalb der Maske gelegt und es funktioniert.
Dim ws As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim aDates() As Variant, vdate As NotesDateTime, bdate As NotesDateTime
Dim i As Integer
Set uidoc = ws.CurrentDocument
Set doc = uidoc.Document
Set vdate = New NotesDateTime("15.03.2011")
Set bdate = New NotesDateTime("17.03.2011")
Redim aDates(0)
aDates(0) = vdate.DateOnly
vdate.Adjustday(1)
i = 0
While vdate.Dateonly <= bdate.Dateonly
If (Weekday(vdate.Dateonly) <> 7) And (Weekday(vdate.Dateonly) <> 1) Then
i = i + 1
Redim Preserve aDates(Ubound(aDates) + 1)
aDates(Ubound(aDates)) = vdate.DateOnly
End If
vdate.Adjustday(1)
Wend
Call doc.ReplaceItemValue( "CalendarDateTime", aDates)
Call uidoc.Refresh
Axel
Bernhard,
das dürfte leicht zu lösen sein über
aDates(Ubound(aDates)) = vdate.LSLocalTime
Gruß
Marco
Date/Time ist wohl wirklich nicht so mein Fall.... :-:
Wenn ich Bernhards Beispiel versuche umzusetzen, erhalte ich einen Type Mismatch in der For-Schleife:
Ich denke, dass die For-Schleife so nur für numerische Werte funktioniert?
Dim aDates() As Variant
Dim vStart As Variant
Dim vEnd As Variant
Dim vLoop As Variant
Set vdate = New NotesDateTime("15.03.2011")
Set bdate = New NotesDateTime("18.03.2011")
Set vStart = vdate
Set vEnd = bdate
For vLoop = vStart To vEnd Step 1
ReDim Preserve aDates(UBound(aDates) + 1)
Set aDates(UBound(aDates)) = vLoop
Next
Call doc.ReplaceItemValue( "CalendarDateTime", aDates)
Und ich war mir soo sicher, dass folgender Code funktionieren würde (erzeugt aber auch nur einen leeren CalendarDateTime):
argvdat = "15.03.2011", argbdat = "17.03.2011"
Dim aDates() As Variant
Set vdate = New NotesDateTime(argvdat)
Set bdate = New NotesDateTime(argbdat)
ReDim aDates(0)
Set aDates(0) = New NotesDateTime(argvdat & " " & starttime)
vdate.Adjustday(1)
While vdate.Dateonly <= bdate.Dateonly
If (Weekday(vdate.Dateonly) <> 7) And (Weekday(vdate.Dateonly) <> 1) Then
ReDim Preserve aDates(UBound(aDates) + 1)
Set aDates(UBound(aDates)) = New NotesDateTime(CStr(vdate.DateOnly) & " " & starttime)
End If
vdate.Adjustday(1)
Wend
Call doc.ReplaceItemValue( "CalendarDateTime", aDates)