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’

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

PRB: Exceeded Limits on Array Sizes of User Defined Types

Symptoms
When compiling code that has user-defined types containing arrays ofvariable-length strings you may get this error:

“Fixed or static data can’t be larger than 64K”
Resolution
You exceeded the data limitations of a user-defined type. As stated in theProgrammer’s Guide for Microsoft Visual Basic version 4.0:
No variable of a user-defined type can exceed 64K, though the sum ofvariable-length strings in a user-defined type may exceed 64K(variable-length strings occupy only 4 bytes in the user-defined type;the actual contents of a string are stored separately. User-definedtypes can be defined in terms of other user-defined types, but the totalaggregate size of the types cannot exceed 64K.

PRB: Error When You Access an Array Field of a .NET Structure from COM

Symptoms
When you access an Array field of a structure that is defined in .NET from inside a COM DLL, you may receive the following error message:

“An unhandled exception of type ‘System.ArgumentException’ occurred in ProjectName”
Additional information: Wrong number of arguments or invalid property assignment.
Resolution
Because of the late-bound method that is used in this case, the Visual Basic 6.0 runtime cannot get the type information for the Array field that you are attempting to access.

PRB: Error Setting Field Format Property of Access Tables

Symptoms
From Visual Basic, when trying to specify a field Format property of anAccess table (for example, field type DateTime) from blank to “Long Date”format, the following error occurs:

Run-time error ‘3421′:
Data type conversion error.
Resolution
The property data type constant should always be “dbText.” If other datatype constants, such as dbDate or dbNumeric are specified, you willencounter the error described above.

PRB: ADO: Compile Error: User-Defined Type Not Defined

Symptoms
When you compile your ADO project, you receive the following error:

Compile error:User-defined type not definedThis can occur on either a Connection or Command object.
Resolution
You may have referenced one of the following libraries instead of theMicrosoft ActiveX Data Objects (ADODB) type library:Microsoft ActiveX Data Objects Recordset (ADOR) type library.
-or-Microsoft ActiveX Data Objects (Multi-dimensional) (ADOMD) type library.