|
-
Feb 7th, 2007, 01:18 PM
#8
Re: Classic VB - What does this error mean, and how do I fix it?
"Error 13: Type mismatch"
What it means: You are trying to use the wrong data type, eg: writing a string into a variable which is declared as Integer.
How to solve it: First of all, check that the data types of the variables/properties/functions/etc. of what you are using are all compatible (for example, the InputBox function returns a String, so you should not use an Integer to store the result of it). Note that if you have declared variables in this way: Dim x, y, z As Long , only z is a Long (x and y are variants), see here for the proper way to declare multiple variables on one line.
Note that things like a TextBox and Form are also variables (technically Object Variables) that contain multiple properties (similar to variables, such as .Height and .Width), each of which have their own data type. For example, if you are using the code a = Text1 , you are actually refering to the property Text1.Text, which is a String data type.
If you are trying to store a value that the user has entered (from a TextBox etc) into a numeric variable, then either check that the value can be converted into a number by using the IsNumeric function, or get just the numeric part by using the Val function (which returns 0 if no number is found), eg:
VB Code:
Dim intValue as Integer 'first method - check if it is a number: If IsNumeric(Text1.Text) Then intValue = CInt(Text1.Text) '(CInt converts a value to an integer) End If 'or, second method - get the numeric part of the text (default of 0) intValue = Val(Text1.Text)
Last edited by si_the_geek; Sep 30th, 2013 at 01:36 PM.
Reason: fixed links
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|