Johan G
Johan G

Reputation: 1013

Type mismatch when comparing value with lotusscript

This question is related to my original question

I am trying to follow Ken's suggestion. So I just want to see if I can at least pop up a message box if the original and last saved value is the same. Here are the things that I set up.

Global declaration  
Dim originalValues(2) As Variant
Dim lastValues(2) As Variant

Then on the queryopen:

Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
' Current document
    Dim doc As NotesDocument
    Set doc = Source.Document

' Array containing original value
    originalValues(0) = doc.QCR_No
    originalValues(1) = doc.QCR_Mobile_Item_No
    originalValues(2) = doc.QCR_Qty
End Sub

PostSave

Sub Postsave(Source As Notesuidocument)
    ' Current document
    Dim doc As NotesDocument
    Set doc = Source.Document

    ' Load fields value to the array
    lastValues(0) = doc.QCR_No
    lastValues(1) = doc.QCR_Mobile_Item_No
    lastValues(2) = doc.QCR_Qty

    ' Compared each value in the array to see if there is any difference
    Dim i As Integer
    For i = 0 To 2
        If lastValues(i) = originalValues(i) Then
            Messagebox "Same", MB_OK            
        End If
    Next
End Sub

Now when it comes to this line

If lastValues(i) = originalValues(i) Then

I got an error 'Type Mismatch' which I do not understand why. I debugged the code and the values in the array are all the same. The array has a Variant data type too. What do I do wrong here?

Upvotes: 1

Views: 2831

Answers (1)

Ken Pespisa
Ken Pespisa

Reputation: 22266

When you access the items using the convenience properties (i.e. doc.ItemName), you are actually accessing an array of values. 99% of the time you want to just get the first value in that array, so you'll need to specify that as doc.ItemName(0), for example:

originalValues(0) = doc.QCR_No(0)
originalValues(1) = doc.QCR_Mobile_Item_No(0)
originalValues(2) = doc.QCR_Qty(0)

and

lastValues(0) = doc.QCR_No(0)
lastValues(1) = doc.QCR_Mobile_Item_No(0)
lastValues(2) = doc.QCR_Qty(0)

then you should be comparing like types when you do your comparison in the PostSave

Upvotes: 6

Related Questions