-1

I don't know where I'm wrong but I kept on getting "Type mismatch" error

Here is the original code

    Dim policy As New Policy
    Dim policyDocument As NotesDocument

    Set policyDocument = p_baseManager.base_policyDocument
    policy.formName = policyDocument.Getitemvalue("Form")(0)    //Had type mismatch error on this line
    policy.universalId = policyDocument.Universalid
    policy.formX = policyDocument.Getitemvalue("FormX")(0)

I tried to modify it a bit to display some of the values

    Dim policy As New Policy
    Dim policyDocument As NotesDocument

    Set policyDocument = p_baseManager.base_policyDocument
    Print "universal id = " + policyDocument.Universalid
    Print "FORM NAME = " + policy.formName
    policy.formName = "FormName"
    Print "FORM NAME = " + policy.formName
    policy.formName = policyDocument.Getitemvalue("Form")(0)     // still getting type mismatch
    policy.universalId = policyDocument.Universalid
    policy.formX = policyDocument.Getitemvalue("FormX")(0)

Thank you!

  • p_baseManager is not a built in class, but something custom. Nobody here can tell you, if p_baseManager.base_policyDocument returns a NotesDocument Object AND is not nothing... no help possible without more code. And Policy by the way is also a custom class: nobody knows, what formName Property of this class expects and if in „Form“ item of your policy document there is really a string (if thats expected) – Tode Mar 10 '20 at 17:13

2 Answers2

0

Adding error handling is the best way to find out where the error is occurring. The type mismatch will be data-specific, so it's going to be difficult to troubleshoot without having access to the environment. The best library for error handling in LotusScript is beyond all doubt OpenLog.

Paul Stephen Withers
  • 15,699
  • 1
  • 15
  • 33
0

Ok, lets analyze this using your "DEBUG"- Code. We have two custom classes that we know nothing about:

Class name: Policy Instance: policy

and Class name: ??? Instance: p_baseManager

Then we have the line that throws the error:

policy.formName = policyDocument.Getitemvalue("Form")(0)

From your Test- Line

policy.formName = "FormName"

we know, that policy.formName accepts a String as an input and that the left side of our erroneous line does throw an error in itself.

Now, if we have a "Type mismatch" that means that our right part of the assignment does not return a string.

If p_baseManager.base_policyDocument did not return a valid NotesDocument, then we would get an Object variable not set in that line --> We can conclude, that policyDocument is a valid NotesDocument and not Nothing.

Now lets look at GetItemValue("Form"): It returns an Empty String, if the document does not contain an item named "Form": An empty String still is a String --> No Type Mismatch in that case.

The only possibility, that policyDocument.Getitemvalue("Form")(0) does not return a String, is, if the item is present but contains a number or a date value...

So: What to do now?

First of all: Are you SURE that the error is in that line (did you use Debugger)?
Second: Use the debugger to find out the value of the Form- Item of your PolicyDocument
Third: As mentioned by Paul Stephen Withers: Use error handling to EXACTLY identify the error line, error code and error.

Tode
  • 11,795
  • 18
  • 34