Re: Variant vs Object variable type
- From: "Allen Browne" <AllenBrowne@xxxxxxxxxxxxxx>
- Date: Mon, 10 Sep 2007 23:06:59 +0800
An object is something (like a form or text box) that has properties and methods.
5 is not an object: it is a number (probably integer.)
"Hello" is not an object: it is a string.
Therefore you could code:
Dim A As Object
Set A = Forms(0)
but you cannot code:
Set A = 5
because 5 is not an object.
In general, you want to declare the most specific data type you can. So if you will assign a text box to the control, it would be better to use:
Dim A As Control
rather than:
Dim As As Object
Better yes:
Dim A As Textbox
Likewise, it is better to use:
Dim A As Long
if you plan to assign 5 to it.
However, you do need to use Variant where the value may be Null.
--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Len" <Len@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:DBB22765-792C-4285-8FF1-3415DBB71B5B@xxxxxxxxxxxxxxxx
I am elaborating the ways to replace in my program variant variable
declarations with the object one. For example, if I have
Dim A as Variant
A=5
A="Hello"
I intend to have:
Dim A as Object
and to assign to A a number and a string.
How it can be done?
Thank you.
.
- Prev by Date: RE: Access and Frontpage
- Next by Date: Re: IIF Statements in update query
- Previous by thread: Re: IIF Statements in update query
- Next by thread: Re: Access Message Box
- Index(es):
Relevant Pages
|