Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
G_Zeni
Contributor
Contributor

Vb function included using ExecuteGlobal not working in load-script

Hello,

Before writing this message I spent a lot of time (without success) to read blogs in order to find a solution.

The goal is simpy: I want to share and reuse vb code as function in load-script between different QlikView applications.

The way I tried to di it is to put vb code into a file and load it using vb ExecuteGlobal statement.

For test I did as follow:
1) I created a file named "vbCode.vb" with this simply content:

function f_externalSum(p_val1, p_val2)
f_externalSum = p_val1 + p_val2
end function

2) In macro editor I succesfully loaded vb code from "vbCode.vb" file using "ExecuteGlobal" as described in many posts and I noticed that vb functions code name (f_externalSum) is correctly load inside macro editor.

3) In script editor (not macro editor) I wrote this code:

let totalExternal = f_externalSum(5, 2);

The editor did not show any syntax error (it recognized the f_externalSum function)


The problem: when I run the load script I receive "syntax error".

 

 

Macro code:

call Include()

sub Include()
Dim v_vbCodeFile, o_fso, o_file, v_vbCode

v_vbCodeFile = ".\vbCode.vb"
Set o_fso = CreateObject("Scripting.FileSystemObject")
set o_file = o_fso.OpenTextFile(ActiveDocument.GetProperties.MyWorkingDirectory & "\" &v_vbCodeFile)
v_vbCode = o_file.ReadAll
o_file.Close
ExecuteGlobal v_vbCode
end sub

 

1 Solution

Accepted Solutions
cwolf
Creator III
Creator III

If you call a macro from script, you have no access to the "ActiveDocument" object or to the "Application" object. Thatswhy you have to use a absolute path to external scripts in macro.

Normally, you will have a global share for external scripts (qvs and vb), for example "\\server\scripts\":

call Include()

sub Include()
    v_vbCodeFile = "\\server\scripts\vbCode.vb"
    Set fso = CreateObject("Scripting.FileSystemObject")
    ExecuteGlobal fso.OpenTextFile(v_vbCodeFile).ReadAll
end sub

View solution in original post

2 Replies
cwolf
Creator III
Creator III

If you call a macro from script, you have no access to the "ActiveDocument" object or to the "Application" object. Thatswhy you have to use a absolute path to external scripts in macro.

Normally, you will have a global share for external scripts (qvs and vb), for example "\\server\scripts\":

call Include()

sub Include()
    v_vbCodeFile = "\\server\scripts\vbCode.vb"
    Set fso = CreateObject("Scripting.FileSystemObject")
    ExecuteGlobal fso.OpenTextFile(v_vbCodeFile).ReadAll
end sub
G_Zeni
Contributor
Contributor
Author

Bingo !!!

 

Thank you a lot Cwolf.