以前用lotus domino为客户写的办公自动化程序,出了问题
发现用lotus的@contains函数存在问题,当要判断的字符串太大时,就会报错.
这是以前的写法:
NotesMacro$="@contains("""+sendto+""";"","")"
Dim flag As Variant
flag=Evaluate(NotesMacro$) '当sendto很大时,这句话会报错误,导致执行不下去
'当发送多个用户时,先将文本串转换成文本列表,在赋值
If flag(0) Then
NotesMacro$ = "@Explode("""+sendto+""";"","")"
mailDoc.sendto =Evaluate(NotesMacro$)
Else
mailDoc.sendto=sendto
End If
这是修改后的写法:
先写一个分割字符串的函数:
Function ParseString(StringToParse As String,Delim As String) As Variant
' Returns an array containing the results of parsing
' a string based on the specified delimiter.
' If StringToParse or Delim is empty returns Null
' If Len(Delim) >= Len(StringToParse returns Null
' If StringToParse does not contain the delimiter, returns
' the entire string.
Dim a() As String
Dim s As String
Dim DelimPos As Integer
Dim count As Integer
If Len(StringToParse) = 0 Or Len(Delim) = 0 Then
ParseString = Null
Exit Function
End If
If Len(Delim) >= Len(StringToParse) Then
ParseString = Null
Exit Function
End If
DelimPos = Instr(1, StringToParse, Delim)
If DelimPos = 0 Then
Redim a(0)
a(0) = StringToParse
ParseString = a
Exit Function
End If
s = StringToParse
count = 0
Do
Redim Preserve a(count)
a(count) = Left(s, DelimPos - 1)
s = Right(s, Len(s) - (DelimPos + Len(Delim) - 1))
count = count + 1
DelimPos = Instr(1, s, Delim)
If DelimPos = 0 Then
Redim Preserve a(count)
a(count) = s
s = ""
End If
Loop Until Len(s) = 0
ParseString = a
End Function
然后将上面的语句修改为:
mailDoc.sendto=ParseString(sendto,",")
问题解决!