Link to home
Start Free TrialLog in
Avatar of decornez
decornez

asked on

Edit box does not display output

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.
Avatar of kashif063098
kashif063098

Write UpdateData(FALSE); after m_HkdInstru1 = CashOrSwap.c_str();
i think it will solve your problem.


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?
Avatar of decornez

ASKER

kashif,

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

Rgds,
A.
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.
Norbert,

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


Rgds,
Arnaud.
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?
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of yonat
yonat

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I will check it out.

Thanks,
A.