Visual Basic Q&A

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Entries Tagged ‘type mismatch error’

PRB: Type Mismatch with Default Prop of VB4 Data Access Object

Symptoms
Some data access objects in Visual Basic for Windows version 4.0 no longerhave the default “Name” property. Instead, these objects now have a defaultcollection. This change can lead to “Type Mismatch” (Error 13) or “InvalidArgument” (Error 3001) errors when attempting to run your code.
Resolution
To work around this problem, add the name of the property you want toreference.
For example, use this:

MsgBox Data1.Database.TableDefs(0).Name instead of this:

MsgBox Data1.Database.TablesDefs(0)

BUG: Data Control Errors Do Not Populate Error Object

Symptoms
A “Type Mismatch” error is generated when a control is bound to a fieldwith an incompatible type, but the Error object is not populated when it isexamined in the Data Control Error event.
Resolution
This is a limitation of the Data Control in Visual Basic version 4.0. Whenthe DAO generates an error, the Error object is cleared when the Errorevent for the Data Control is fired.

“Name ‘DTE’ is not declared” error message while running the “Item Method (General Extensibility)” MSDN sample code

Symptoms
This article describes problems that you may experience when you follow the documentation for the Item Method (General Extensibility) that appears in the following Microsoft Developer Network (MSDN) article:
http://msdn2.microsoft.com/en-us/library/aa301425(VS.71).aspx(http://msdn2.microsoft.com/en-us/library/aa301425(VS.71).aspx)When you paste the sample code from the Example section of the article to a Visual Basic .NET application, and then you try to compile the file, you receive the following error message:

Name ‘DTE’ is not declared.When you try to assign the return value of the EnvDTE.Documents.Item method to an AddIn type variable, you receive the following error message:

An unhandled exception of type ‘System.InvalidCastException’ occurred in ApplicationName.exe
Additional information: Specified cast is not valid.When you pass an Object parameter to the EnvDTE.Documents.Item method, you receive the following error message:

An unhandled exception of type ‘System.Runtime.InteropServices.COMException’ occurred in ApplicationName.exe
Additional information: Type mismatch.
Resolution
You receive the “Name ‘DTE’ is not declared” error message because the variable named DTE is not declared in the sample code that is provided in the MSDN article. You receive theInvalidCastException error message because the MSDN article states that the return value for the EnvDTE.Documents.Item method is an AddIn type. However, the EnvDTE.Documents.Item method returns a Document type object. Therefore, when you try to assign a Document type object to an AddIn type variable, you receive the error message.You receive the Type mismatch error message when you try to pass a parameter that is not an Integer or a String to the EnvDTE.Documents.Item method. The EnvDTE.Documents.Item method is used to gain access to the elements of the EnvDTE.Documents collection. The EnvDTE.Documents.Item method can accept only two types of parameters:Integer – for the index value of the documents in the EnvDTE.Documents collectionString – for the key of the documents in the EnvDTE.Documents collection