LotusScript – Error: Type Mismatch
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