Re: Variant vs Object variable type

Tech-Archive recommends: Fix windows errors by optimizing your registry



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.

.



Relevant Pages

  • Re: IE sequencing and cookie notification popups
    ... ' 10Apr04: accept cookies from hotmail. ... Dim SetWindowLong ' as object ... Const sDlgCaption = " Kookie Kruncher, ... ' notifications associated with that type of control. ...
    (microsoft.public.scripting.vbscript)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.win2000.termserv.clients)
  • FYI: TS client script
    ... for TS on the machine running the script, ... the web control class was not found; ... Dim m_Tracing, m_TraceStream ... Function ArgString(ByVal argName, ByVal defaultValue) ...
    (microsoft.public.windows.terminal_services)
  • Re: Transfer data from one Content Control to another Word 2007 VB
    ... unfortunately cleared the grey placeholder text and turned it black and I ... Dim cc1PtMedication As ContentControl ... you can just assign the text of one control directly to the text ... macro transfers the contents of room 1 to the controls for room 3, ...
    (microsoft.public.word.vba.beginners)
  • Re: Option Explicit
    ... The meaning of "intialize the variable with a data not on the Dim statment" ... you declare all of your variables the code will run at the same speed. ... if Access handles a Variant date, ... I can't imagine that Dim varResult as Variant uses memory ...
    (microsoft.public.access.formscoding)