andyf2022 0 Posted October 26, 2022 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
andyf2022 0 Posted October 26, 2022 19 minutes ago, Alexander Sviridenkov said: round(pos/2.55) Brilliant, thank you. Share this post Link to post
David Heffernan 2345 Posted October 26, 2022 Why did you decide to have the scrollbar be ranged between 0 and 255? Share this post Link to post
andyf2022 0 Posted October 26, 2022 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
David Heffernan 2345 Posted October 26, 2022 But why? If you are mapping 0..255 to 0.100 why not have the scroll bar range 0..100? Share this post Link to post
XylemFlow 8 Posted October 28, 2022 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
haley 2 Posted October 29, 2022 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
Rollo62 536 Posted October 29, 2022 (edited) 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 October 29, 2022 by Rollo62 1 Share this post Link to post
reshup 0 Posted November 1, 2022 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