Slider math
Author Message
Slider math

I have a slider that should accept values from 5 to 5000.
Since this cannot really be done by .Min and .Max, I have made it so
that the slider values are internally converted into a logarithmic scale
like this:

Private Sub pTellValueFromSlider(ByVal nValue As Integer)

Dim lMin&
Dim lMax&
lMin = 5
lMax = 1000

Dim lRes&
lRes = 10 ^ (log10(lMin) + ((nValue - Me.slider1.Min) / _
Me.slider1.Max * (log10(lMax) - log10(lMin))))

Me.Caption = lRes

End Sub

This works great: When the slider is in the middle, it tells me that
value is 71, that is exactely what I wanted.

Now I am trying to write a sub that positions the slider:
When I feed the sub with the value 71, I would like to have the slider
set exactely in the middle.

After trying it for 3 hours I am a bit lost...

This is the closest I could get:

Private Sub pSetSliderPos(ByVal nValue As Integer)

Dim lMin&
Dim lMax&

lMin = 5
lMax = 1000

Dim lPos&
lPos = ((nValue - log10(lMin)) / (log10(lMax) - log10(lMin)) \
(Me.slider1.Max - Me.slider1.Min)) \ 10

Me.slider1.Value = lPos

End Sub

Does somebody know where I went wrong?

Tue, 07 Aug 2012 17:16:59 GMT
Slider math

Wed, 18 Jun 1902 08:00:00 GMT
Slider math
I got it now... :-)

Dim lMin&
Dim lMax&

lMin = 5
lMax = 1000

Dim lPos&
lPos = (log10(nValue) - log10(lMin)) / (log10(lMax) - log10(lMin))
* (Me.slider1.Max - Me.slider1.Min)

Me.slider1.value = lPos

Tue, 07 Aug 2012 18:13:02 GMT
Slider math

Wed, 18 Jun 1902 08:00:00 GMT
Slider math

Quote:
> I have a slider that should accept values from 5 to 5000.
> Since this cannot really be done by .Min and .Max, I have made it so that
> the slider values are internally converted into a logarithmic scale like
> this:

> This works great: When the slider is in the middle, it tells me that value
> is 71, that is exactely what I wanted.

What do you mean it can't be done?  How is a value of 71 in the middle of a
range that's 5 - 5000 (or even 1000 as you used for Max in your code)?

Are you using the Slider from Windows Common Controls? It's Min and Max (and
other related properties) are Long data types. This code works fine:

Slider1.Min = 0
Slider1.Max = 100000
Slider1.Value = 50000

--
Mike

Tue, 07 Aug 2012 20:02:40 GMT
Slider math

Quote:

>> I have a slider that should accept values from 5 to 5000.
>> Since this cannot really be done by .Min and .Max, I have made it so that the
>> slider values are internally converted into a logarithmic scale like this:

>> This works great: When the slider is in the middle, it tells me that value is
>> 71, that is exactely what I wanted.

> What do you mean it can't be done?  How is a value of 71 in the middle of a
> range that's 5 - 5000 (or even 1000 as you used for Max in your code)?

> Are you using the Slider from Windows Common Controls? It's Min and Max (and
> other related properties) are Long data types. This code works fine:

>    Slider1.Min = 0
>    Slider1.Max = 100000
>    Slider1.Value = 50000

> --
> Mike

Mike,

his scale is logarithmic, like the Richter scale for earthquakes.
The force of an earthquake with 5.0 is 10 times that of an earthquake with 4.0

If in his case the actual values are from 5 to 5000, you could simply scale from
0 to 3:
5  = 5 * 10^0   ==>  0
50  = 5 * 10^1   ==>  1
500  = 5 * 10^2   ==>  2
5000  = 5 * 10^3   ==>  3
Or use an offset to make it more complicated, as he does.

On a logarithmic scale, doubling the real value shows always an increase of the
With an linear scale as you suggested, you will see no change of the slider
position
if the value doubled from 50 to 100.

Helmut.

Tue, 07 Aug 2012 20:48:18 GMT
Slider math
Yes, exactely!

I am doing it this way because I care more about the smaller values than
for the large ones, but I still need to allow the large values as well.

Just for the records I would like to update my previous posting because
I made a mistake. The corrected version is this:

Private Sub pTellValueFromSlider(ByVal nValue As Integer)

Dim lMin&
Dim lMax&
lMin = 5
lMax = 1000

Dim lRes&
lRes = 10 ^ (log10(lMin) + ((nValue + Me.slider1.Min) / _
Me.slider1.Max * (log10(lMax) - log10(lMin))))

Me.Caption = lRes

End Sub

Am 19.02.2010 13:48, schrieb Helmut Meukel:

Quote:

>>> I have a slider that should accept values from 5 to 5000.
>>> Since this cannot really be done by .Min and .Max, I have made it so
>>> that the slider values are internally converted into a logarithmic
>>> scale like this:

>>> This works great: When the slider is in the middle, it tells me that
>>> value is 71, that is exactely what I wanted.

>> What do you mean it can't be done? How is a value of 71 in the middle
>> of a range that's 5 - 5000 (or even 1000 as you used for Max in your
>> code)?

>> Are you using the Slider from Windows Common Controls? It's Min and
>> Max (and other related properties) are Long data types. This code
>> works fine:

>> Slider1.Min = 0
>> Slider1.Max = 100000
>> Slider1.Value = 50000

>> --
>> Mike

> Mike,

> his scale is logarithmic, like the Richter scale for earthquakes.
> The force of an earthquake with 5.0 is 10 times that of an earthquake
> with 4.0

> If in his case the actual values are from 5 to 5000, you could simply
> scale from 0 to 3:
> 5 = 5 * 10^0 ==> 0
> 50 = 5 * 10^1 ==> 1
> 500 = 5 * 10^2 ==> 2
> 5000 = 5 * 10^3 ==> 3
> Or use an offset to make it more complicated, as he does.

> On a logarithmic scale, doubling the real value shows always an increase
> of the
> scale value of about 0.3.
> With an linear scale as you suggested, you will see no change of the
> slider position
> if the value doubled from 50 to 100.

> Helmut.

Wed, 08 Aug 2012 01:13:33 GMT
Slider math
Helmut, do you have any idea how I can make it so that the smaller
values take up more space in the slider?

Right now it is so that when the slider is at the middle position, I am
at the "real" value "71".
I am thinking about a way how to make it let's say "30" only when I'm in
the middle position.
I have no idea which alogrithm I should use.
I think "double logarithmic" means something else, right?

Greetings
Hermann

Am 19.02.2010 13:48, schrieb Helmut Meukel:

Quote:

>>> I have a slider that should accept values from 5 to 5000.
>>> Since this cannot really be done by .Min and .Max, I have made it so
>>> that the slider values are internally converted into a logarithmic
>>> scale like this:

>>> This works great: When the slider is in the middle, it tells me that
>>> value is 71, that is exactely what I wanted.

>> What do you mean it can't be done? How is a value of 71 in the middle
>> of a range that's 5 - 5000 (or even 1000 as you used for Max in your
>> code)?

>> Are you using the Slider from Windows Common Controls? It's Min and
>> Max (and other related properties) are Long data types. This code
>> works fine:

>> Slider1.Min = 0
>> Slider1.Max = 100000
>> Slider1.Value = 50000

>> --
>> Mike

> Mike,

> his scale is logarithmic, like the Richter scale for earthquakes.
> The force of an earthquake with 5.0 is 10 times that of an earthquake
> with 4.0

> If in his case the actual values are from 5 to 5000, you could simply
> scale from 0 to 3:
> 5 = 5 * 10^0 ==> 0
> 50 = 5 * 10^1 ==> 1
> 500 = 5 * 10^2 ==> 2
> 5000 = 5 * 10^3 ==> 3
> Or use an offset to make it more complicated, as he does.

> On a logarithmic scale, doubling the real value shows always an increase
> of the
> scale value of about 0.3.
> With an linear scale as you suggested, you will see no change of the
> slider position
> if the value doubled from 50 to 100.

> Helmut.

Wed, 08 Aug 2012 01:19:29 GMT
Slider math
Hermann,

right, double logarithmic means something else:
http://de.wikipedia.org/wiki/Doppelt-logarithmische_Auftragung

Right now I don't have any idea, but to find an anwer I have do go
back in time to my highschool math, more than 40 years. I never
needed logarithms later in my life. <bg>
Maybe I come up with something after a good nights sleep.

Helmut.

Quote:
> Helmut, do you have any idea how I can make it so that the smaller values take
> up more space in the slider?

> Right now it is so that when the slider is at the middle position, I am at the
> "real" value "71".
> I am thinking about a way how to make it let's say "30" only when I'm in the
> middle position.
> I have no idea which alogrithm I should use.
> I think "double logarithmic" means something else, right?

> Greetings
> Hermann

> Am 19.02.2010 13:48, schrieb Helmut Meukel:

>>>> I have a slider that should accept values from 5 to 5000.
>>>> Since this cannot really be done by .Min and .Max, I have made it so
>>>> that the slider values are internally converted into a logarithmic
>>>> scale like this:

>>>> This works great: When the slider is in the middle, it tells me that
>>>> value is 71, that is exactely what I wanted.

>>> What do you mean it can't be done? How is a value of 71 in the middle
>>> of a range that's 5 - 5000 (or even 1000 as you used for Max in your
>>> code)?

>>> Are you using the Slider from Windows Common Controls? It's Min and
>>> Max (and other related properties) are Long data types. This code
>>> works fine:

>>> Slider1.Min = 0
>>> Slider1.Max = 100000
>>> Slider1.Value = 50000

>>> --
>>> Mike

>> Mike,

>> his scale is logarithmic, like the Richter scale for earthquakes.
>> The force of an earthquake with 5.0 is 10 times that of an earthquake
>> with 4.0

>> If in his case the actual values are from 5 to 5000, you could simply
>> scale from 0 to 3:
>> 5 = 5 * 10^0 ==> 0
>> 50 = 5 * 10^1 ==> 1
>> 500 = 5 * 10^2 ==> 2
>> 5000 = 5 * 10^3 ==> 3
>> Or use an offset to make it more complicated, as he does.

>> On a logarithmic scale, doubling the real value shows always an increase
>> of the
>> scale value of about 0.3.
>> With an linear scale as you suggested, you will see no change of the
>> slider position
>> if the value doubled from 50 to 100.

>> Helmut.

Wed, 08 Aug 2012 03:02:38 GMT
Slider math
Hi Helmut,

thank you for thinking with me, but I think it's not necessary anymore...
I have hardcoded this ugly thing now because it doesn't have to be dynamic.

Greetings,
Hermann

Am 19.02.2010 20:02, schrieb Helmut Meukel:

Quote:
> Hermann,

> right, double logarithmic means something else:
> http://de.wikipedia.org/wiki/Doppelt-logarithmische_Auftragung

> Right now I don't have any idea, but to find an anwer I have do go
> back in time to my highschool math, more than 40 years. I never
> needed logarithms later in my life. <bg>
> Maybe I come up with something after a good nights sleep.

> Helmut.

>> Helmut, do you have any idea how I can make it so that the smaller
>> values take up more space in the slider?

>> Right now it is so that when the slider is at the middle position, I
>> am at the "real" value "71".
>> I am thinking about a way how to make it let's say "30" only when I'm
>> in the middle position.
>> I have no idea which alogrithm I should use.
>> I think "double logarithmic" means something else, right?

>> Greetings
>> Hermann

>> Am 19.02.2010 13:48, schrieb Helmut Meukel:

>>>>> I have a slider that should accept values from 5 to 5000.
>>>>> Since this cannot really be done by .Min and .Max, I have made it so
>>>>> that the slider values are internally converted into a logarithmic
>>>>> scale like this:

>>>>> This works great: When the slider is in the middle, it tells me that
>>>>> value is 71, that is exactely what I wanted.

>>>> What do you mean it can't be done? How is a value of 71 in the middle
>>>> of a range that's 5 - 5000 (or even 1000 as you used for Max in your
>>>> code)?

>>>> Are you using the Slider from Windows Common Controls? It's Min and
>>>> Max (and other related properties) are Long data types. This code
>>>> works fine:

>>>> Slider1.Min = 0
>>>> Slider1.Max = 100000
>>>> Slider1.Value = 50000

>>>> --
>>>> Mike

>>> Mike,

>>> his scale is logarithmic, like the Richter scale for earthquakes.
>>> The force of an earthquake with 5.0 is 10 times that of an earthquake
>>> with 4.0

>>> If in his case the actual values are from 5 to 5000, you could simply
>>> scale from 0 to 3:
>>> 5 = 5 * 10^0 ==> 0
>>> 50 = 5 * 10^1 ==> 1
>>> 500 = 5 * 10^2 ==> 2
>>> 5000 = 5 * 10^3 ==> 3
>>> Or use an offset to make it more complicated, as he does.

>>> On a logarithmic scale, doubling the real value shows always an increase
>>> of the
>>> scale value of about 0.3.
>>> With an linear scale as you suggested, you will see no change of the
>>> slider position
>>> if the value doubled from 50 to 100.

>>> Helmut.

Wed, 08 Aug 2012 03:30:29 GMT

 Page 1 of 1 [ 10 post ]

Relevant Pages