Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Need to write macro for showing prime numbers

Hi All,

I have a table which contains some numbers say 1 to 100. My requirement is to show a message or alert once i click on any of the rows in the table if it is a prime number. I am not familiar with macros to deal with this situation. Can anyone guide me to achieve this. Help is much more appreciated since i am struggling to writa single macro for last one week.

Thanks,

sujeet

6 Replies
m_woolf
Master II
Master II

See attached qvw

Not applicable
Author

Hi,

I am not able to open this file since i dont have the licensed version of Qlikview. Please paste the scripts.

Thanks,

Sujeet

m_woolf
Master II
Master II

The field which has the number is named Num.

In Document Settings|Triggers, I created an OnSelect Action for the Num field to run a macro:

=if(Getselectedcount(Num) = 1,'IsPrime')

Here is the macro script:

sub IsPrime

set val=ActiveDocument.Fields("Num").GetSelectedValues

intNum = val.Item(0).Text

if intNum = 1 then exit sub

blnIsPrime = True

for i = 2 to intNum -1

  If intNum mod i = 0 then blnIsPrime = False

next

if blnIsPrime then msgbox "Prime"

end sub

Not applicable
Author

Hi,

Thanks for the reply.

I tried the following steps as described by you.

Created my table with following data.

PrimeTable:

LOAD * INLINE [

    numbers,

    1,

    2,

    3,

    4,

    5,

    6,

    7,

    8,

    9,

    10

];

Added a "table box".

Created the macro.

I have added the trigger in the following way.

Untitled.png

tab.png

But once I click any of the values the macro window comes which shows the vb script.

I dont know if have missed something.

Thanks,
Sujeet

m_woolf
Master II
Master II

I can't read the complete expression you set in the trigger.

You haven't posted your macro code.

When the macro window appears, is a lone of code highlighted? If so, which line?

Not applicable
Author

This is working now. Thanks for your help