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: 
orital81
Partner - Creator III
Partner - Creator III

Send Variable to a Macro Function

Hi,

Im using a Column Adjustmant macro to set the column width.

Im a Macro suggested by Gysbert Wassenaar

Sub

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

ColCount = val.count

ColWidth = 2000/ColCount

if ColWidth > 200 then ColWidth = 200

if ColWidth < 20 then ColWidth = 20

set chart = ActiveDocument.GetSheetObject( "CH01" )

chart.SetPixWidth val.count,ColWidth

end sub

it's working great except when I clear selection  the macro fails (I guess since ColCount= 0 and we devide by 0)

Im trying to overcome this by using GetPossibleCount in a variable and sending it to the function

but I cannot get it working..

I will appreciate any help here. See attached file.

CAdjust1 is using the variable while CAdjust is without (doesn't work when I clear all)

Thanks in advance

6 Replies
orital81
Partner - Creator III
Partner - Creator III
Author

Just to simplify my Question: How do I pass a variable to a function?

Im using this approach: func(($var)). But it doen't work  )-:

any other ideas?

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

HI,

     Try this.

          set v = ActiveDocument.Variables("Variable1")

          msgbox(v.GetContent.String)

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
orital81
Partner - Creator III
Partner - Creator III
Author

Thanks for the fast reply Kaushik

My variable is not a result of a function,

So when I use your suggestion I see : "GetPossibleCount(FunctionblockDesc)"

instead of the value of it.

Any suggesitons?

See attached (press on CAdjust1 button)

kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

     Go to variable overview and add = at start of your expression.

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
orital81
Partner - Creator III
Partner - Creator III
Author

Thanks, only = didn't work.

I added =Num(GetPossibleCount(FunctionblockDesc)) and it shows the value.

But still when clearing selection it returns the number but opens the macro edit, as if there was an error.

Any Idea Why?

See attached, (press CAdjust1 button)

orital81
Partner - Creator III
Partner - Creator III
Author

Sorry, My bad. there was another trigger that opened the error macro.

It works Now,

Thanks a lot!

Ori