Runtime Error - Type Mismatch

Often you are not exactly sure what type of data a variable might hold initially, and you need to be sure of what type of data it is before you try to use a conversion function on it. This is because using a conversion function on the wrong type of data can cause a runtime error. For example, try this code:

Dim varTest
varTest = "Hello"
varTest = CLng(varTest)

This code will cause a runtime error on line 3: "Type Mismatch". Not a nice thing to happen when your code is trying to accomplish something. Obviously, this little code sample is pretty silly, because we knew that the variable contained a String when we tried to convert it to a Long. This is especially true when you are (1) accepting input from a user (2) reading data from a database (3) reading data from a file.

First
Next