Solved

CEdit question

Posted on 1998-06-09
7
394 Views
Last Modified: 2013-11-20
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
Comment
Question by:RolandKoehrsen
  • 4
  • 3
7 Comments
 
LVL 2

Accepted Solution

by:
kinkajou earned 100 total points
ID: 1317799
You'll need to translate the double into a string and then equate the string to your edit box. Answer comming.
0
 

Author Comment

by:RolandKoehrsen
ID: 1317800
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
 
LVL 2

Expert Comment

by:kinkajou
ID: 1317801
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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 

Author Comment

by:RolandKoehrsen
ID: 1317802
Thanks, I'll try it!

Roland
0
 

Author Comment

by:RolandKoehrsen
ID: 1317803
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
 
LVL 2

Expert Comment

by:kinkajou
ID: 1317804
I have an example program that uses the above code that I submitted. It does work. Would you like for you verification?
0
 

Author Comment

by:RolandKoehrsen
ID: 1317805
oh yes, please!!

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

Roland.Koehrsen@kiel.netsurf.de

Thank you!
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 49
sameEnds challenge 3 180
mapBully challenge 6 154
How do I get Window Title of all opened process? 4 14
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question