Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
riyazasma1009
Creator
Creator

Using relative paths in variables

Hi All,

I have a vbscript which performs the action of reducing data(File - > Reduce Data -> Select Possible).

Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(vFilePath,0,False)
MyDoc.ReduceData
MyDoc.SaveAs(vFilePath)
MyDoc.CloseDoc
Set MyApp = Nothing

vFilePath contains the absolute file path of the qvw to be reduced. The issue here is the above code does not work when relative paths are used in vFilePath whereas it works perfectly fine for absolute paths.

Can anyone please help me with the same.

Thanks,

Asma

1 Solution

Accepted Solutions
marcus_sommer

I have had now a look on google to relative paths within vbs and it seems that there is no native way to execute them. What I have found are various kinds of workarounds to generate a fullpath and here is one possible solution adapted to qlikview:

sub Test

dim vTest, vFolderCount

vTest= "\applications other\calendar4-5-4.qvw"

vFolderCount = len(vTest) - len(replace(vTest, "\", ""))

vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest

msgbox vTest

call ReduceData(vTest)

end sub

- Marcus

View solution in original post

6 Replies
marcus_sommer

AFAIK relative paths do work in vbs. Therefore I think that your relative path isn't correct and/or the syntax isn't right and you might need additionally double-quotes around the path.

- Marcus

riyazasma1009
Creator
Creator
Author

Hi Marcus,

The folder structure is as shown below:

The Qlikview file containing the macro code for reducing data is present in folder B.

The folder Application contains the qvw file to be reduced.

In the vbscript, I have given the relative path as:

dim vTest

vTest= "..\A\ABC\Application\Reduce_data.qvw"

If I use the absolute path in the code, then it runs fine without giving any error. Whereas if relative path Is given, it throws an error as Object required : 'MyDoc' at the line "MyDoc.ReduceData"

VBscript code:

Function ReduceData(vFilePath)

Set MyApp = CreateObject("QlikTech.QlikView")
Set MyDoc = MyApp.OpenDocEx(vFilePath,0,False)
MyDoc.ReduceData
MyDoc.SaveAs(vFilePath)
MyDoc.CloseDoc
Set MyApp = Nothing
end Function

'ITP Dashboard
sub Test
dim vTest
vTest= "..\A\ABC\Application\Reduce_data.qvw"
call ReduceData(vTest)
end sub

Could you please help me with the same.

Thanks,

Asma

marcus_sommer

I have had now a look on google to relative paths within vbs and it seems that there is no native way to execute them. What I have found are various kinds of workarounds to generate a fullpath and here is one possible solution adapted to qlikview:

sub Test

dim vTest, vFolderCount

vTest= "\applications other\calendar4-5-4.qvw"

vFolderCount = len(vTest) - len(replace(vTest, "\", ""))

vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest

msgbox vTest

call ReduceData(vTest)

end sub

- Marcus

riyazasma1009
Creator
Creator
Author

Thanks Marcus for the quick reply!

The VB Code is working as expected.

I just need a small clarification. Could you please explain what does the below line of code mean:

vTest = ActiveDocument.evaluate("left(DocumentPath(), index(DocumentPath(), '\', " & -vFolderCount & ") - 1)") & vTest

Thanks,

Asma

marcus_sommer

The logic is to read the full-path from the current script and cut the right-part to the x-number of backslashes (counted before in vFolderCount) and then adding the used relative-part which is then together a valid full-path again.

The backslash-counting is done here in vbs because it's quite simple with len + replace. To cut a string to a variable point isn't so easy in vbs and therefore it's done with qlikview-functions called per evaluate().

- Marcus

riyazasma1009
Creator
Creator
Author

Thanks Marcus!!