Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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
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
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
Bingo !!!
Thank you a lot Cwolf.