Link to home
Start Free TrialLog in
Avatar of Lee W, MVP
Lee W, MVPFlag for United States of America

asked on

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!
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Objects are not the same as variables. Variables contain values whereas objects are, well, objects like Dictionaries or Collections.
ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Lee W, MVP

ASKER

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.
I agree to your POV. Being specific in the name and unspecific in the type just doesn't make sense.
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
Avatar of Bill Prew
Bill Prew

Did you used to be in sales Martin...?

;-)