Converting string name of an object to the actual object
Is it possible to dim an object as a evaluation of a string variable.
VB Code:
Friend gobjSalesRecord As SageDataObject100.SalesRecord
Public Sub New(ByVal strSDODataObjectName As String)
Dim objSDODataObject As Object
objSDODataObject = strSDODataObjectName
......
End Sub
Where strSDODataObjectName = "gobjSalesRecord"
I want to convert that string name of the object to the actual Object and pass that, ie make objSDODataObject = gobjSalesRecord
Re: Converting string name of an object to the actual object
Why not just pass the entire object into the sub?... (byval DataObject as SageDataObject100.SalesRecord)
Re: Converting string name of an object to the actual object
Because I don't know which object I want to use until run time and the calling program does not know anything about SageDataObject100.SalesRecord .....
Anyway fixed it ... just needed to change this line
objSDODataObject = strSDODataObjectName
to
objSDODataObject = CObj(strSDODataObjectName)
Re: Converting string name of an object to the actual object
Um, no. All that does is cast your String as an Object and assign it to that variable. It absolutely DOES NOT get a reference to an object that is refered to by a variable of that name. strSDODataObjectName is a string variable and the value it contains has no relationship whatsoever to any other variable whose name is the same as that value. If you want to get a member variable from a name in a string then you need to use Reflection.