-1

The questions is how to get data from trackbar like hexa numbers. What I need is: get values from 1 to 64 on the ride side and on the other side(-1 to -64) will be data represending data from 81 to E4.
I set my trackbar on min -64 and max 64 and set default value to 0. I my plan is use If condition some like this:

if (trackBar1.Value <= -1)
{
    PM = trackBar1.Value; //any magic code to convert my value
}
else
{
    PM = trackBar1.Value;
}

Is there any ways how to do it?

3
  • Sorry I cannot see the pattern of the data conversion, 81 to E4?? Write 64 switch-case statements :)
    – kennyzx
    Nov 12, 2018 at 14:49
  • yes sound like good start point. I will use for now! thanks for supp! :D Nov 12, 2018 at 14:52
  • Surely if the minus values should be from 0x81 to 0xE4, just do PM = 0xE5 + trackBar1.Value?
    – Martin
    Nov 12, 2018 at 14:53

2 Answers 2

1

If I understand your question correctly, you have a track bar whose values run from -64 through to +64. Where the trackbar value is below 0, you want to return figures from 0x81 to 0xE4, and where the trackbar value is above 0, you wan to return figures from 1 to 64 as normal.

In this case, it's a simple case of performing a different calculation depending on whether the value is below 0 or above it:

if (trackBar1.Value <= -1)
{
    PM = 0xE5 + trackBar1.Value;
}
else
{
    PM = trackBar1.Value;
}

Where the value is below 0, this will add the negative value to 0xE5, which will give you the appropriate value in the range 0x81 to 0xE4.

-1

The right way for me was:

PM = Convert.ToByte(trackBar1.Value);

Thanks for help to every one. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.