Passing Variables By Value or Reference

Data Types & Conflicts

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.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Some people, when confronted with a problem, think "I know, I’ll use regular expressions." Now they have two problems.” - Jamie Zawinski