Click to See Complete Forum and Search --> : Numeric updown - assign values to variables?


bodycode
January 31st, 2010, 10:45 PM
Hi all. I'm an absolute noob. I'm on the 118th. page of Ivor Horton's Beg. VC++. That's how new I am :) that is why I need to ask, how do you assign the value of a numeric up/down control to variables?

I get errors for all ints, floats, doubles and every other kind of variable I try!

for example, creating a Windows Forms and double clicking the numeric up/down control, it opens the code window (of course), and I declare one variable, of type float.

float myFloat;

myFloat = nudMyUpDown.


Doesn't work. Why is that? I'd also like to ue the decimal output of the control as well. that REALLY didn't work out too well! I can't find any definitive help in MSDN. All they talk about is doing this in VB. I don't wanna do VB, I wanna do VC++.

Any clues? Thanks in advance.

PS: Can you guyz & girlz keep it simple for this stupid? Thanks :)

Arjay
January 31st, 2010, 10:49 PM
Are you using MFC?

bodycode
February 1st, 2010, 12:21 AM
Both CLR and MFC. And any and all project templates that can create a Windows Forms project.

When I created my first project to experiment with the control, I had Visual C++ selected, top level, neither CLR or MFC was actually selected. I was still able to selected a Windows Forms Project. But I guess I need to select either one? Either way, I'll need to know how to do this for any Windows forms project. Thanks.

BTW, I saw a few examples on the internet, and I saw the symbol
->, in place of the period, as seen in VB, as in nudUPDown.value. What's that all about? If I need to use that symbol in place of the period, what key is in on the keyboard? Thanks in advance.

Regards,
Marshall.

Arjay
February 1st, 2010, 12:27 AM
You're making life more difficult for yourself if you use the CLR and MFC. Since you are learning why not stick to MFC (or if you want to go with managed code, use C#)?

Attached is a Visual Studio 2008 MFC project that does what you want.

bodycode
February 1st, 2010, 12:54 AM
Thanks for your help, however it's not what I'm looking for at all. I'm actually looking to use the numericupdown control in the toolbox, in a Windows Forms project. MFC will come later. I'm not up to that and quite frankly, the code I saw here is like 2 years away from where I need to be right now and compltely blew me away. A real show stopper for me. I'm just looking for a Really Simple Solution, that is, creating a windows forms project, dragging a numeric updown control to a form, and, declaring some variables that will be assigned values from the numericupdown GUI control. I guess that creating the Windows Forms template from a CLR project is what I need. Thank you.

Regards,
Marshall

Arjay
February 1st, 2010, 01:07 AM
If you want simple, then I suggest you code in .net using C# or VB.net. Coding .net with managed C++ and the CLR isn't trivial.

Btw, the MFC project that I attached took about 5 minutes to code. The majority of the code was created for me. All I had to do is drag
a static control (label), edit box control, and spin control onto the dialog in the resource editor. Next I added a data variable for the edit
box and a control variable for the spin control. From there, it was a couple of more lines to initialize the spin control and display the
message box when the user clicked OK.

bodycode
February 1st, 2010, 01:10 AM
So returning a value from a numeric updown to a variable in a CLR project can't be done in a line of code? Thanks in advance.

Regards,
Marshall

Arjay
February 1st, 2010, 01:12 AM
So returning a value from a numeric updown to a variable in a CLR project can't be done in a line of code? Thanks in advance.

Regards,
MarshallIt looks like it can be. The updown control in managed code doesn't need to be bound like in MFC.

Attached is a C++ CLR Forms project.

Arjay
February 1st, 2010, 01:36 AM
Moving to the managed C++ forum.

bodycode
February 1st, 2010, 02:20 AM
Ok, I found my answer.

Within the system namespace, we have the following variable declaration possible. This is actually within a CLR project, but I'm sure that the System namespace can work with any other kind of template. Might be wrong, but I think it's C++ all the way? Anyway..

System::Decimal myDecimalVariable;

myDecimalVariable = numericUPDown ->value

Strange symbol there before the value property!!!! But that's what to use. The symbol is actually a minus sign, no space, and the greater than sign! Takes the place of the dot symbol used in VB!!

Any corrections here, don't hesitate. But this compiles and runs without any errors.

Thanks.

Regards,
Marshall

bodycode
February 1st, 2010, 02:21 AM
I found the clue in Ivor Horton's Beg. Visual C++ 2008, page 99.

Arjay
February 1st, 2010, 10:01 AM
Ok, I found my answer.

Within the system namespace, we have the following variable declaration possible. This is actually within a CLR project, but I'm sure that the System namespace can work with any other kind of template. Might be wrong, but I think it's C++ all the way? Anyway..

System::Decimal myDecimalVariable;

myDecimalVariable = numericUPDown ->value

Strange symbol there before the value property!!!! But that's what to use. The symbol is actually a minus sign, no space, and the greater than sign! Takes the place of the dot symbol used in VB!!

Any corrections here, don't hesitate. But this compiles and runs without any errors.

Thanks.

Regards,
MarshallYou mean like in the following line of my second sample:


MessageBox::Show( String::Format( L"Max count: {0}", this->_upDownCtrl->Value ), L"SpinIt CLR", MessageBoxButtons::OK );


Be sure to keep in mind that, C++, Managed C++ and C# are all case-sensitive languages (value in your example above needs to be Value).