Type Mismatch using Case

And here I was, thinking that I was getting close with my code.

I am working on code to pull field information from Form A to a newly created Form B.

My code gives me the error ‘Type Mismatch’ and debugger shows that it stops on the line ‘fDrop = fdoc.Drop’. I originally had fDrop dimmed as a NotesItem but using Case caused all sorts of errors that seemed to want it to be a string, so I changed all of the code to accomodate this.

The field referred to by ‘Drop’ is a text field if that is any help. I have been looking at and working with this code for long enough today that I am getting a little loopy.

Any help would be great:

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim plist As NotesDocumentCollection

Dim db As NotesDatabase

Dim fdb As NotesDatabase

Dim view As NotesView

Dim fview As NotesView

Dim item As NotesItem

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim fdoc As NotesDocument

Set db = session.CurrentDatabase

Set fdb = session.GetDatabase(“AppServer”, “folder/database.nsf”)

Set view = db.GetView( “dbView”)

Set fview = fdb.GetView( “fdbView” )

Set plist = ws.PickListCollection(PICKLIST_CUSTOM, True, “AppServer”, “folder/database.nsf”, “View”, “Title”, “Prompt.”)

Set fdoc = plist.GetFirstDocument

Set uidoc = ws.ComposeDocument( “”, “”, “Form”)

Set doc = uidoc.Document

doc.fromfield1 = fdoc.tofield1

doc.fromfield2 = fdoc.tofield2

doc.fromfield3 = fdoc.tofield3

doc.fromfield4 = fdoc.tofield4

doc.fromfield5 = “field5info”

doc.fromfield6 = “field6info”

Dim fDrop As String

Dim DropYr As String

Dim DropQtr As String

Dim DropDate As String

fDrop = fdoc.Drop

Select Case fDrop

Case 1 = Evaluate(|@Contains(“Drop”; “.1”)|, fdoc)

DropQtr = “1Q”

Case 2 = Evaluate(|@Contains(“Drop”; “.2”)|, fdoc)

DropQtr = “2Q”

Case 3 = Evaluate(|@Contains(“Drop”; “.3”)|, fdoc)

DropQtr = “3Q”

Case 4 = Evaluate(|@Contains(“Drop”; “.4”)|, fdoc)

DropQtr = “4Q”

End Select

If Evaluate(|@Contains(“Drop”; @Text(@Year(@Today)))|, fdoc) Then

DropYr = Cstr(Year(Today))

End If

If Evaluate(|@Contains(“Drop”; @Text(@Year(@Adjust(@Today; -1; 0; 0; 0; 0; 0))))|, fdoc) Then

DropYr = Cstr(Year(Today)-1)

End If

DropDate = DropQtr + " - " + DropYr

Dim DSview As NotesView

Dim DSdoc As NotesDocument

Set DSview = db.GetView(“DSView”)

Set DSdoc = DSview.GetDocumentByKey(“DSForm”, True)

If DropDate = DSDoc.Field1 Then

doc.field7 = DSdoc.field1

doc.field8 = DSDoc.field2

End If

Subject: Type Mismatch using Case

try

fDrop = fDoc.getItemValue( “drop”)( 0)

since drop is a notes item, you are using document properties to get the first value of the item.

john

Subject: RE: Type Mismatch using Case

Thank you for the response. I tried your suggestion, but it just moves the Type Mismatch down to ‘Case 1’. I cannot seem to get Case to work with the NotesItems.

Subject: RE: Type Mismatch using Case

If the type is text, then change your cases from

case 1 to case “1”

case 2 to case “2”

etc, etc…

or if your sure it will always be numeric then do a

Select case cint( fDrop)

in which case it will convert the string to an integer

John

Subject: Type Mismatch using Case

Have a go at:Select Case True

Case 1 = Cint(Evaluate(|@Contains(“Drop”; “.1”)|, fdoc))

DropQtr = “1Q”

Case 1 = Cint(Evaluate(|@Contains(“Drop”; “.2”)|, fdoc))

DropQtr = “2Q”

Case 1 = Cint(Evaluate(|@Contains(“Drop”; “.3”)|, fdoc))

DropQtr = “3Q”

Case 1 = Cint(Evaluate(|@Contains(“Drop”; “.4”)|, fdoc))

DropQtr = “4Q”

End Select

Cheers, Robin

Subject: Type Mismatch using Case

There is a lot of misunderstanding of both the language and the Domino product objects illustrated in this code.

First, a NotesItem is an object that has a number of properties, one of which is the Values property. It does not, of itself, have a value, so you can’t compare it to anything except to another NotesItem variable – and then you can only determine whether or not the two variables are referring to the same NotesItem object. That’s a relatively esoteric sort of check, so the chances are that if you are trying to compare a NotesItem to anything in the normal course of coding, you’ve taken a wrong turn somewhere.

When you get the value of a NotesItem, whether by getting the Values property of the item, by using doc.GetItemValue(“Fieldname”) or by the extended class syntax of the NotesDocument (doc.FieldName), you are ALWAYS getting an array of values, even if there is only one value in the field. If you know there is only one value, or are interested only in the first value, you can directly access the first value using the zeroeth index of the array:

stringVariable = doc.Fieldname(0)

or

stringValue = doc.GetItemValue(“Fieldname”)(0)

Now for the Select Case statement. Your code seems to be treating the Case statements as an enumeration. That is, you are numbering the cases, then trying a test. It doesn’t work that way. Select Case is a concise way of writing a long If->Then, Elseif->Then, Elseif->Then…Elseif->Then, Else block. In the Select Case statement, you tell the code the value you want to base your decision on, and each of the Case statements contains one or more of the possible values for the variable you used in the Select Case statement.

In this case, you seem to be looking for a quarter of the year in a value that is expressed in the format “YYYY.Q”. If that’s the actual format, then you want everything to the right of the period/point as the value to base your decision on. Rewritten on that basis, your code would look like this:

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim plist As NotesDocumentCollection

Dim db As NotesDatabase

Dim fdb As NotesDatabase

Dim view As NotesView

Dim fview As NotesView

Dim item As NotesItem

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim fdoc As NotesDocument

Set db = session.CurrentDatabase

Set fdb = session.GetDatabase("AppServer", "folder/database.nsf")



Set view = db.GetView( "dbView")

Set fview = fdb.GetView( "fdbView" )

Set plist = ws.PickListCollection(PICKLIST_CUSTOM, True, "AppServer", "folder/database.nsf", "View", "Title", "Prompt.")

Set fdoc = plist.GetFirstDocument

Set uidoc = ws.ComposeDocument( "", "", "Form")

Set doc = uidoc.Document



doc.fromfield1 = fdoc.tofield1

doc.fromfield2 = fdoc.tofield2

doc.fromfield3 = fdoc.tofield3

doc.fromfield4 = fdoc.tofield4

doc.fromfield5 = "field5info"

doc.fromfield6 = "field6info"



Dim fDrop As String

Dim fDropQtr As String

Dim DropYr As String

Dim DropQtr As String

Dim DropDate As String

fDrop = fdoc.GetItemValue("Drop")(0)

DropYr = Strleft(fDrop, ".")

fDropQtr = Strright(fDrop, ".")

Select Case fDropQtr

Case "1"

	DropQtr = "1Q"

Case "2"

	DropQtr = "2Q"

Case "3"

	DropQtr = "3Q"

Case "4"

	DropQtr = "4Q"

End Select

DropDate = DropQtr + " - " + DropYr



Dim DSview As NotesView

Dim DSdoc As NotesDocument

Set DSview = db.GetView("DSView")

Set DSdoc = DSview.GetDocumentByKey("DSForm", True)

If DropDate = DSDoc.Field1(0) Then

	doc.field7 = DSdoc.field1

	doc.field8 = DSDoc.field2

End If

But notice that since we’ve been able to extract the quarter number (as a string) from the source document’s Drop field value (using Strright), there is no longer a need to use the Select Case block, so you can simplify it to:

Dim ws As New NotesUIWorkspace

Dim session As New NotesSession

Dim plist As NotesDocumentCollection

Dim db As NotesDatabase

Dim fdb As NotesDatabase

Dim view As NotesView

Dim fview As NotesView

Dim item As NotesItem

Dim doc As NotesDocument

Dim uidoc As NotesUIDocument

Dim fdoc As NotesDocument

Set db = session.CurrentDatabase

Set fdb = session.GetDatabase("AppServer", "folder/database.nsf")



Set view = db.GetView( "dbView")

Set fview = fdb.GetView( "fdbView" )

Set plist = ws.PickListCollection(PICKLIST_CUSTOM, True, "AppServer", "folder/database.nsf", "View", "Title", "Prompt.")

Set fdoc = plist.GetFirstDocument

Set uidoc = ws.ComposeDocument( "", "", "Form")

Set doc = uidoc.Document



doc.fromfield1 = fdoc.tofield1

doc.fromfield2 = fdoc.tofield2

doc.fromfield3 = fdoc.tofield3

doc.fromfield4 = fdoc.tofield4

doc.fromfield5 = "field5info"

doc.fromfield6 = "field6info"



Dim fDrop As String

Dim DropDate As String

fDrop = fdoc.GetItemValue("Drop")(0)

DropDate = Strright(fDrop, ".") + "Q-" + Strleft(fDrop, ".")



Dim DSview As NotesView

Dim DSdoc As NotesDocument

Set DSview = db.GetView("DSView")

Set DSdoc = DSview.GetDocumentByKey("DSForm", True)

If DropDate = DSDoc.Field1(0) Then

	doc.field7 = DSdoc.field1

	doc.field8 = DSDoc.field2

End If