Ask the Expert

Locate offending "type mismatch" variable when running a script

Is there an easy to find the offending variable producing a "type mismatch" error when a script is run?

There's not a "way" to do this, but there is a way of looking at things that could make it easier. What I would do is to make a variable for EVERY piece of data in your script where you think the problem might be and use the debugger to see the data types associated with the error. For example, instead of:
Call uidoc.FieldSetText( "fname", otherDoc.otherField(0) )

Do this:

VarTemp = otherDoc.otherField(0)
Call uidoc.FieldSetText( "fname", VarTemp )

When you do that, you could step through the debugger and view the variables to see what DataType is assigned to VarTemp. Then you know if it is not text that is where your error is. If the error is on assignment to a variable and you have "option declare" or "option explicit" in place, then use a temporary variant variable to determine the data type that you were trying to stuff into the variable.

I hope this helps you.

This was first published in November 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: