Search code examples
lotus-noteslotusscript

Lotusscript - Type mismatch when useing ArrayGetIndex


I have a function where I check if a string is found in a variant:

Function checkIfValueIsInVariant (tempVariant As Variant, tempValue As String) As Boolean
    Dim valueFound As Boolean

    'zet standaard waarde op niet gevonden
    valueFound = False
    Print "Value : " + tempValue
    If Not IsNull( ArrayGetIndex(tempVariant, tempValue) ) Then
            'waarde is gevonden in variant dus zet op true
            valueFound = true
    End If
        checkIfValueIsInVariant = valueFound
End Function

When I go through the code with the debugger then I can see these values:

tempVariant = "value" type = Variant
tempValue = "value" type = String

But when it is executing this line:

`If Not IsNull( ArrayGetIndex(tempVariant, tempValue) )` Then

I get Type mismatch, What am I doing wrong?


Solution

  • Variant is a very bad data type in LotusScript: it can contain anything. ArrayGetIndex expects the first parameter to be An array or Variant containing an array.. In your example tempvariant is a Variant of type string and NOT an array --> Type mismatch.

    If I don't know, if I get a scalar or an array in before then usually I write something like that in my code:

    Dim varArray as Variant
    Dim arrOneElement(0) as Variant
    
    
    If not IsArray( tempVariant ) then
        arrOneElement(0) = tempVariant
        varArray = arrOneElement
    Else
        varArray = tempVariant 
    End If
    If Not IsNull( ArrayGetIndex(varArray, tempValue) ) Then
    

    That way I can put in there (almost) whatever I want and it will return the correct result.