Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

vbscript function returns Null Value

Hi everyone !

I have a problem using a personal vbscript function in qlikview.

What am I trying to do is :

- Retrieve the selected date

-Transform the date into an Unix TimeStamp

-Send the value to a qlikview variable

The problem is that I retrieve a Null value from the vbscript function.

VBSCRIPT :

<pre>FUNCTION DateToTimestamp() set val = ActiveDocument.Fields("Year").GetSelectedValues set val1 = ActiveDocument.Fields("Month").GetSelectedValues set val2 = ActiveDocument.Fields("Day").GetSelectedValues SELECT CASE val1.Item(0).Text case "janv" b=1 case "fév" b=2 case "mars" b=3 case "avr" b=4 case "mai" b=5 case "juin" b=6 case "juil" b=7 case "août" b=8 case "sept" b=9 case "oct" b=10 case "nov" b=11 case "déc" b=12 END SELECT SELECT CASE val1.Item(val1.Count-1).Text case "janv" c=1 case "fév" c=2 case "mars" c=3 case "avr" c=4 case "mai" c=5 case "juin" c=6 case "juil" c=7 case "août" c=8 case "sept" c=9 case "oct" c=10 case "nov" c=11 case "déc" c=12 END SELECT datec = val.Item(0).Text & "/" & b & "/" & val2.Item(0).Text datef = val.Item(val.Count-1).Text & "/" & c & "/" & val2.Item(val2.Count-1).Text 'msgbox(datec) 'msgbox(datef) DateToTimestamp= DateDiff("s","1/1/1970",datec) '& "-" & DateDiff("s","1/1/1970",datef) 'msgbox(selectedYear) END FUNCTION
QlikView :
<pre>
let timestampSelected = DateToTimestamp();
Is this a problem with my vbscript function or with qlikview?
Regards,
Adrian
1 Reply
Not applicable
Author

Hello Adrian

The function is probably ok but you can't use GetSelectedValues from the load-script.
You should be able to use a trigger instead when the document is opened.
Go to document properties (Ctrl+Alt+D), the tab triggers and add a trigger to execute your macro when the document is opened.
You also need to change your macro from a function to a sub.

/Fredrik