473,385 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Why not always Variant type

Hello

If Variant type is the data type that contains any kind of data type is
there a reason why one would not always use Variant when declaring
variables?
Thanks
G Gerard
Nov 6 '06 #1
3 2545
G Gerard wrote:
Hello

If Variant type is the data type that contains any kind of data type is
there a reason why one would not always use Variant when declaring
variables?
I'm sure someone can deliver a more convincing and accurate argument
than I, but here goes from this novice's point of view...

Typing variables correctly is a core skill for a programmer. To
understand why it is necessary to understand exactly what variables are
and how the system uses them.

Without going into the bits and bytes of every VBA variable type, or how
the system has to dynamically adjust to the data you feed it, I will say
you may very well get away with loosely typing variables in your code.
VBA and pre- dot.Net versions of VB are rather forgiving in this regard.
You may have all the memory and processing power you need to overcome
the overhead incurred by declaring everything as a Variant. With today's
typical hardware, maybe everyone else does too.

However taking this approach demonstrates a lack of understanding of the
data you are processing. What you gain in a blanket approach to variable
typing you lose in ability to control the data and handle exceptions. As
a programmer, if you understand the code you write and the data you are
processing, then you should have little difficulty assigning the most
efficient type to your variables.

That's my soapbox... I'll step down now.
--
Smartin
Nov 6 '06 #2
"G Gerard" <gg*****@nbnet.nb.cawrote
If Variant type is the data type that contains
any kind of data type is there a reason why
one would not always use Variant when
declaring variables?
It is not efficient, and it doesn't always "guess right" at the type of data
and sometimes you need to know the type is correct.

But, it is eminently useful in cases where you need to have a Null value as
one of the options -- because it's the only Access variable type that can be
Null.

Larry Linson
Microsoft Access MVP
Nov 6 '06 #3
On Mon, 06 Nov 2006 21:30:23 GMT, "G Gerard" <gg*****@nbnet.nb.ca>
wrote:

Because it's good programming practice to always use the
minimal-suitable datatype: don't use a Long Integer if an Integer
suffices, etc. Don't use a sloppy data type if a precise one suffices.
The reason is that the additional checking will reveal possible
problems early on, hopefully at compile-time rather than at runtime.

The same principle applies to database design. You wouldn't use memo
fields for every field in your database, right?

-Tom.

>Hello

If Variant type is the data type that contains any kind of data type is
there a reason why one would not always use Variant when declaring
variables?
Thanks
G Gerard
Nov 7 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: C. N. Sridhar | last post by:
Hi, I'm writing a wrapper to a win32 dll in C#. I need to call a method in DLL which has a Variant type reference parameter. How to marshal variant type from win32 (unmanaged code) to C#...
19
by: Jon Davis | last post by:
Hi guys! Just wanted to let you all know that I created a Variant structure, inspired by the old VB6 days. This is written in C#, but you can build a CLR/.NET class library assembly and reference...
10
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbaac11/html/acfctNZ_HV05186465.asp "If the value of the variant argument is Null, the Nz function returns the number zero or a...
4
by: Claus77 | last post by:
Hi there, I've got a little problem with the following: I'm just writing a com-application in C++ with VS-6, which should also be used with VB-Script, so I have to use variables of type...
11
by: MLH | last post by:
The following procedures found at http://ffdba.com/downloads/Send_Mail_With_Outlook_Express.htm are meant to work together in harmony to effect eMail sends via OE. The last procedure (FN SplitB)...
1
by: darrenbenn | last post by:
I need to convert this code to VB .NET (2003). Dim FaxMsg As IFaxMessage Set FaxMsg = gFC.NewMessage Dim Recip As Variant ' add a recipient to the fax recipients collection Set Recip =...
3
by: empire5 | last post by:
I'm trying to convert a MS-Sql 6.5 VB application to SQL 2005 and vb.net. The vb app has uses a variant data type. When I try to read the variant data type from the sql 2005 database I get 8,000...
1
by: captainc | last post by:
I have C++ code to import a .tlb and use a .dll that has functions that return VARIANT types and accepts BSTRs (bstrings). I have seen that python has modules that can manipulate VARIANTs and BSTRs...
4
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.