Values slightly off when working with sliders

Discussion in 'Mac Programming' started by sheepopo39, Jan 12, 2010.

  1. sheepopo39 macrumors 6502

    Joined:
    Sep 18, 2008
    #1
    I just recently made up a very simple application with a slider, a label, and a button. When the user hits the button it gets the value of what slider currently is at and sends it to the label. I have the slider start from 0 to 100, with 10 ticks. However the problem is, is that when I hit the buttons, the values are slightly off, i.e 11, instead of 10 and 88 instead of 90, it seems to go up in denominations of 11. Does anyone know how I can fix this?

    Thanks,

    John.

    Edit: Also when I try to change the current value in IB, say I enter 10 it takes it to 11.1, also I have only stop on ticks set.
     
  2. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #2
    If you want your tick marks to hit at every factor of 10 from 0 to 100, try using 11 ticks instead of 10.
     
  3. sheepopo39 thread starter macrumors 6502

    Joined:
    Sep 18, 2008
    #3
    Alright, it worked, thanks a lot, although, is there any way I could do it with ten? Though now I think of it, 11 makes a lot more sense.
     
  4. Sydde macrumors 68020

    Sydde

    Joined:
    Aug 17, 2009
    #4
    AFAIK, the only way to do it with ten ticks is to make 10 your minimum value. I have always found inclusive math to be a pain in the head (like trying to figure out substring ranges, back in the old days). Think of it this way: there are ten integer values from 1 to 10 - if you want to include 0 in that range, you end up with 11 values.

    You might also want to look at continuous controls and/or bindings so that the value gets updated constantly instead of needing a button click to update.
     
  5. sheepopo39 thread starter macrumors 6502

    Joined:
    Sep 18, 2008
    #5
    Thanks a lot, it's a lot more clearer now. Also, thanks for the recommendation, I was gonna do that later too, but I just wanted to get the whole stuff down first.

    Thanks,

    John.
     

Share This Page