Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

Declaring Variables in VBScript

Hi all,

This is driving me crazy...... I wish to set a variable in VBScript but it's not working.

This is my code....

I am creating a number of folders and I wish to set each folder path as a variable:

' set ocr path

SUB Ocr (objVariable)

  ON ERROR RESUME NEXT

  SET objShell = CREATEOBJECT("Shell.Application")

  SET objFolder = objShell.BrowseForFolder (WINDOW_HANDLE, TITLE, OPTIONS, ROOT)

  SET objFolderItem = objFolder.Self

  ocrFolder = objFolderItem.Path

  SET objSavePath = ActiveDocument.Variables(objVariable)

  objSavePath.SetContent ocrFolder, TRUE

  ON ERROR GOTO 0

'create folders

Dim oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

' Create OCR folder

oFSO.CreateFolder ocrFolder & "\OCR"

oFSO.CreateFolder ocrFolder & "\OCR\Output"

oFSO.CreateFolder ocrFolder & "\OCR\Output\Single_File"

oFSO.CreateFolder ocrFolder & "\OCR\Staging"

oFSO.CreateFolder ocrFolder & "\OCR\Archive"

dim outputFolder

outputFolder = ocrFolder & "\OCR\Output\Single_File"

dim stagingFolder

stagingFolder = ocrFolder & "\OCR\Staging"

dim archiveFolder

archiveFolder = ocrFolder & "\OCR\Archive"

end sub



ocrFolder is defined (e.g. c:mydocs\myfolder)



My issue is that outputFolder , stagingFolder & archiveFolder  are not being created?


What am I doing wrong? 

5 Replies
MVP & Luminary
MVP & Luminary

Re: Declaring Variables in VBScript

The reason could be the use of relative paths. For this topic see also: Using relative paths in variables.

- Marcus

autopilot
Contributor III

Re: Declaring Variables in VBScript

Haven't tested but what happens if you try setting the oFSO.CreateFolder commands to a variable and call it directly?

i.e.

'create folders

Dim oFSO

Set oFSO = CreateObject("Scripting.FileSystemObject")

' Create OCR folder

set f1 = oFSO.CreateFolder ocrFolder & "\OCR"

set f2 = oFSO.CreateFolder ocrFolder & "\OCR\Output"

set f3 = oFSO.CreateFolder ocrFolder & "\OCR\Output\Single_File"

set f4 = oFSO.CreateFolder ocrFolder & "\OCR\Staging"

set f5 = oFSO.CreateFolder ocrFolder & "\OCR\Archive"

CreateFolderF1 = f1.Path

CreateFolderF2 = f2.Path

CreateFolderF3 = f3.Path

CreateFolderF4 = f4.Path

CreateFolderF5 = f5.Path

Not applicable

Re: Declaring Variables in VBScript

Thanks for the replies - I couldn't get it to work.

So I just had to use the variable + 'the end folder path (hard coded)', throughout my code.

Not applicable

Re: Declaring Variables in VBScript

Hi Jammy,

From the script it looks like you are using "BrowseForFolder " which will give you a pop up to select the path. If you cancel that pop up it will create folders in default location may be in "C:" or "C:\Program Files\QlikView".

You can check the above mentioned folders, all the folders which you were creating using macro must have been created somewhere in your machine.

PS: As per your script, ocrFolder is nothing but a variable which is already appended before the folder path, I am not sure why are you adding another variable.

Hope it helps.

Regards,

Sakir

MVP & Luminary
MVP & Luminary

Re: Declaring Variables in VBScript

Like in my link from above the logic could be like relative paths even if the in the end used path is a full-path (and therefore is no need to hard-code the paths).

- Marcus