Link to home
Start Free TrialLog in
Avatar of jackjohnson44
jackjohnson44

asked on

return a class from function

I have a function in vb6. Which returns an object.
I create a varaiable as an object, set it to a class and return it.

function myfunction(stepNameLong) as object

       dim stepToBeProgrammed  as object

       select Case true
       Case InStr(stepNameLong, "xxx")
                stepToBeProgrammed = ClsMyClass
        End Select

        myfunction=stepToBeProgrammed

end function


when I do it in vb.net
I get an error when I try to set the class to the object

       dim stepToBeProgrammed  as object
        stepToBeProgrammed = ClsMyClass

If I do this

       dim stepToBeProgrammed  = ClsMyClass

it works, but I get an error at the bottom when I try to return the class
since it gets declared in the case statement.  It is a compile time error.

        myfunction=stepToBeProgrammed


Avatar of doobdave
doobdave

Hi there,

What's the error message you're getting please?

Is the snippet you provided the full code?
If not, please give a bit more code so as we can see exactly what's going on.

Best Regards,

David
ASKER CERTIFIED SOLUTION
Avatar of Shakti109
Shakti109

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 YZlat
try

function myfunction(stepNameLong) as object

       dim stepToBeProgrammed  as object

       select Case true
       Case InStr(stepNameLong, "xxx")
                stepToBeProgrammed = New ClsMyClass()
        End Select

        myfunction=stepToBeProgrammed

end function
oops, I didn't refresh the page