I ran into an issue with a Variant variable passed from one LotusScript class to another. (error: Type mismatch)
The code reads the first ( and only ) document in a database and gets the values from a multi value item.
The value of this item is stored in a Variant; a getter lets you access the values.
Class ConfigProvider
Public Class ConfigProvider
Private m_settings As Variant
Public Sub New
Dim session As New NotesSession
m_settings = _
FullTrim(session._
currentDatabase._
Alldocuments._
Getfirstdocument()._
Getitemvalue("settings"))
End Sub
Public Property Get Settings As Variant
Settings = m_settings
End Property
End Class
I access the ConfigProvider from within another class in a different LotusScript library. The code is invoked by an agent
Agent
Option Public
Option Declare
Use "de.eknori.config.provider"
Use "de.eknori.config.consumer"
Sub Initialize
Dim cc1 As New ConfigConsumer(1)
Dim cc2 As New ConfigConsumer(2)
Dim cc3 As New ConfigConsumer(3)
End Sub
Class ConfigConsumer
Public Class ConfigConsumer
Private m_settings As Variant
Public Sub New(flag As integer)
Dim cp As New ConfigProvider
m_settings = cp.Settings
MsgBox ""
MsgBox " -------- sample: " + CStr(flag)
Select Case flag
Case 1 : 'works
ForAll t In m_settings
MsgBox CStr(t)
End ForAll
Case 2 : 'works
Dim i As Integer
For i = 0 To UBound(cp.Settings)
MsgBox CStr(cp.Settings(i))
Next
Case 3 : 'does not work
ForAll s In cp.Settings
MsgBox CStr(s)
End ForAll
Case Else :
msgbox "Else"
End Select
End Sub
End Class
The expected behaviour is that in all cases, the code would print the values from the config document to the console, but …
te amgr run "variant.nsf" 'test' 09/03/2019 07:38:25 AM AMgr: Start executing agent 'test' in 'variant.nsf' 09/03/2019 07:38:25 AM Agent Manager: Agent message: 09/03/2019 07:38:25 AM Agent Manager: Agent message: -------- sample: 1 09/03/2019 07:38:25 AM Agent Manager: Agent message: item1 09/03/2019 07:38:25 AM Agent Manager: Agent message: item2 09/03/2019 07:38:25 AM Agent Manager: Agent message: item3 09/03/2019 07:38:25 AM Agent Manager: Agent message: 09/03/2019 07:38:25 AM Agent Manager: Agent message: -------- sample: 2 09/03/2019 07:38:25 AM Agent Manager: Agent message: item1 09/03/2019 07:38:25 AM Agent Manager: Agent message: item2 09/03/2019 07:38:25 AM Agent Manager: Agent message: item3 09/03/2019 07:38:25 AM Agent Manager: Agent message: 09/03/2019 07:38:25 AM Agent Manager: Agent message: -------- sample: 3 09/03/2019 07:38:25 AM Agent Manager: Agent 'test' error: Type mismatch 09/03/2019 07:38:25 AM AMgr: Agent 'test' in 'variant.nsf' completed execution
This is reproducible on Domino V9.x, V10.x and V11 Beta1
I have attached a small sample database, so you can test in your own environment
I wonder if it is a late binding issue where ‘s’ is defined before the type has been determined. I’d assume ForAll looks at the variant and figures out its type, but it may do it too late in the process. Hmm.
I wrote a lengthy report yesterday on this site about my test results, but it seems to have been lost somehow. The last test was with both classes in one Script library, and then everything worked. If you’re interested in the full report, please contact me.
I debugged it and changed the code slightly:
Case 3 : ‘does not work
ForAll s In cp.Settings
Dim v As Variant
v=s
MsgBox CStr(s)
End ForAll
First I got the error message ‘Type mismatch’ during the excution of v=s and then I got an ‘Out of memory’ and after the fourth run Notes crashed.
So whatever type Forall has given to ‘s’, it’s also completely incompatible with the variant type. This is most probably a bug of the Forall method.
Update:
A ‘Datatype(s)’ returned a value of 2670 , the type of ‘s’ is obviously extraterrestrial.