Type Mismatch with the MsgBox Command 
Author Message
 Type Mismatch with the MsgBox Command

Why does this line of code return the error "Type Mismatch"
MsgBox vStartingPoint + " value of vStartingPoint"
I'm looking for away to prompt (debugging purposes)the value of a
variable and a string comment in the same message box.



Mon, 12 Jul 1999 03:00:00 GMT  
 Type Mismatch with the MsgBox Command

Use the "&" operator for text concatenation, the "+" operator is
no longer overloaded.
--
Chris Behrens
Site Builder Network Level 2
http://www.deltav.net


"Outside of a dog, a book is a man's best friend.
Inside of a dog, it's too dark to read."



Quote:
> Why does this line of code return the error "Type Mismatch"
> MsgBox vStartingPoint + " value of vStartingPoint"
> I'm looking for away to prompt (debugging purposes)the value of a
> variable and a string comment in the same message box.



Mon, 12 Jul 1999 03:00:00 GMT  
 Type Mismatch with the MsgBox Command



Quote:
> Why does this line of code return the error "Type Mismatch"
> MsgBox vStartingPoint + " value of vStartingPoint"
> I'm looking for away to prompt (debugging purposes)the value of a
> variable and a string comment in the same message box.

The '+' operator can mean concatenation or addition.  If vStartingPoint is
numeric then VB will see "<numeric value>+" and assume addition and then
fail when the next arg is a string.  For concatenation you should always
use the & operator:
MsgBox vStartingPoint & " value of vStartingPoint"
Actually, to remove all ambiguity you should really use:
MsgBox CStr(vStartingPoint) & " value of vStartingPoint"
or:
MsgBox Format$(vStartingPoint) & " value of vStartingPoint"


Tue, 13 Jul 1999 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. MSGBOX function - Type Mismatch ERROR!!

2. Type Mismatch Executing Adodb.command

3. Type Mismatch when checking command.state

4. Prob. w\ TYPE data type: err:Type Mismatch

5. Type mismatch when the types are correct ?

6. Type mismatch on user defined data type

7. Type Mismatch - Array of Type Long

8. Type Mismatch reading from Access 2K of type Date

9. Passing user data type to function causes type mismatch error

10. type mismatch error: 3464.

11. ByRef Argument Type Mismatch

12. Type mismatch

 

 
Powered by phpBB® Forum Software