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=stepToBeProgram med
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=stepToBeProgram med
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=stepToBeProgram
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=stepToBeProgram
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try
function myfunction(stepNameLong) as object
dim stepToBeProgrammed as object
select Case true
Case InStr(stepNameLong, "xxx")
stepToBeProgrammed = New ClsMyClass()
End Select
myfunction=stepToBeProgram med
end function
function myfunction(stepNameLong) as object
dim stepToBeProgrammed as object
select Case true
Case InStr(stepNameLong, "xxx")
stepToBeProgrammed = New ClsMyClass()
End Select
myfunction=stepToBeProgram
end function
oops, I didn't refresh the page
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