CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Jan 2010
    Posts
    10

    Numeric updown - assign values to variables?

    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

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    Are you using MFC?

  3. #3
    Join Date
    Jan 2010
    Posts
    10

    Re: Numeric updown - assign values to variables?

    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.

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    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.
    Attached Files Attached Files

  5. #5
    Join Date
    Jan 2010
    Posts
    10

    Re: Numeric updown - assign values to variables?

    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

  6. #6
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    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.
    Last edited by Arjay; February 1st, 2010 at 02:10 AM.

  7. #7
    Join Date
    Jan 2010
    Posts
    10

    Re: Numeric updown - assign values to variables?

    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

  8. #8
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    Quote Originally Posted by bodycode View Post
    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
    It 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.
    Attached Files Attached Files
    Last edited by Arjay; February 1st, 2010 at 02:35 AM.

  9. #9
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    Moving to the managed C++ forum.

  10. #10
    Join Date
    Jan 2010
    Posts
    10

    Re: Numeric updown - assign values to variables?

    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:ecimal 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

  11. #11
    Join Date
    Jan 2010
    Posts
    10

    Re: Numeric updown - assign values to variables?

    I found the clue in Ivor Horton's Beg. Visual C++ 2008, page 99.

  12. #12
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Numeric updown - assign values to variables?

    Quote Originally Posted by bodycode View Post
    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:ecimal 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
    You mean like in the following line of my second sample:

    Code:
    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).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured