QlikTip #17: Simulating the $(include) command in QlikView macros

Within load-scripts in QlikView there is the useful “$(include)” command available for including files containing some script to be used within the load-script.

Doing so it is easy to encapsulate and reuse some code used in several QlikView applications.

So organizing your code in load-scripts is easy, you can use several tabs and the $(include) command, whereas QlikView is not offering similar possibilities in the macro-editor. There are no tabs and “officially” there does not exist an corresponding command for including code in macros.

But that’s not the whole story, there is a nice possibility:
QlikTech is using the VBScript engine for interpreting the macro code by default (you could also use the JavaScript engine …). In VBScript there is a not very well known command called “ExecuteGlobal” (Official reference at MSDN, which “executes one or more specified statements in the global namespace of a script.”

So can we use that in QlikView macros?

Yes, we can!

Dim objFSO 'as Object
Dim objFile 'as Object
Dim strScript 'as  String

'// Open the File using File-System-Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("SOME_SCRIPT_TO_ENCLUDE.vbs")

'// Copy the content of the file
strScript = file.ReadAll

'// Just destroy the objects again
Call objFile.Close()

'// Execute the script globally
Call ExecuteGlobal(strScript)

Doing so at the beginning of the script you can now use the content defined in SOME_SCRIPT_TO_ENCLUDE.vbs in the subsequent macro code.

Because I am using this possibility of including existing scripts quite often I have improved the code above a little bit and created a function which I use in every application where I need this stuff:

'// *****************************************************************
'// Function for executing external content in your application.
'// ~
'// Parameters:
'//	p_strFilePath – full absolute path in relation to the QlikView application
'// ~
'// Return Value:
'//	Will return true if succeeded, otherwise false (e.g. if the file
'//	does not exist)
'// Examples:
'//	IncludeAndExecute(“D:\QlikView\Scripts\FileFunctions.vbs”)
'// Further information: http://www.qlikblog.at/509/
'// ******************************************************
Private Function IncludeAndExecute(ByVal p_strFilePath) 'as Boolean

'// Variable declaration
Dim objFSO 'as Object
Dim objFile 'as Object
Dim strScript 'as  String

'// Open the File using File-System-Objects
Set objFSO = CreateObject("Scripting.FileSystemObject")

'// prevent errors ...
On Error Resume Next

	Set objFile = objFSO.OpenTextFile(p_strFilePath)

	'// Copy the content of the file
	strScript = objFile.ReadAll

	'// Just destroy the objects again
	Call objFile.Close()

	'// Execute the script globally
	Call ExecuteGlobal(strScript)

	'// If an error occurred just return false
	If (len(Err.Description) > 0) Then
		IncludeAndExecute = false

		'// Just comment the following line if you want to suppress messages
		'// in case of errors
		msgbox(Err.Description)

		Exit Function
	End If
On Error Goto 0

IncludeAndExecute = true
End Function

And then I am using this code as follows:
Final Result when using the function IncludeAndExecute multiple times

For testing purposes you can download all the scripts and a sample application by clicking on the link below:

Advantages

  • Code reuse and code encapsulation is easier
  • Because you are now only using text-files integration into CVS-systems will be easier!
  • Because of using the File-System-Objects (FSO) you have to enable “System Access” in the macro-security settings!!!

Disadvantages

  • You are creating an unnecessary, artificial dependency between the included scripts and your QlikView-applications! So certainly you have to take care when changing your global scripts …
Bookmark and Share

Tags: , , , , , ,

A little tool for creating nested if-statements

Nested If-statements are sometimes necessary in QlikView- load-scripts, unfortunately.
They are quite difficult to read and very tricky to create and especially to debug.

In the last recent months I had a lot of projects where a tenfold nesting of if-statements was not uncommon.

After struggling with these nested ifs for a while I decided to create a little user-interface which helped me to decrease the time for creating nested if-statements.
Even if this tools is just a little, little helper it may also be helpful for you, so I decided to publish it here:

Try the “Nested If Generator” now

Some screenshots and explanation:

At the beginning you can define the “fieldname” to be generated” and define your first if-statement:
Let’s assume you are checking the two fields “Age” and “Profession”:

Defining the first if-statement

Defining the first if-statement

If you want to add an additional if-clause just click on “Add another IF-block”:

Adding a second if-statement

Adding a second if-statement

As you can see when comparing the two screenshots above the “else-block” of the first statement was removed and replaced by an additional if-clause.

After some further if-blocks the configuration could look like as follows:

After adding several if-statements

After adding several if-statements

Now the last step is easy, change to the “Generated Code” tab and copy your code:

Generated Code to be used in QlikView

Generated Code

The Tool is offering three different “Formatting Styles”:

Single line formatting

Single line formatting

Single line formatting

If-statements formatted like this were the main-reason for creating this tool :)

Indent style with one line per condition

Indent style with one line per condition

Indent style with one line per condition

This is my preferred formatting-style for really large if-statements with complex conditions

Indent style with one line per if-statement

Indent style with one line per if-statement

Indent style with one line per if-statement

This is my preferred formatting-style for if-statements with short conditions like demonstrated in this example …

Have fun :)

Bookmark and Share

Tags: , , ,

qlikblog.at is now published in English!

About four months ago I have created this blog for sharing my knowledge and ideas about business intelligence and especially QlikView.
In the last weeks I have received so many mails! Thanks!

But most of the mails I received were targeting one topic: “Why is your blog published in German” or “Could you please translate the article XY for me into English”, and so on …

Originally I have decided to publish this QlikView blog in my mother tongue, mainly because this blog was primarily planned as a service for my existing (and new customers) and they are located in Austria, Germany and Switzerland.

But I am indeed very interested in getting as much feedback as possible from the whole QlikView-community, that’s the main reason why qlikblog.at will from now on be published in English only.

So stay tuned, what can you expect from qlikblog.at in 2010:

  • In the last two months I have developed about a dozen of tools which should help you to develop your QlikView projects
  • In the next weeks I will also try to translate most of the existing articles written in German to English, so do not hesitate to revisit the page … :)
  • Certainly also new topics will be covered here …

So, do not miss any new article here and subscribe to the RSS-feeds or subscribe to the newsletter (which will only be sent to you when new articles are published).

Looking forward to an interesting year 2010.
Best regards
Stefan

Bookmark and Share

Tags: , ,

QlikTip #16: Zoom in QlikView-Applikationen und Zoom mit Makro automatisieren

QlikView hat eine Funktionalität, mit der man eine Applikation bzw. ein Arbeitsblatt/Sheet auf die aktuelle Fenstergröße anpassen kann.

Dazu wenden Sie bitte im QlikView-Windows-Client folgenden Befehl an:

Menü: “Ansicht” => “Zoom auf Bildschirmgröße anpassen”

Dadurch passt sich der Zoom des aktuellen Arbeitsblattes auf die aktuelle Bildschirmgröße an und zwar so, daß alle Objekte dieses Arbeitsblatts ohne zu Scrollen im Fenster sichtbar sind.

Wenn Sie diesen Zoom anschließend auf alle weitere Arbeitsblätter / Sheets übertragen wollen, dann gibt es auch eine Möglichkeit dazu:

Menü: “Ansicht“ => “Zoom auf alle Arbeitsblätter übertragen”

Zoom mit Makros automatisieren

Die oben beschriebene Funktionalität läßt sich nun auch mittels Makro automatisieren. Dieses Makro könnte zB im DocumentOnOpen-Event, oder dergleichen eingebunden werden:

ActiveDocument.ActiveSheet.FitZoomToWindow
ActiveDocument.GetApplication.WaitForIdle
ActiveDocument.ActiveSheet.ApplyZoomToAllSheets
ActiveDocument.GetApplication.WaitForIdle
Bookmark and Share

Tags: , , , ,

QlikTip #15: Layoutraster im Entwurfsmodus verkleinern

Zum möglichst komfortablen Anordnen von Objekten im QlikView Designer gibt es den “Entwurfsmodus”: Menü “Ansicht” -> “Entwurfsmodus” (bzw. Strg/Ctrl + G)

Dann wird ein Raster dargestellt, der einem hilft, Objekte anzuordnen:

Standardraster im Entwurfsmodus

Standardraster im Entwurfsmodus

Mir persönlich ist dieser Raster so grob zum Arbeiten, lieber hätte ich den feinmaschiger:

Benutzerdefinierte Rastergröße im Entwurfsmodus

Benutzerdefinierte Rastergröße im Entwurfsmodus

Diese Einstellung finden Sie unter:
Menü: „Einstellungen“ -> „Benutzereinstellungen“ (bzw. Strg/Ctrl + Alt + U), dann im Reiter „Design“ den „Linienabstand (mm)“ auf die gewünschte Größe einstellen (in meinem Fall präferiere ich 5 mm).

Einstellen des Layoutrasters in den Benutzereinstellungen

Einstellen des Layoutrasters in den Benutzereinstellungen

Bookmark and Share

Tags: , ,

QlikTip #14: Fehlende Layoutoptionen (Rahmen, abgerundete Ecken, etc.)

Da ich jetzt schon mehrfach die Frage bekommen habe, wieso die erweiterten Layout-Optionen im Eigenschaftsdialog eines Objektes fehlen hier die Antwort:

Wenn der Eigenschaftsdialog im QlikView-Windows-Client plötzlich so aussieht:

Fehlende Layoutoptionen im Eigenschaftsdialog von Objekten

Fehlende Layoutoptionen im Eigenschaftsdialog von Objekten

Sie hätten diesen Dialog aber gerne (wieder) so:

Eigenschaftsdialog eines Objektes mit erweiterten Layoutoptionen

Eigenschaftsdialog eines Objektes mit erweiterten Layoutoptionen

Dann ist nur folgendes zu tun:

Menü: „Einstellungen“ -> „Eigenschaften des Dokumentes“ (bzw. Strg/Ctrl + Alt + D) und dann im Reiter „Allgemein“ das „Aussehen der Objekte“ auf „Erweitert“ einstellen:

Einstellen der erweiterten Layoutoptionen in den Benutzereinstellungen

Einstellen der erweiterten Layoutoptionen in den Benutzereinstellungen

Wann genau diese Option sich zurückgestellt hat, konnte ich bei mir nicht reproduzieren; zunächst dachte ich, es hängt mit der Installation von QlikView 9 zusammen; da sich dieses Verhalten auch bei Kunden mit QlikView 8.5 gezeigt hat, kann ich keine schlüssige Aussage mehr dazu treffen ;)

Bookmark and Share

Tags:

QlikTip #13: Verschlüsselung von Daten

QlikView Dokumente beinhalten oftmals äußerst sensitive und heikle Daten.

Was tun, wenn Sie die Daten dennoch „außer Haus“ geben wollen und müssen, z.B. wenn Sie auf Ihrem Laptop weiterentwickeln wollen, wenn Sie eine Beispielapplikation an den Support oder an eine QlikView-Berater schicken wollen?
Kein Problem, dafür gibt es eine Funktionalität in QlikView, die diese Anforderungen abdeckt: Verschlüsselung!

Spielen wir die Verschlüsselung anhand einer einfachen Beispielapplikation durch, die folgende Daten beinhält:

Beispiel der Verschlüsselung, Schritt für Schritt

Datenstruktur der Demo-Applikation

Datenstruktur der Demo-Applikation

Wenn die Daten sorglos aus der Hand gegeben werden können sollen, dann wären folgende Felder zu verschlüsseln:

Tabelle Kunden:

  • Firma
  • KontaktName
  • Straße
  • Telefon

Tabelle Bestellungen:

  • Spediteur
  • UmsatzBestellung

Also, machen wir uns ans Werk:
Unter Einstellungen -> Eigenschaften des Dokumentes (bzw. Strg + Alt + D) gibt es den Reiter Verschlüsselung:

Eigenschaftsdialog des Dokumentes, Tab "Verschlüsselung"

Eigenschaftsdialog des Dokumentes, Tab "Verschlüsselung"

Viel brauche ich jetzt nicht mehr zu erklären:

  • Wählen Sie die gewünschten Felder im linken Bereich aus
  • und klicken Sie anschliessend auf den „Verschlüsseln“ Button (mit gedrückter Strg/Ctrl-Taste können mehrere Felder selektiert werden)
  • Je nachdem, wie groß Ihre QlikView-Applikation ist, kann der Vorgang des Verschlüsselns natürlich einige Zeit in Anspruch nehmen

Achtung: Beachten Sie bitte, dass der Vorgang des Verschlüsselns nicht mehr rückgängig zu machen ist, daher vorher eine Sicherung des Originaldokumentes machen!

Wie werden die Daten verschlüsselt?

Schauen wir uns abschließend noch schnell an, was aus den Originaldaten geworden ist:

Nachfolgende Grafik zeigt jeweils die Daten der Felder „UmsatzBestellung“ und „Firma“ vor und nach der Verschlüsselung an.

Gegenüberstellung der Daten vor und nach der Verschlüsselung

Gegenüberstellung der Daten vor und nach der Verschlüsselung

Auffallend ist (zum Glück), dass die Verschlüsselung intelligent umgesetzt wurde:

  • Aus Text bleibt Text (da werden einfach nur Buchstaben vertauscht)
  • Zahlen bleiben Zahlen, auch das Format bleibt gleich, selbst die Größenordnung der Zahlen bleibt ungefähr in einer sinnvollen Relation.

So lassen sich mit diesen Daten auch sinnvolle Demos entwickeln!

Bookmark and Share

Tags: , , ,