2011-02-05 64 views
1

我從一個視圖訪問的文檔上,讀出的日期時間字段,弄清楚的天數,其分爲四類兩個日期/時間值之間。在每個類別中都有一個for循環,它將一系列日期時間值添加到變體數組中。數組條目介於7到35之間。循環之後,我喜歡將數組值賦給表單上的日期時間字段並保存文檔。我已經使用Notes項目如下:分配日期時間陣列以多值日期字段Domino表單

Dim nitem as Notesitem 
Set nitem = doc.ReplaceItemValue("Datefield", dtArray) 

它沒有工作。我用doc.ReplaceItemValue「的DateField,dtArray這一個也不能工作的字段爲空白代理運行後我聲明的變量並分配數組變量然後被分配給變量領域的形式:。

Dim var1 as variant 
var1 = dtArray 
doc.datefield = Var1 

仍然沒有運氣看到分配給該領域的文檔

在這裏,在數組值是主循環

Redim dateArray(0) 
For i=0 to NumberofDays -1 
    set notesitem = dtitem.DateTimeValue 
    call notesitem.AdjustDay(i) 
    set dateArray(i) = notesitem 
    Redim preserve dateArray(i+1) 
Next 


doc.replaceitemvalue "Datefield", dateArray 

call doc.save(false, true) 
erase dateArray 

爲什麼劑中的文件運行的DateField後的空白?缺少什麼?如何我應該改變這個來獲得結果嗎?可能嗎?到delemiter添加到賦值語句如下:

謝謝

回答

1

當你與NotesItemNotesDateTime類打轉轉,我想你會使用NotesItemDateTimeValue財產有更多的歡樂。這是讀取/寫入,並返回(或期望)一個NotesDateTime對象。

舉例來說,如果你有一個NotesDateTime例如所謂的「DT」,這是你如何將其寫回到一個名爲「YourDT」字段:

所以,你應該能夠把你的NotesDateTime對象數組,然後使用這種方法將其寫回相關字段。

0

這是棘手的麻煩拍攝的你,因爲你沒有提供的原始源代碼。你嘗試使用方法的方式有點奇怪。

下面是你要怎樣做一個基本的去。日期時間字段有點棘手,但您可以使用變體數組來設置它們。

Dim i As Integer 
    Dim vDateArr() As Variant 
    Dim itDate As notesItem 
    ' setup date array. 
    ' ......... 
    ' ......... 
    ' Now get the date field to be updated from the document 
    Set itDate = doc.GetFirstItem("fieldName") 
    ' loop through the array of values and make sure they're date time 
    For i=0 To numberOfDays - 1 
     ' ensure that the array has date type values. V_DATE is a constant defined 
     ' in LSConst.lss. V_DATE = 7, so you can still write the following line as 
     ' If Datatype(vDateArr(i)) <> 7 then 
     If Datatype(vDateArr(i)) <> V_DATE Then 
      vDate = Cdat(vDateArr(i)) 
     End If 
     vDateArr(i) = vDate 
    Next 
    ' assign the array back onto the itDate field. Even if the field is not 
    ' already a dateTime type. Assigning the array this way will make it so. 
    itDate.Values = vDateArr 
    Call doc.Save(True, False) 

我覺得最好在基本情況下工作,而不是在這種情況下的對象。這裏發生的是我確保日期值存儲爲dateTime值。然後將該數組分配給該字段,然後保存該文檔。有很多方法可以做到這一點,但是當你想將一個特定類型的數組推送到一個字段時,這是我首選的方式。如果您可以發佈原始代碼,那麼更正代碼會更容易。

1

到日期時間字段從數組指派最簡單的方法是:

SimpleDateFormat smdf = new SimpleDateFormat(); 
smdf.applyPattern("dd.MM.yyyy"); 
Vector dates = new Vector(); 
for (Date dt: dateArray) { 
     dates.addElement(smdf.formatter(dt)); 
}; 
doc.replaceItemValue("dateField", dates); 
相關問題