Jump to content

Recommended Posts

I have a scrollbar with Min 0 and Max 255

on a Label I want to add what percent the position is moved too.

 


pos:=scrollbar1.position;

PercentLabel.caption:=inttostr(round(pos div 100));

Confused with the results  0 1 and 2 as I move the scrollbar.

 

Of course I am doing something wrong but what?

 

 

Share this post


Link to post
1 minute ago, David Heffernan said:

Why did you decide to have the scrollbar be ranged between 0 and 255?

Needed the range including zero to 255

Share this post


Link to post
On 10/26/2022 at 10:02 AM, David Heffernan said:

But why? If you are mapping 0..255 to 0.100 why not have the scroll bar range 0..100? 

I have done this too in some cases. I assume it's because the range of the variable being adjusted is 0-255 (for example the luminance of a colour or the opacity), but providing a percentage is much more understandable to the user.

Share this post


Link to post

Mmm I guess another way to do it, if you don't want to bother changing the min and max values on a scrollbar, could be to assign the max value to a constant and then use that to calculate the amount that you are after. Could be useful if you have a lot of scrollbars on your page.

Const
    VALUE_MAX = 256;

pos := scrollbar1.position;

dataValue := (round((pos div 100) *  VALUE_MAX));

And then you don't need to bother with having to calculate the percentage:

percentLabel.caption  :=  inttostr(pos);

It also makes it easier if you need to change the max value, because you can just change the constant value and don't have to worry about the scrollbar.

 

But I suppose it's a much of a muchness, really.

 

Share this post


Link to post

I think the main question here is: Which granularity of a single step the user really needs for setting something ?

Is it full 0...255 or is 0...100 sufficient ?

 

This can be depending on the application, the formulas above only make it more readable to the user in %

Edited by Rollo62
  • Like 1

Share this post


Link to post

for I := 0 to fFilesCount-1 do

fProgress := (((I+1) / (fFilesCount)) * 100);

 

0->100 should be ok. TProgressBar does not allow more than "Single" anyway.

then have a Label saying the current fFilesCount value or something

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×