2

我正在从视图访问文档,读取日期时间字段,找出两个日期/时间值之间的天数,这些值分为四类。在每个类别中都有一个 for 循环,它将日期时间值的数量添加到变量数组中。数组条目介于 7 到 35 之间。在循环之后,我喜欢将数组值分配给表单上的日期时间字段并保存文档。我使用了 Notes 项目如下:

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是空白的?什么不见​​了?我应该如何改变它以获得结果。是否可以在赋值语句中添加分隔符,如下所示:

谢谢

4

3 回答 3

1

When you're playing around with NotesItem and the NotesDateTime classes, I think you will have more joy using the NotesItem DateTimeValue property. This is read / write, and returns (or expects) a NotesDateTime object.

For example, if you have a NotesDateTime instance called "dt", this is how you would write it back to a field called "YourDT":

Dim itDT as NotesItem
Dim dt as New NotesDateTime
' Instantiate itDT and dt
...
Set itDT.DateTimeValue = dt

So, you should be able to take your array of NotesDateTime objects, and write it back to the relevant field using this approach.

于 2011-02-07T12:46:29.997 回答
1

从数组中分配 dateTime 字段的最简单方法是:

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);
于 2012-08-05T08:47:09.240 回答
0

由于您没有提供原始源代码,因此很难为您排除故障。您尝试使用方法的方式有点奇怪。

以下是您正在尝试做的基本操作。DateTime 字段有点棘手,但您可以使用变体数组设置它们。

    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 值。然后将数组分配给字段,然后保存文档。有很多方法可以做到这一点,但是当您想要将特定类型的数组推送到字段中时,这是我的首选方式。如果您可以发布原始代码,则更正您的代码会更容易。

于 2011-02-09T05:45:25.900 回答