Another thing to consider in the passing of variables is the selected Data Type.
You will most certainly receive an error if attempting to pass a variable of the type String to a Long variable. You could however perform so called type shifts by user-defined types and other more delicate choices here. It is however not recommendable if you can avoid it, and it is often cause for several bugs.
A more common problem is that a data type selected may not be large enough to hold your values. You could then find a run time error #6, Runtime overflow. It can happen if you attempt to pass a Long value to an Integer variable, or even worse so, when multiplying two Integers to a Long value, even though the result may well fit into a Long.
If you doubt it, try performing a simple multiplication of 1024 * 1024 inside a variable assignment of a long variable as such,
Dim MyLong As Long
MyLong = 1024 * 1024
The result would be 1048576, which is well within the realm of a Long, however it causes an error #6. A slight bit annoying but it can be handled when you are aware of this.
Comments