Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Writing log using a VB macro

Hi

I'm trying to use a VB macro inside the QV loading script in order to write an activity log, but I'm not having luck.

First, this is the code included in the macro section:

Dim objFSO

Dim logFile

Function openOutputFile(filename)

Rem *** Create and open an output file

    CONST ForWriting = 2

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set openOutputFile = objFSO.OpenTextFile(filename, ForWriting, True)

End Function

CONST LOGFILE_NAME = "D:\tmp\test1.log"

Function WriteLog(message)

    logFile = openOutputFile(LOGFILE_NAME)

    logFile.WriteLine(message)

    logFile.Close

End Function

and inside the QV script, (i.e. in Main tab) the WriteLog function is invoked:

LET x = WriteLog("test");

The file is being created, but it is empty.

Could you please provide some advice

Thanks in advance!

Regards,

Jesús

1 Solution

Accepted Solutions
Miguel_Angel_Baeyens

Hi Jesús,

Just change this line

logFile = openOutputFile(LOGFILE_NAME)

to this line

Set logFile = openOutputFile(LOGFILE_NAME)

That should work.

Miguel

View solution in original post

1 Reply
Miguel_Angel_Baeyens

Hi Jesús,

Just change this line

logFile = openOutputFile(LOGFILE_NAME)

to this line

Set logFile = openOutputFile(LOGFILE_NAME)

That should work.

Miguel