Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How do I change the width and height of an object with a macro based on a variable.

Hello everyone,

I added a qlikview document to help explain my question. What I am trying to achieve is on the right part of this Qlikview document and on the left of the qlikview document we find the examples I used as inspiration.

What am I trying to achieve on the right? I want people to be able to type in a number under "Insert desired Width: " and when they press the button "Resize" it uses that number to resize "Object ID: TX05". So if someone types in a width of 300, after pressing the resize button, the object below it get's a width of 300.

I tried doing this by using this macro:

sub resize

     set obj = ActiveDocument.GetSheetObject("TX05")
     set fr = obj.GetFrameDef
     set pos = fr.Rect

'     Ratio is 2.5

     pos.Width = 120 * 2.5

'     pos.Height = vPreferredWidth/vOriginalWidth * vOriginalHeight     (this isn't relevant atm, but I want the ratio of width to height to stay the same and this will probably achieve this by using the original width and height ratio and applying that to the new width to get a new height).
     pos.Height = 200 * 2.5
     obj.SetFrame fr,true,dummy

End sub

The problem with this, is that I want to use the variable vWidth that the user put in. So instead of pos.Width = 120*2.5, I want something like pos.Width = vWidth. Problem is, if I do that the button stops working all together.

Can anyone explain to me what I am doing wrong or where I can learn what I am doing wrong. (I just started with macro's and variables, so almost everything in the qlikview is new to me.) I would also be interested in knowing where I can learn to understand this better? For example what does .GetFrameDef do and .Rect and .SetFrame. Is there an noob-friendly place I can use to learn more about this?

I think I need to do something like pos.Width = vWidth.GetContent.INT or something, but I can't seem to figure it out.

Hopefully one of you guys and gals can help me out.

Thanks in advance!

1 Solution

Accepted Solutions
Not applicable
Author

I made it work, only took me 300 hours!

Here is my new code:

sub resize

' Ratio is 2.5

  set obj = ActiveDocument.GetSheetObject("TX05")

  set fr = obj.GetFrameDef

  set pos = fr.Rect

  set WidthUser = ActiveDocument.Variables("vWidth")

  set HeightUser = ActiveDocument.Variables("vHeight")

  OriginalWidth = pos.Width

  OriginalHeight = pos.Height

  DesiredUserWidth = Cint(WidthUser.GetContent.String)

  pos.Width = DesiredUserWidth * 2.5

  pos.Height = DesiredUserWidth / OriginalWidth * OriginalHeight * 2.5

  obj.SetFrame fr,true,dummy

  msgbox("Changed Width to: " & pos.Width/2.5 & " " & Chr(13) & "Changed Height to: " & pos.Height/2.5)

End sub

If anyone sees something I can do to make it better, let me know!

View solution in original post

2 Replies
Not applicable
Author

Quick update:

I am 1 step further. I changed my code to:

sub resize

     set obj = ActiveDocument.GetSheetObject("TX05")
     set fr = obj.GetFrameDef

     set pos = fr.Rect

     set WidthUser = ActiveDocument.Variables("vWidth")

'    set OriginalWidth = Cint pos.Width

'    set OriginalHeight = pos.Height

'    Ratio is 2.5

     pos.Width = Cint(WidthUser.GetContent.String) * 2.5

'    pos.Height = vPreferredWidth/vOriginalWidth * vOriginalHeight

     pos.Height = 200 * 2.5
     obj.SetFrame fr,true,dummy

     msgbox("Changed Width to: " & pos.Width/2.5 & " " & Chr(13) & "Changed Height to: " & pos.Height/2.5)


End sub


So what has changed? I can now use the width that the user put in to change the width of the object.
What do I still need? I need a way to store my original width and height in a variable. I tried doing it with:
set OriginalWidth = pos.Width , but that doesn't work at all.

The problem is, that I need to store the original Width and Height to maintain my width/height ratio.

Anyone got any ideas about how I can solve this?

Not applicable
Author

I made it work, only took me 300 hours!

Here is my new code:

sub resize

' Ratio is 2.5

  set obj = ActiveDocument.GetSheetObject("TX05")

  set fr = obj.GetFrameDef

  set pos = fr.Rect

  set WidthUser = ActiveDocument.Variables("vWidth")

  set HeightUser = ActiveDocument.Variables("vHeight")

  OriginalWidth = pos.Width

  OriginalHeight = pos.Height

  DesiredUserWidth = Cint(WidthUser.GetContent.String)

  pos.Width = DesiredUserWidth * 2.5

  pos.Height = DesiredUserWidth / OriginalWidth * OriginalHeight * 2.5

  obj.SetFrame fr,true,dummy

  msgbox("Changed Width to: " & pos.Width/2.5 & " " & Chr(13) & "Changed Height to: " & pos.Height/2.5)

End sub

If anyone sees something I can do to make it better, let me know!