Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Functions can return objects? True or False 2

Status
Not open for further replies.

JJ1

Programmer
Apr 19, 2001
104
GB
Folks,

I'm a VBScripting newbie and have a very simple question.

I'm trying connect to a COM Object as follows:
Code:
'Global Vars
dim objFarm

'Create Farm Object
objFarm = ConnectFarm()

Function ConnectFarm( )

    Dim objFarm

        ' Create MetaFrameFarm object
        Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")

        '[...]Error Checking code[...]

        'return object [line58]
        return objFarm

End Function
However, I receive this error:
Code:
C:\CtxAppSecurity.wsf(58, 14) Microsoft VBScript runtime error: Type mismatch: 'return'

I assume this error means that I'm not returning the objFarm object correctly. Could anyone inform me of the correct way to let functions return objects in vbscript please?

Thanks in advance for your help.

James.
 
>objFarm = ConnectFarm()
[red]set[/red] objFarm = ConnectFarm()
 
You use return in other languages, not VBScript:

Function ConnectFarm( )

Dim objFarm

' Create MetaFrameFarm object
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")

'[...]Error Checking code[...]

End Function

The last value assignment to a the function name is what the return value is.

Lee
 
'Global Vars
dim objFarm
'Create Farm Object
Set objFarm = ConnectFarm()

Function ConnectFarm( )
Dim objFarm
' Create MetaFrameFarm object
Set objFarm = CreateObject("MetaFrameCOM.MetaFrameFarm")
'[...]Error Checking code[...]
Set ConnectFarm = objFarm
End Function

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Thank you folks. Great answers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top