Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
ivan_will
Partner - Creator II
Partner - Creator II

having problems with Macro : if v="......." then

Hi QV ers,

Could anyone help me with this macros:

I'm having error on this line : if v = "Alan" then ???? :Object doesn't support this property or method

sub setUser

set v = ActiveDocument.Variables("vUser")

msgbox(v.GetContent.String)

if v = "Alan" then

msgbox("ti si bace")

else

msgbox("tc ne 6te")

end if

end sub

1 Solution

Accepted Solutions
ivan_will
Partner - Creator II
Partner - Creator II
Author

Actually this works for me :

sub setUser

set v = ActiveDocument.Variables("vUser")

if v.GetContent.String = "Ivan" then

ActiveDocument.PlaySound "C:\Windows\Media\ding.wav"

else ActiveDocument.PlaySound "C:\Windows\Media\tada.wav"

end if

end sub



View solution in original post

9 Replies
johnw
Champion III
Champion III

I believe this is what you need:

set v = ActiveDocument.Variables("vUser").GetRawContent

With your code, I believe v was the variable object, not the text contents of the variable.

ivan_will
Partner - Creator II
Partner - Creator II
Author

It gives me Object required: '[string: "=USER_NICK"]' ???

So I have a variable vUser in QV

This variable is equal to who is the user from section access.

So I need to check who is the user (in the macro module) and than play sounds according to who is the user!

Thanks in advance!

johnw
Champion III
Champion III

I'm not sure what's wrong with yours, but here is working macro code from one of my applications that both checks and sets a variable's value.

set chartVariable = ActiveDocument.GetVariable("vDynamicChart")
chartID = chartVariable.GetRawContent
if chartID > "" then 'if there's already a dynamic chart
ActiveDocument.GetSheetObject(chartID).Close 'remove the old dynamic chart
chartVariable.SetContent "",false 'blank out the variable
end if

ivan_will
Partner - Creator II
Partner - Creator II
Author

Thanks for the fast response but I'm still having problems

the vUser in QV =USER_NICK (USER_NICK - from section access)

use macro:

sub setUser

set MacroUser = ActiveDocument.GetVariable("vUser")

check = MacroUser.GetRawContent

if check = "Willy" then

ActiveDocument.PlaySound "D:\PROJECTS\ADAC\nostart.wav"

end if

end sub



and it is called: ready

but the user is Willy and the if statement says that if check <> "Willy" then ?????

johnw
Champion III
Champion III

What does a msgbox(check) tell you is in the field?

ivan_will
Partner - Creator II
Partner - Creator II
Author

shittt : gives me "=USER_NICK"

ivan_will
Partner - Creator II
Partner - Creator II
Author

How to make it work correctly ?

Tnx.

johnw
Champion III
Champion III

I would assume you need to check the value in the format it's actually in (=USER_XXXX), and not the format you thought it was in (Xxxx).

sub setUser
set MacroUser = ActiveDocument.GetVariable("vUser")
check = MacroUser.GetRawContent
if check = "=USER_WILLY" then
ActiveDocument.PlaySound "D:\PROJECTS\ADAC\nostart.wav"
end if
end sub

ivan_will
Partner - Creator II
Partner - Creator II
Author

Actually this works for me :

sub setUser

set v = ActiveDocument.Variables("vUser")

if v.GetContent.String = "Ivan" then

ActiveDocument.PlaySound "C:\Windows\Media\ding.wav"

else ActiveDocument.PlaySound "C:\Windows\Media\tada.wav"

end if

end sub