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
sUnitName = rst("UnitName") & vbnullstring
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
public function f_GetUnitInfo(byval sUnitName as string) as MyUnit
dim oUnit as new MyUnit
oUnit.UnitName = rst("UnitName") & vbnullstring
oUnit.UnitBase = rst("UnitBase") & vbnullstring
I hope I have explained something meaningful.