troubleshooting Question

Returning an Object from a function

Avatar of nzfire
nzfire asked on
Visual Basic Classic
9 Comments1 Solution196 ViewsLast Modified:
Hi All,

I am rewriting some code and getting rid of the global variables that I am using to hold data. I would like to build an object with properties to hold this.

My functions are returning data from an ado recordset and I would like to have an object to hold all the fields. If there is a better way then I'd love to hear. Basically what I have done in the past is have a whole load of variables in the declarations section of my module eg

Dim sUnitName as string
Dim sUnitBase as string
Dim sUnitNumber as string

Then I would run a proc that would return the recordset and then fill the variables with the info
so

...
sUnitName = rst("UnitName") & vbnullstring
etc
...

NOW:

I would like to have an object, lets call it MyUnit with properties, UnitName, UnitBase etc

I haven't run or tried this code, but these are just my thoughts:

Private Sub MyUnitInformation

    dim oUnitInfo as New MyUnit
dim sName as string

    set oUnit = f_GetUnitInfo("blah")

'***HOW WOULD I USE THE PROPERTIES HERE***?
    sName = oUnitInfo.UnitName


end sub





public function f_GetUnitInfo(byval sUnitName as string) as MyUnit

    dim oUnit as new MyUnit

...open recordset...

    oUnit.UnitName = rst("UnitName") & vbnullstring
    oUnit.UnitBase = rst("UnitBase") & vbnullstring

    set f_GetUnitInfo

exit function





I hope I have explained something meaningful.

Cheers,
Sean
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros