Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

souadouert
Contributor III

mid functon in macro

I used this script to export straight table with each selection date_s(yyyy/mm)

Si have to store each file qvd with this  ruls "straight"num_month .qvd

So i used this funtion NAMEFILE=Instr(String,6,2) to extract th month like MID() FUNTION

eg: 2017/10  title=10

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

set obj = ActiveDocument.GetSheetObject("CH173")

set String=(val.Item(i).Text)

NAMEFILE=Instr(String,6,2)

    obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next


but i have error Object required: '[string: "12/2015"]'

1 Solution

Accepted Solutions

Re: mid functon in macro

Yeah. Here is the correct code.

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

      ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

      set obj = ActiveDocument.GetSheetObject("CH173")

      NAMEFILE=  Right (val.Item(i).Text, 2)

     obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next

8 Replies

Re: mid functon in macro

Hi Souad,

Why not you use right function?

NAMEFILE = Right(val.Item(i).Text,2)

souadouert
Contributor III

Re: mid functon in macro

we cAn use with macro RIGHT()?


Re: mid functon in macro

Yeah. Here is the correct code.

set val=ActiveDocument.Fields("date_s").GetPossibleValues

for i=0 to val.Count-1

      ActiveDocument.Fields("date_s").Select (val.Item(i).Text)

      set obj = ActiveDocument.GetSheetObject("CH173")

      NAMEFILE=  Right (val.Item(i).Text, 2)

     obj.ExportEx "C:\Users\04488\Desktop\Vision\straight"& NAMEFILE & ".qvd",4

next

souadouert
Contributor III

Re: mid functon in macro

THANK YOU

mwoolf
Honored Contributor II

Re: mid functon in macro

You can use mid or right, but I'm guessing you will get an error with your filename. If val(item(i),Text contains "/". These are not valid symbols in file names. I usually use the replace function to replace "/" with "-".

Highlighted

Re: mid functon in macro

Hi M W,

You are right. But Souad is taking only the month numbers (01, 02... 12) from the date field. So I am pretty sure, it won't throw any error.

souadouert
Contributor III

Re: mid functon in macro

thank you for your interactivity

Re: mid functon in macro