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?)

Thanks!
LVL 98
Lee W, MVPTechnology and Business Process AdvisorAsked:
Who is Participating?
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.
0
Bill PrewCommented:
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.


»bp
0

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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

QlemoBatchelor, Developer and EE Topic AdvisorCommented:
I would say "lazy" or "irresolute". You always should declare as the most restrictive type possible.
0
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.
0
QlemoBatchelor, 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.
0
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
0
Bill PrewCommented:
Did you used to be in sales Martin...?

;-)
1
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
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.