i have a numeric updown
that goes from 0-99 and it works but i want to make it continuous
so if i hit the down when its at 0 it goes to 99 and when its on 99 and i hit up it goes to zero
anyone know the code id add to make that happen?

Recommended Answers

All 3 Replies

For UP, if number is MIN, set number to MAX.
For DOWN, if number is MAX, set number to MIN.

i have a numeric updown
that goes from 0-99 and it works but i want to make it continuous
so if i hit the down when its at 0 it goes to 99 and when its on 99 and i hit up it goes to zero
anyone know the code id add to make that happen?

You need to be more specific, are you using only C++?

Is this what you are trying to achieve( in psuedo-code) ?

long num = 0;
while true{
  print : Press up or down;
  char keyPressed equals getKeyPressed();
  if keyPressed is up the print : ++num;
  else print : --num;
}

NumericUpDown is a Winforms control in .NET.

@OP- I tried a couple of times to get WaltP's idea (and using this article for VB) to work but for some reason when I would try to wrap around I would get a StackOverflowException.

The solution is using a DomainUpDown control (in Toolbox go to All Window Forms). In properties, turn Wrap to True and set Text to your initial value. In your Form1_load event populate the list with a for loop:

for (int i = 0;i<100;i++)
      domainUpDown1->Items->Add(i.ToString());

Next make a button or whatever will do your bidding:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
      int value = Int32::Parse((String ^)domainUpDown1->SelectedItem);
      int newvalue = value*10+5; //for illustrative purposes
      MessageBox::Show(newvalue.ToString());
}

It's a little bit kudgy to go back and forth from string like that but if you really need the wraparound feature it may be the way to go (I'm not completely dismissing the NumericUpDown but it may have been designed (but to what purpose?) to function without wrapping)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.