vbavbscripthp-uftuft14

UFT 14.00 how to use a property of function in different actions


I have this problem in UFT/QTP 14.00. I want use a property from a function to write a log file, but return this error when run the action.

Error message: Object doesn't support property or method

Here is my code:

Function Escrito
    'Function in VBS
    'Habilitamos la creacion y modificacion de archivos
        'Enable Create and update files
     Set fso=createobject("Scripting.FileSystemObject")
     set Stream = fso.CreateTextFile("C:\Users\HCCMD\Documents\test.txt")
     Escrito = Stream
End Function

I want use Escrito().write "Hola mundo" for example.


Solution

  • You forgot Set.

    Set Stream = fso.CreateTextFile("C:\Users\HCCMD\Documents\test.txt")
    Set Escrito = Stream
    

    Or, easier

    Set Escrito = fso.CreateTextFile("C:\Users\HCCMD\Documents\test.txt")
    

    Also see: What does the keyword Set actually do in VBA? (applies to VBScript as well)