Mathematical help / suggestion (SOLVED)

Started by Rui 'Trovatore' Pires, Sun 15/01/2006 14:57:05

Previous topic - Next topic

Rui 'Trovatore' Pires

Well, I need some sort of help with my maths - I need to know if something is possible, and if so how. If not, I'd like to suggest something to make the whole matter obsolete.

I have a slider, see. And I have a listbox to go with it, see. So far so good. But I want the slider to behave like a windows slider. Well, with the following code I've managed to get it to work in the exactly opposite way:

Code: ags
sldVerbs.Max=lstVerbs.ItemCount-lstVerbs.RowCount;
sldVerbs.Value=lstVerbs.TopItem;


What happens is, when the top item of the listbox is, say, 0, the value of the slider is also 0. And it moves accordingly to it's LOWER position. ANd when it moves UP, the listbox moves DOWN.

I'd like to know if there's some sort of mathematical formula, barring endless "ifs" and "elses" of manual and inefficient labout, to make it so that, for instance, when the max. value for the slider is 1 (between 0 and 1), putting it to 1 equals the listbox's top item being 0; and when max. value is 5, also make it equal the listbox's top item 0; and when it's 0, make it the listbox's furthest possible down item.

This was probably not very informative. Sorry, I don't know how to put it. But if it's not possible, then I'd like to suggest something else which may show what I'd like to achieve.

Would it be possible to make it so that sliders, which default to lowest value to the left/down, also allowed for the lowest value being to the right/up?
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

monkey0506

Maybe if you did:

Code: ags
sldVerbs.Min = 0;
sldVerbs.Max = lstVerbs.ItemCount - 1;
sldVerbs.Value = lstVerbs.TopItem;


I'm presuming that you're using the ListBox.Scroll(Up/Down) functions to update the top item.  I think that the problem may have been that you were setting the Max value to the number of items minus the number of items shown.  For example, if you had 10 items, and 4 could be shown at once, you would only have access to items 0 - 6.  Unless I've just misunderstood what you've done.

Rui 'Trovatore' Pires

#2
Oh, no, that's exactly what I wanted. That way I have good control over it. With your way, when I get to the lower numbers the final rows in the listboxes will display just empty rows, which I didn't want. This way, if I have 10 items and can show four, I can only change the first 6, which guarantees the described situation won't occur.

EDIT - At any rate, the problem would have remained. The value "0" of the slider would still correspond to it's lower position, and to the first item in the listbox.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

Code: ags
sldVerbs.Value=sldVerbs.Max - lstVerbs.TopItem;


Perhaps?
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

Well well well! I feel downright silly for not having thought of that, because it works great. And I'll feel even sillier for this next question, but I must:

What code should I use, then, to replace the one that I called when I clicked on the actual slider? It used to be: "lstVerbs.TopItem=sldVerbs.Value;", but that doesn't work anymore, naturally, and I don't see what I can do... see, in the other situation I scroll first and move the slider accordingly, and now I have to move the slider and scroll accordingly.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

lstVerbs.TopItem=sldVerbs.Max - sldVerbs.Value;

I'm guessing a bit at how exactly you've got it working, but that works for me.
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

What a beauty! Thank you very much for your help.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

SMF spam blocked by CleanTalk