
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Macro: in VBScript or JScript?
Hi everyone,
As I would like to create some macros to do some strong calculations on my fields, I would like to know what are the main differences between VBScript and JScript. Is one better than the other to do some tasks? Is one easier to use/code? I have no special skills in one of these languages, so I would like to study the best one.
Thank you for your answers
Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi
as far as i know there isn't much difference in the capabilities of either of the languages, except maybe in a way of convenience .
if there are any differences, then they probably wont effect what you need to do in qlikview using macros.
as a good practice i normally try to avoid macros altogether and use them only for simple tasks or for automation purposes (like batch exporting to excel or emailing)
as regarding this:
I have to do strong calculations in a factory background. I have many records for an item, I have to select particular records to calculate time between stations, and the calculations have to be different if there are breakages or not... And then put the final time calculated in a field to 'link' it to the item. I hope it makes sense for you.
it sounds to me like this problem could (should) be solved in the script and/or layout and not with a macro.
if you could post a sample or explain about your original problem, I'm sure a solution cold be found.
Mansyno

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
http://en.wikipedia.org/wiki/VBScript
http://en.wikipedia.org/wiki/JScript
While many will laugh at using Wikipedia it's still good to get on overview as a starting point. I'm not an expert in either code, but in my experience VB has been by far the easier to learn, use and understand.
Without more information on what you are trying to do I won't go and post any information I have on each code - But Google is very friendly if you want to know common limitiations/advantages of each code.
Personally, I would roll with VB. Unless it has a severe limitation that will prevent what you are trying to do I believe it will be easier.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I know that Google is my friend, but as far as I know in general you cannot choose which language you will use. Therefore people don't compare the two languages. Moreover, I saw that there were some limitations in the languages (such as a specific library for JScript), that's why I wanted to have some feedback from Qlikview programmers.
I have to do strong calculations in a factory background. I have many records for an item, I have to select particular records to calculate time between stations, and the calculations have to be different if there are breakages or not... And then put the final time calculated in a field to 'link' it to the item. I hope it makes sense for you.
I guess this is the best way to do with macro, if not please tell me.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi
as far as i know there isn't much difference in the capabilities of either of the languages, except maybe in a way of convenience .
if there are any differences, then they probably wont effect what you need to do in qlikview using macros.
as a good practice i normally try to avoid macros altogether and use them only for simple tasks or for automation purposes (like batch exporting to excel or emailing)
as regarding this:
I have to do strong calculations in a factory background. I have many records for an item, I have to select particular records to calculate time between stations, and the calculations have to be different if there are breakages or not... And then put the final time calculated in a field to 'link' it to the item. I hope it makes sense for you.
it sounds to me like this problem could (should) be solved in the script and/or layout and not with a macro.
if you could post a sample or explain about your original problem, I'm sure a solution cold be found.
Mansyno

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
VBScript is probably syntactically easier. JScript might be better if you need to do things like bitwise operations.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you for all your answers.
@Mansyno: my problem is I use in the script a connection to a database, with SQL query, and I don't know then how to make a calculation coming from 2 fields from different databases. Here is an example of what I would like to do.
ODBC CONNECT TO [server ];
select * from db1;
select * from db2;
select * from db3;
load
if ( db1.field1<1 , networkdays(db2.field2,db3.field3), networkdays(db2.field4,db3.field5)) as Date,
db1.field6 as Reference;
I know that the syntax is incorrect, this is just to illustrate what I would like. In fact, I would like to add a new calculated field to a database, that's why I load db1.field6, to 'link' it to db1.
I have already tried some things with "map" or "table1: .... resident table1" but I didn't succeed to do anything, my fields weren't found. However these syntax aren't very clear to me when we have to use several references to several databases so I surely made something wrong.
Until now, I made these calculations in expressions and it works quite well, but I will be very happy to make them in the script to make my expressions less complex. As I need to go further, I should calculate something like that (for information, I am working on a report for a factory, and I have to calculate the delays added by each station on each product) :
table1:
InputField Delay;
select * from db1;
load db1.fieldKey, RowNo() as Delay resident table1; // I put RowNo() because the field Delay doesn't exist, but I guess it can be any value
foreach(Reference)
Let Date1= Max({$<db1.field1={1}>} db1.field2)
Let Date2=Max({$<db2.field1={1}>} db2.field2)
Let Result=if( Date1<Date2, networkdays(Date,Date1), networkdays(Date,Date2))
Delay.SetInputFieldValue 0,result // how should I get the offset? something like RowNo(db1.fieldKey)?
end foreach
I know it is quite complicated, but so far it is the only idea I have. I hope this "code" make a little bit sense for you.
I create a input field, because I have to create a new field to store each delay added for each item. So I link it to a field with unique value, db1.fieldKey. Then I make a loop for all the item with Reference, I get the dates I need, I make my calculations (which are simplified here), and then I store the value in my input field. Is the offset needed here? If so, how do I have its value? I also think to put in the code field1Key.select(), and this way there is only one value for Delay, but I don't know if it's a good idea or not.
Any idea/help is welcome (and thank you for reading me until the end).

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
hi,
i started to write a lengthy reply but i decided to ask you first
these tables in your example are they connected in some way? with common fields?
if you execute only the first 3 line of script where you get the db1 db2 and db3 table, do you get any lines conecting them in the qlikview table viewer?
can you post a sample of the fields in these 3 tables?
i believe that with qv capabilities you can do it all in the script but more information is needed for a better solution
Mansyno
P.S.
you should start thinking more like a dba and less like a programmer 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Sorry for late reply, but I was quite busy and I receive a training on Qlikview, so it is a little bit easier for me ^^ To answer you Mansyno, yes my 3 databases are linked by one field.
In fact I will try to make my calculations in a script, which is the best way. Now my problem is to calculate something with 2 different fields from 2 different databases. I cannot concatenate the databases because I have a relation of one to many, so I tried something with mapping but it doesn't work... The field is not found.
Here is a sample of my code:
RXORD:
BUFFER LOAD "RXORD_SEQNO",
RCVNO,
// RCVDATE,
// Date#(RCVDATE,'YYYYMMDD') as RCVDATE_OK,
LABOCD,
TRAYNO,
"TRAYNO"&' '&"LABOCD" as TRAYNOLABOCD;
SQL SELECT *
FROM HOYA."ARCV_RXORD"
WHERE (HOYA.ARCV_RXORD.RCVDATE>=20091220) and (HOYA.ARCV_RXORD.RCVDATE<=20100120);
RCVDATE_MAP:
mapping buffer load
RXORD_SEQNO,
RCVDATE;
SQL select *
from HOYA."ARCV_RXORD"
WHERE (HOYA.ARCV_RXORD.RCVDATE>=20091220) and (HOYA.ARCV_RXORD.RCVDATE<=20100120);
RXORD_PROC:
buffer LOAD "RXORD_SEQNO",
applymap('RCVDATE_MAP',RXORD_SEQNO) as RCVDATE,
"REQPASSDATE_01",
if(right(RCVDATE,4)<700,
if(REQPASSDATE_01>1000,
makedate(Year(date#(RCVDATE,'YYYYMMDD')),month(Date#(REQPASSDATE_01,'MMDD')),day(Date#(REQPASSDATE_01,'MMDD'))),
makedate(Year(date#(RCVDATE,'YYYYMMDD')),month(Date#(REQPASSDATE_01,'MDD')),day(Date#(REQPASSDATE_01,'MDD')))
),
if(REQPASSDATE_01>1000,
makedate(Year(date#(RCVDATE,'YYYYMMDD')),month(Date#(REQPASSDATE_01,'MMDD')),day(Date#(REQPASSDATE_01,'MMDD'))),
makedate(Year(date#(RCVDATE,'YYYYMMDD'))+1,month(Date#(REQPASSDATE_01,'MDD')),day(Date#(REQPASSDATE_01,'MDD')))
)
) as REQPASSDATE_01_OK;
SQL SELECT *
FROM HOYA."ARCV_RXORD_PROCESS"
where STDDLVDATE>=20091220 and STDDLVDATE<=20100120;
The purpose is I need to add a year to REQPASSDATE_01 because it doesn't have to use it in networkdays in expressions further. So I take the year from RCVDATE which is in another database (I cannot use a date in the same database because there is not). But the problem is the field is not found. Can't I use a mapped field in a calculation? Or where is my problem? Any other idea?
Thanks
ps: Mansyno, if I was the dba, I would change MANY things in the databases, but unfortunately I am not ^^
