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

Macro randomly does not set variable?

Greetings.

I have a macro that sets variables that is setting a start and end age:

ActiveDocument.Variables("vAgeEnd").SetContent "63", true
ActiveDocument.Variables("vAgeStart").SetContent "23", true

There are all sorts of age ranges that it sets, based on a number of things in the system. Occasionally, it will set one age, and not the other. I found that if I changed the order of the settings (Usually I set vAgeStart first, then the vAgeEnd) it "fixes" the problem, but then later on, if I happen to be coming from a particular selection, it won't work. In some cases, in the one macro, I set these two variables more than once.

Has anyone ever seen anything like this? Is it a known problem? Its killing me, because I'm constantly rechecking my code, thinking I've programmed something wrong.

Thanks.

1 Solution

Accepted Solutions
Not applicable
Author

DUH.

I forgot I had constraints on these. If the new vAgeStart date was greater than the current vAgeEnd, it wouldn't update the variable (but I got no warning message like if I tried to do it manually). So. I check for the old values before adding the new values and it all works file.

View solution in original post

4 Replies
Anonymous
Not applicable
Author

Sally,
Try to insert WaitForIdle or Sleep before each variable setting.

Not applicable
Author

I tried with WaitForIdle, but didn't seem to make a difference (other than generally slowing down the screen). But I may have not tried it before each setting. I'll give that a try and see what happens.

Not applicable
Author

Did the following:

ActiveDocument.GetApplication.WaitForIdle 3000
ActiveDocument.Variables("vAgeEnd").SetContent "1", true
ActiveDocument.GetApplication.WaitForIdle 3000
ActiveDocument.Variables("vAgeStart").SetContent "1", true
ActiveDocument.GetApplication.WaitForIdle 3000

And vAgeEnd remained the 999 it was before executing these statements.

Not applicable
Author

DUH.

I forgot I had constraints on these. If the new vAgeStart date was greater than the current vAgeEnd, it wouldn't update the variable (but I got no warning message like if I tried to do it manually). So. I check for the old values before adding the new values and it all works file.