Moving a rectangle box based on a value (1 Viewer)

WineSnob

Not Bright but TENACIOUS
Local time
Today, 16:52
Joined
Aug 9, 2010
Messages
211
Is it possible to move a rectangle control using code? I am trying to create a visual representation of a number on a linear scale.
I have a control named RiskIndex which will have a value of 0 - 100. I would to "Slide" a rectangle named Box1 along a line from 0 = Far left to 100 = Far Right and in between based on the value of RiskIndex.

If you have any other ideas to show the represtation I am open to it.

If it is a big deal to so it no problem. I just thought would be nice to see. If the user cannot tell 22 is closer to 0 than 78 they have other problems :rolleyes:
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:52
Joined
Feb 19, 2013
Messages
16,618
It is pretty straightforward

Most controls have a left, top, width and height properties

Although values in this properties on the property sheet are in cm or inches (depending on the db setup options) in code you use twips - there are 1440 twips to an inch, 567 to a cm.

So to move a control 1cm to the right you would use

myCtrl.Left=myCtrl.Left+567

If you wanted it to grow 1cm you would use

myCtrl.Width=myCtrl.Width+567

Minimum value is 0 so you need to ensure you do not create negative numbers or you will get an error.

For what you require you probably need a bit of scaling based on the length of your line less the width of the rectangle (to avoid 'overshooting')
 

WineSnob

Not Bright but TENACIOUS
Local time
Today, 16:52
Joined
Aug 9, 2010
Messages
211
Thanks. That moves the box to the right. How do I "reset it" to the original position? How do I move it to the left?
I have an on openevent
Box1.Left = Box1.Left + (Me.RiskIndex * 10 + 500)
If RiskIndex is 40 then it moves it to 400+500=9000
If the next time I open the form and RiskIndex = 10 then it continues to move it to the right.
What I want is on open it looks at RiskIndex and moves the box either left or right as necessary based on the value.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 21:52
Joined
Feb 19, 2013
Messages
16,618
Without wishing to state the obvious, if you add 567 to the .left property and it goes right, what to you think would happen if you subtracted 567 from the .left property?:D

Code:
If the next time I open the form and RiskIndex = 10 then it continues to move it to the right.
This is probably because you saved the form (with the new left value)

Suggest you try this - change Line1 to the name of your line

Code:
Box1.Left = [COLOR=red]Line1[/COLOR].Left + (Me.RiskIndex * 10 + 500)
 

Users who are viewing this thread

Top Bottom