Solved

Edit box does not display output

Posted on 1998-11-05
10
279 Views
Last Modified: 2007-10-18
I have an Edit box which is part of a dialog box.
What I am trying to achieve is to read some data from a file and then to display some of the contents back to the edit boxes I have. I have no trouble when displaying numbers in other edit boxes. But when trying to display strings, then it stays blanks.

In the example below, the variable attached to the Edit box is a CString. Please find below the code used:

string CashOrSwap;
fstream      InpFil("C:\\Tads\\DPRM files\\MDRYieldCurvesCcy.HKD.01",ios::in);
string      CurLin;
getline(InpFil,CurLin,'\n');
InpFil >> FirstInt >> MOrYLetter >> CashOrSwap >> From >> Hyphen >> To;
m_HkdInstru1 = CashOrSwap.c_str();
//m_HkdInstru1 is the CString variable attached to the edit box

If I just write m_HkdInstru = "fwebfweub";
then the garbage "fwebfweub" will be displayed correctly.

I am not sure what is happening !
So can anyone provide me with a solution to display my string variable in my CString edit box ?

Rgds,
A.
0
Comment
Question by:decornez
10 Comments
 

Expert Comment

by:kashif063098
ID: 1177051
Write UpdateData(FALSE); after m_HkdInstru1 = CashOrSwap.c_str();
i think it will solve your problem.


0
 
LVL 5

Expert Comment

by:yonat
ID: 1177052
If you set a break point at the line
    m_HkdInstru1 = CashOrSwap.c_str();
Does CashOrSwap has some meaningful content? If it does, does m_HkdInstru1 has a meaningful content after this line is executed?
0
 

Author Comment

by:decornez
ID: 1177053
kashif,

Thanks for your proposed answer, but it is not the reason.
I already have this line of code in my program.

Rgds,
A.
0
 
LVL 3

Expert Comment

by:Norbert
ID: 1177054
Are you sure that you have
UpdateData(FALSE) ?
uf you only call UpdateData()
it will operate with TRUE what means that the data from the edit box is written back to the member variable.
0
 

Author Comment

by:decornez
ID: 1177055
Norbert,

Yes I am sure.
It is also located after all this code.


Rgds,
Arnaud.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 5

Expert Comment

by:yonat
ID: 1177056
decornez, did you see my previous comment? Here it is again:

If you set a break point at the line
    m_HkdInstru1 = CashOrSwap.c_str();
Does CashOrSwap has some meaningful content? If it does, does m_HkdInstru1 has a meaningful content after this line is executed?
0
 

Author Comment

by:decornez
ID: 1177057
Yonat,

I am afraid I am rather unfamiliar with the MS VC++ debugger. Give me a bit of time to sort it out as at the moment when I try to put a breakpoint on that line it does not seem to accept. I will hopefully figure it out within a few minutes/hours and let you know what the outcome is.

A.
0
 

Author Comment

by:decornez
ID: 1177058
Yonat,

I have sorted out the debugger.
For your info, here is what my code looks like (you will recognize your .c_str() ) :

/////////////////////////////////////////////////////////////////////////////////
while(!InpFil.eof()) // While not at the end of the file.
       {
          InpFil >> FirstInt >> MOrYLetter >> CashOrSwap >> From >> Hyphen >> To;
          getline(InpFil,CurLin); // Get current line.
       }
      m_HkdBid1 = From;
      m_HkdInstru1 = CashOrSwap.c_str();
/////////////////////////////////////////////////////////////////////////////////

It looks like the while loop tries to read one more line than it should.
I am not sure why, maybe an eof flag problem with that file.
Anyway, since for testing I had put "m_HkdInstru1 = CashOrSwap.c_str(); " outside the while loop, it was trying to read the last available CashOrSwap produced by that loop.
But since the loop is reading one extra "rubbish" line the content of CashOrSwap was blanked.
When I put "m_HkdInstru1 = CashOrSwap.c_str(); " inside the loop, m_HkdInstru1 is being updated properly, so the c_str() bit works fine :o)
So I think that to sort my problem I will use the while loop to first count the number of lines I want to read, and then use a For Next with appropriate number of steps to update my controls.

I will try it and will keep you posted.
Yonat since you got me on the right track by pushing me to use the debugger I will give you the points.
Just put an answer and they are yours.

By the way, the reason why I was having some troubles with the debugger is that I was in Release mode ! Ooooops

Thanks,
A.
0
 
LVL 5

Accepted Solution

by:
yonat earned 40 total points
ID: 1177059
Seems you stumbled on the infamous getline bug! See http://www.dinkumware.com/vc_fixes.html for a fix.
0
 

Author Comment

by:decornez
ID: 1177060
I will check it out.

Thanks,
A.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now