• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 451
  • Last Modified:

CEdit question

I feel stupid to ask this, but I am a beginner at C++ ;-) (Visual C++ 5)

What is the best way to write a Double type value into an CEdit box?
Do I have to convert it to CString and if: How do I do that best?

I have created a member variable called m_CEdit1_double which I use to read the value of the Edit box, can I use this to write a double  value to this Edit box? m_CEdit1_double = 1.645 gives no result.

Please don't laugh at me.. ;-) The beginning with Visual Basic was just as hard for me, but I made it!
0
RolandKoehrsen
Asked:
RolandKoehrsen
  • 4
  • 3
1 Solution
 
kinkajouCommented:
You'll need to translate the double into a string and then equate the string to your edit box. Answer comming.
0
 
RolandKoehrsenAuthor Commented:
I'm anticipating your conversion-answer.

By the way, tell me about MY solution I have found in the meantime. What does an expert say to this:?

CString CTemperatur2Dlg::str(double zahl, int nachkomma)
{
      CString a;
      int s,d;

      a = _fcvt(zahl,nachkomma,&d,&s);
      a=a.Left(d) + '.' + a.Right(nachkomma);
      a=(!d)? '0' + a:a;
      a=(s)? '-' + a:a;
      
      return(a);
}
0
 
kinkajouCommented:
RolandKoehrsen,

Add a CString member variable to your CEdit box. In the procedure you want to update CEdit1, add a char buffer and use sprintf () to convert the double. I used the following.

char buffer[20];
sprintf (buffer, "%f", m_CEdit1_double);

Following, add the converted string to your CString member variable like below:

m_CEdit1_string = buffer; // where m_CEdit1_string is a CString

MFC should take care of actually adding the text to the CEdit box if your program is simple and you haven't over-ridden the CEdit functions.

Good Luck!
Kinkajou
0
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
RolandKoehrsenAuthor Commented:
Thanks, I'll try it!

Roland
0
 
RolandKoehrsenAuthor Commented:
Obviously this didn't work.
Changing the member variable doesn't affect on the Edit-box text.

I went over using my own conversion routine and using the SetWindowText function to write the string into the EditBox.

Roland.
0
 
kinkajouCommented:
I have an example program that uses the above code that I submitted. It does work. Would you like for you verification?
0
 
RolandKoehrsenAuthor Commented:
oh yes, please!!

maybe it's best if you send via e-mail:

Roland.Koehrsen@kiel.netsurf.de

Thank you!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now