arrays - LotusScript ArrayUnique 函数似乎不适用于日期/时间数组

标签 arrays lotus-notes lotusscript

我试图自己解决这个问题,但也许我对方式有误解 ArrayUnique作品。
这是一些样本 LotusScript 代码:

'Let's test some dates
dateOne = CDat("12/16/2010")
dateTwo = CDat("12/16/2010")
testSuccess = (dateOne = dateTwo)

'On evaluation, testSuccess = true
        
'Now let's make an array ...
Dim someArray(1) As Variant
someArray(0) = dateOne
someArray(1) = dateTwo
uniqueArray = ArrayUnique(someArray)

'uniqueArray has the same two elements ... the duplicate hasn't been removed
在上面的例子中,dateOne、dateTwo、testSuccess 和 uniqueArray 都是隐式声明的变体变量。
我究竟做错了什么?我读过 the help它说:

Usage

Elements in a variant array will only compare equal if they are of the same type. The variant array can't contain classes or objects.

Array elements that contain the null value will match other null values.

Array elements that are empty will match with other elements that are empty.


好吧,本示例中的变体数组包含日期/时间类型的变体变量。所以,如果我正确地阅读本文,我没有做错任何事情。
编辑:关于 Notes Forums ,用户 Thoms Kennedy 尝试了以下操作:

If you spell out the time component like this

dateOne = CDat("12/16/2010 04:20:17 AM")

dateTwo = CDat("12/16/2010 04:20:17 AM")

it will still treat them as distinct. There does not seem to be a millisecond component, so I would say that ArrayUnique does not know how to deal with DateTime variants.


所以他的结论是 ArrayUnique 嗯,不起作用。

最佳答案

嗯,这有效:

%REM
    Function ArrayUniqueStringCompare
    Since ArrayUnique doesn't seem to work in some cases (such as with date/time values),
    Let's convert all of the elements to string and then perform arrayunique.
    After performing unique, we can convert back to original type
    This will crash if sourceArray is not an array.
%END REM
Function ArrayUniqueStringCompare(sourceArray As Variant) As Variant
    typeOfElement$ = TypeName(sourceArray(0))
    upperLimitSource% = UBound(sourceArray)
    Dim stringArray() As String
    ReDim stringArray(upperLimitSource%)
    For i% = 0 To upperLimitSource%
        stringArray(i%) = CStr(sourceArray(i%))
    Next
    'Now get the unique values...
    uniqueArray = ArrayUnique(stringArray)
    upperLimitUnique% = UBound(uniqueArray)
    'Finally, convert the values back to their original data type
    Dim returnArray() As Variant
    ReDim returnArray(upperLimitUnique%)
    For i% = 0 To upperLimitUnique%
        If typeOfElement$ = "DATE" Then
            returnArray(i%) = CDat(uniqueArray(i%))
        End If
    Next
    ArrayUniqueStringCompare = returnArray
End Function

但这肯定不是最好的解决方案,对吧?必须有一些更好的方法让 ArrayUnique 工作......

关于arrays - LotusScript ArrayUnique 函数似乎不适用于日期/时间数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4464305/

相关文章:

javascript - 如何使用 Angular 和 ng-repeat 在 JavaScript 中创建 3D DOM?

php - 如何使用 PHP 在 MySQL 表中插入数组?

javascript - 警报显示一些 href,而其他则不显示,我想要包含该词的所有 href

javascript - 为什么 style.cursor 方法在 xPage 上不起作用?

arrays - 在 typescript 中遍历数组

Java笔记API : Create Client Session with Domino Libraries

calendar - 使用 iCalendar 在 Lotus Notes 中进行全天事件

authentication - "Logout"来自 Notes 身份验证

java - 如何以编程方式在电子邮件中发送 lotusscript?

lotus-domino - Lotus NotesStream 如何逐字符读取