Object instead of Integer?

Can anyone think of a good reason to declare variables as objects instead of the appropriate variable type in VB6?

I'm experimenting with converting a VB6 app to .NET (2008 for now, then, if it works, 2017) and looking over the code, the original dev declared everything as objects.  Dim intLoop1 As Object (why not integer?)  Is there (could there be) a good reason for this or was he being lazy as my gut tells me?)

LVL 99
Lee W, MVPTechnology and Business Process AdvisorAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Martin LissOlder than dirtCommented:
Objects are not the same as variables. Variables contain values whereas objects are, well, objects like Dictionaries or Collections.
Bill PrewIT / Software Engineering ConsultantCommented:
It's "okay" to do that, from the compiler point of view, you actually allocate a pointer that can reference any data type when assignment is made.

The place I would typically use or see that used is when doing late binding to an object (rather than early binding).  Other than that it feels like it introduces more overhead when the program runs, and has to dereference pointers to base data classes, and also limits the compliers ability to identify type issues in your code before runtime.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Martin LissOlder than dirtCommented:
Note that when people define something as Object they are sometimes just lazy or perhaps they don't know how to further define the object.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I would say "lazy" or "irresolute". You always should declare as the most restrictive type possible.
Lee W, MVPTechnology and Business Process AdvisorAuthor Commented:
I can see defining things as objects when you're not sure what kind of data they may contain... but then why name the variables after the type data you expect it to contain?  Examples:

Dim intCounter As Object
Dim strSomeText As Object

intCounter = 1
strSomeText = "Fun to be lazy"

Open in new window

I would expect the variable names to reflect that they are objects:
Dim objCounter As Object
Dim objSomeText As Object

objCounter = 1
objStrSomeText = "Fun to be lazy"

Open in new window

At this point, the above question is rhetorical.  I thank you all for your quick info and insight.
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
I agree to your POV. Being specific in the name and unspecific in the type just doesn't make sense.
Martin LissOlder than dirtCommented:
You’re welcome and I’m glad I was able to help.

If you expand the “Full Biography” section of my profile you’ll find links to some articles I’ve written that may interest you.

Marty - Microsoft MVP 2009 to 2017
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2017
Bill PrewIT / Software Engineering ConsultantCommented:
Did you used to be in sales Martin...?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.