473,782 Members | 2,525 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2565
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
7268
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# (managed code)? I tried using Marshal.GetObjectForNativeVariant(), but of no use.
19
2095
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 it to your liking. ' Here is an example of use: ' start with a string of "1" Dim da As Variant = new Variant("1") ' add an integer of 2, becomes 3
10
4590
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 zero-length string (always returns a zero-length string when used in a query expression)" **** How many records are there in FirstTable in which Product Is Null. SELECT COUNT(*) AS CountofNullProdcut
4
4226
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 VARIANT in my functions in order to get no problems with VB-Script. I try to transform them into C++-Variables somehow like this:
11
1961
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) fails on its last line which is meant to assign the value of SplitB (a variant) the value of aSplit (an array dim'd as variant). That fails due to Type Mismatch. Anyone know how to get around this? Private Type MapiRecip Reserved As Long
1
1507
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 = FaxMsg.Recipients.Add(0) Recip.Name = sWho
3
6115
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 characters into the variant type, however when I use the 6.5 database I get only the limited number of characters that are actually in the column.
1
3242
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 in the win32com or comtypes.automation packages. I began to use Boost.Python to script some of my code. I tried to send the VARIANT back to python by having the extension module's functions return a VARIANT or VARIANT*; I even tried _variant_t. In...
4
12152
by: =?Utf-8?B?cmtibmFpcg==?= | last post by:
How can I define type variant in c#?
0
9641
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10313
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8968
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7494
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6735
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.