Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

If Statement in a Macro

I have a field call Shift time which is Day or Night. Based on the current time that the Application is opened I want to display only the Day shift hours production or the Night shift production.

My If statement would look like this

If (Hour(localtime()) between 7 and 19 then 'Day','Night')

I have no idea how to do this or where to start.

1 Reply
Not applicable
Author

Hello Susan

The following should help you out.

1. Create a variable in the application called vTimeOpen

2. Create a Macro in your Macro code as follows:

SUB SetOpenTime

ActiveDocument.Variables("vTimeOpen").SetContent HOUR(Now()), true

END SUB

3. Call this Macro when opening the document, go to Settings, Document Properties, Macros, then on the document event triggers section, add the macro to the OnOpen event. This means that every time the document is opened, this macro will be called and the value of the variable will be set to the current hour.

4. In you chart/table etc, you can use the following expression: =IF ( vTimeOpen >= 7 AND vTimeOpen <=19 , 'Day', 'Night' )

That should do it for you.

Regards,

Nigel.