Annoying MFC C++ problem

amazingtrade

Mad Madchestoh fan
Joined
Jun 19, 2003
Messages
5,139
Reaction score
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.,
 
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?
 
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?
 
penance said:
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?

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.
 
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
 
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.
 
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 :)
 
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.
 
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.
 
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.
 
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.
 
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
 
Back
Top