From: hermann leinen on
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?
From: MikeD on


"hermann leinen" <h.leinen(a)gmx.de> wrote in message
news:u#YVGSUsKHA.4752(a)TK2MSFTNGP04.phx.gbl...
> 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


From: Helmut Meukel on

"MikeD" <nobody(a)nowhere.edu> schrieb im Newsbeitrag
news:epYiytVsKHA.5940(a)TK2MSFTNGP02.phx.gbl...
>
>
> "hermann leinen" <h.leinen(a)gmx.de> wrote in message
> news:u#YVGSUsKHA.4752(a)TK2MSFTNGP04.phx.gbl...
>> 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.



From: hermann leinen on
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:
>
> "MikeD" <nobody(a)nowhere.edu> schrieb im Newsbeitrag
> news:epYiytVsKHA.5940(a)TK2MSFTNGP02.phx.gbl...
>>
>>
>> "hermann leinen" <h.leinen(a)gmx.de> wrote in message
>> news:u#YVGSUsKHA.4752(a)TK2MSFTNGP04.phx.gbl...
>>> 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.
>
>
>

From: hermann leinen on
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:
>
> "MikeD" <nobody(a)nowhere.edu> schrieb im Newsbeitrag
> news:epYiytVsKHA.5940(a)TK2MSFTNGP02.phx.gbl...
>>
>>
>> "hermann leinen" <h.leinen(a)gmx.de> wrote in message
>> news:u#YVGSUsKHA.4752(a)TK2MSFTNGP04.phx.gbl...
>>> 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.
>
>
>

 |  Next  |  Last
Pages: 1 2
Prev: error line source code
Next: Resolved: Re: Slider math