I'm getting error message when trying to return message "failed" inside a function
here's my code which works fine with valid parameters.To handle invalid scenarios it fails at 1st line(set Temp=ConnectPutty())
Temp.Type "some command"
if UserID="" then
Any suggestions please to handle this.
Thank you for your quick reply. I just tried without set but it returns error ..I guess you are using msgbox ConnectPutty inside the function. I 'm trying to use msgbox Temp to know its returned failed.
You cannot return object or string at the same time. Technically you can but while receiving it as return value you should know whether it would return value or object. Depending on same you can use Set or just direct assignment. So your approach in this function itself is wrong
To add to Tarun's point, ideally you don't want to return error strings. The proper way would be to Raise a qualified error. Problem with error strings is the context gets lost, and it becomes hard to debug.
This will allow people calling your function an easier time debugging what's going wrong. Of course this means a lot of annoying exception handling code, that's the reason why most engineers despise VBScript.
Also, you might want to use good coding standards, it helps other engineers figure out what your code is doing easier, notice how their functions are prefixed by the type they return. This helps identify what you expect back to avoid such an issue, as VBScript is not a strongly typed language. Coding Conventions