Type mismatch

This error occurs when LotusScript® code tries to use a value of the wrong datatype for the context in which it is used.

This error often occurs because the code refers to a document field value (which is an array in most cases) in a situation where a scalar is expected. For example:

If doc.Subject = "" Then	' Type mismatch error!

Even if the Subject field contains only one value, the expression doc.Subject returns an array (a one-element array). You can't compare an array value with the scalar value "". The solution in this case is to refer to a specific element of the array:

If doc.Subject(0) = "" Then		' no error.

One of the following conditions could have caused this error:

  • You attempted an operation on operands with conflicting data types. For example,
5 + "-".
  • You assigned a value to a variable that has a different data type, and LotusScript® cannot convert it automatically. For example,
t% = "seven".
  • You are passing a value as an argument that has a different declared data type, and LotusScript® cannot convert it automatically.
  • You used a string as the initial value, or as the To or Step value, in a For statement.

Solution: Use the correct data type or a value that can be converted to the correct datatype. By using explicit variable declarations, for example, Dim name As String, instead of using names without declaring them first, you can find this type of error at compile time.

See also:

Option declare statement