Annoying MFC C++ problem

Discussion in 'General Chat' started by amazingtrade, Nov 16, 2004.

  1. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    I have been working on this for three hours now and I am getting no where. I am writing a windows based calculator but I can't work out how to clear the textbox. I can clear it by setting the controler variable to 0, but when I start clicking on new numbers on my calcalator after the plus button has cleared it the old numbers come back.

    I really can't understand whats happening and I am getting to the point now where I may end up breaking my 17" TFT.

    Can somebody please help me if they know a way of totaly clearing an edit/text box contents using C++.NET MFC.

    Thanks.,
     
    amazingtrade, Nov 16, 2004
    #1
  2. amazingtrade

    penance Arrogant Cock

    Joined:
    Jun 30, 2003
    Messages:
    6,004
    Likes Received:
    2
    Location:
    Bristol - armpit of the west.
    Ive not touched C++ since my OU exam last year, and then it wasnt .NET
    I assume you take the value from the text box and stick it in a variable?
    Can you not just null the original variable?
     
    penance, Nov 16, 2004
    #2
  3. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    Yep there is a a variable that the contents of the textbox are stored in. When I set it back 0 it clears but when I do the next calculation parts of the old number typed in repear in the textbox. I am thinking it must be somthing really simple I am forgetting to do.

    PS I am using MFC so the languager isn't really any difference from Visual Studio 6.

    What do you mean by nulling it?
     
    amazingtrade, Nov 16, 2004
    #3
  4. amazingtrade

    penance Arrogant Cock

    Joined:
    Jun 30, 2003
    Messages:
    6,004
    Likes Received:
    2
    Location:
    Bristol - armpit of the west.
    by null i mean clear the memory alocated to that variable. But im not sure it would work in C++, it does in C.
    Are you useing a pointer?
     
    penance, Nov 16, 2004
    #4
  5. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    Not as far as I am aware unless a pointer is being used behind the scenes. I will have a ago at nulling the variable.
     
    amazingtrade, Nov 16, 2004
    #5
  6. amazingtrade

    Paul Ranson

    Joined:
    Sep 4, 2003
    Messages:
    1,602
    Likes Received:
    0
    Location:
    An octopus's garden.
    You'll have to go into more detail.

    If your MFC app is a dialog and you're using 'data exchange' then setting your variable to 0 and calling 'UpdateData ( FALSE )' might do the trick.

    If you have a CEdit bound to your control then try 'm_edit.SetWindowText ("") ;' or 'm_edit.SetWindowText ("0.0") ;' or whatever. I obviously have guessed what your CEdit or derived class might be called.

    Paul
     
    Paul Ranson, Nov 16, 2004
    #6
  7. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    I am usin the first method, I have already set the the variable to 0 and I am using the UpdateData("FALSE") method.

    We are being told of doing this next week but I am working so I am will miss that lecture hence the reason I am trying to do it now. I might have to speak to him before hand.
     
    amazingtrade, Nov 16, 2004
    #7
  8. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    Just been playing around the with the debugger and the controll vairable is storing the previous values even though reset it. Its probably my buggered up logic.

    I don't want to a be a programmer, I am think about the worlds worse :)
     
    amazingtrade, Nov 16, 2004
    #8
  9. amazingtrade

    michaelab desafinado

    Joined:
    Jun 19, 2003
    Messages:
    6,403
    Likes Received:
    1
    Location:
    Lisbon, Portugal
    I hope your programming is better than your spelling :D (sorry :shame: )

    Michael.
     
    michaelab, Nov 16, 2004
    #9
  10. amazingtrade

    amazingtrade Mad Madchestoh fan

    Joined:
    Jun 19, 2003
    Messages:
    5,139
    Likes Received:
    0
    Location:
    Manchester
    I have worked out the problem now, it helps when using strcpy when trying to replace a string somthing else. I was using strcat.

    I feel pretty stupid but so far my program is now working perfectly.
     
    amazingtrade, Nov 18, 2004
    #10
  11. amazingtrade

    michaelab desafinado

    Joined:
    Jun 19, 2003
    Messages:
    6,403
    Likes Received:
    1
    Location:
    Lisbon, Portugal
    strcpy and strcat? Does anyone still use those antiquated C functions in C++ :eek: ? You're practically asking to have a memory overwrite problem sooner or later with those. Dr.Watson will become your friend :)

    Michael.
     
    michaelab, Nov 18, 2004
    #11
  12. amazingtrade

    penance Arrogant Cock

    Joined:
    Jun 30, 2003
    Messages:
    6,004
    Likes Received:
    2
    Location:
    Bristol - armpit of the west.
    I didnt even know you can access those in C++, are they part of the string class?

    I assume they operate different to the C version, C++ doesnt need a null terminator at the end of strings.
     
    penance, Nov 18, 2004
    #12
  13. amazingtrade

    michaelab desafinado

    Joined:
    Jun 19, 2003
    Messages:
    6,403
    Likes Received:
    1
    Location:
    Lisbon, Portugal
    Nope - you can use them on char pointers just like in C. They're just regular global functions. They operate in exactly the same way and they use null termination.

    Michael.
     
    michaelab, Nov 18, 2004
    #13
  14. amazingtrade

    penance Arrogant Cock

    Joined:
    Jun 30, 2003
    Messages:
    6,004
    Likes Received:
    2
    Location:
    Bristol - armpit of the west.
    hmm, i would think people would want to get away from null termination.
     
    penance, Nov 18, 2004
    #14
  15. amazingtrade

    Paul Ranson

    Joined:
    Sep 4, 2003
    Messages:
    1,602
    Likes Received:
    0
    Location:
    An octopus's garden.
    If you're using MFC then you should be using CString, and I'm pretty sure that the Dialog Data eXchange mechanism will do CString to and fro an edit or static control, taking care of the detail for you.

    'strcat' and 'strcpy' are marked 'deprecated' in current versions of Microsoft Visual C++, so they at least want you to move on to modern idioms.

    Paul
     
    Paul Ranson, Nov 18, 2004
    #15
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...