gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 16:11:39 26 4
gpt4 key购买 nike

我试图自己解决这个问题,但也许我对方式有误解 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com