Microsoft KB Archive/190213

= BUG: Type Mismatch Error Comparing String With Byte Array =

Article ID: 190213

Article Last Modified on 5/13/2003

-

APPLIES TO


 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q190213



SYMPTOMS
In Visual Basic, if you have a function returning an array of bytes and you compare the return value with a string, you get the following error:

Compile Error: Type Mismatch



RESOLUTION
You can bypass this error if you convert the return value of the function using the function Cstr before comparing it with a string, as in the following code: If CStr(myFunc) <> "yes" Then



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.



Steps to Reproduce Behavior
 Create a new Standard EXE project in Visual Basic. Form1 is created by default.  Add a CommandButton to Form1 and paste the following code into the code window of Form1: Public Sub Command1_Click If myFunc <> "yes" Then Stop End If     End Sub

Function myFunc As Byte myFunc = "yes" End Function  Press the F5 key to run the program. Click on Command1. The error message "Compile Error: Type Mismatch" results.

Additional query words: kbDSupport kbVBp600bug kbdss kbVBp kbNoKeyWord

Keywords: kbbug KB190213

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.