Integer comparison (type mismatch)

I know this shouldn’t deserve a thread but I’m posting it for lack of finding a good example within a acceptable timeframe:

Basically I have 3 textboxes on a form, if all are empty I want to set another field on this form, here’s the code I have:

For i = 1 To dc.Count

	Dim intcount As Integer

	intcount = 0

	Msgbox("startifs")

	If doc.firstname = "" Then 

		intcount = intcount + 1

	End If

	If doc.lastname = "" Then 

		Intcount = intcount + 1

	End If

	If doc.jobtitle = "" Then 

		Intcount = intcount + 1

	End If

	Msgbox("startcompare")

	If intcount = 0 Then

		doc.FromJobs = "no"

	End If

	Set doc = dc.getnextdocument(doc)

Next

I tried a singular if statement similar to this:

if doc.firstname <> “” & doc.lastname <> “” & doc.jobtitle <> “” THEN

but pretty much had the same result.

other info:

  • all fields on this doc are TEXT

  • the type mismatch occurs somewhere in the IF loops (before “If intcount = 0 Then”)

I know this has to be obvious, but anyone see it?

Subject: Integer comparison (type mismatch)

NotesItems (back-end fields) reurn a Variant array of values. When you do this:

If doc.lastname = “” Then

you are trying to compare a string to an array. They can never be equal. This will work:

If doc.lastname(0) = “” Then

In that case, you are testing the first element of the Values array against a string. It’s scalar-vs.-scalar now, so it will work.

Subject: Integer comparison (type mismatch)

Try this

If trim(doc.firstname(0)) = “” And trim(doc.lastname(0)) = “” And trim(doc.jobtitle(0)) = “” Then

doc.FromJobs = “no”

End If

Subject: RE: Integer comparison (type mismatch)

hm, didn’t work, although no error, the field remains unchanged.

What exactly does trim do? Anyone notice that designer help’s search function went from super useful in R5 to completely annoying in R6? Search “trim” should find TRIM! (yes, I’m indexed)

anyhow just to be sure this does what I think it does, I don’t want to check if the fields are blank so much as if they are NOT blank. - just checking

Subject: RE: Integer comparison (type mismatch)

Odd. When I search for “trim”, the first result I get is the Trim function.

Anyway, Trim strips off leading and trailing spaces. It’s certainly not necessary for your purposes, but it’ll distinguish between an empty field and one with just a space in it.

Using = will not, as you’ve spotted, give you want you want. However, as I’ve suddenly remembered, using <> with strings probably won’t give you want you want either. Use = and wrap it all up with a Not, maybe like this:

if Not(doc.foo(0) = “” or doc.bar(0) = “”) then

Subject: Integer comparison (type mismatch)

You need to treat fields as arrays, even if they only have one member:

if doc.firstname(0) <> “” & doc.lastname(0) <> “” & doc.jobtitle(0) <> “” THEN